Hi,
I am trying to create a SQL parser for the [SQL-92 BNF](http://savage.net.au/SQL/sql-92.bnf.html) that was converted by me to the lex/yacc grammar. I have the following two rules in the lexer's grammar:
```
[a-zA-Z][a-zA-Z_0-9]* {
Console.WriteLine("SQL_IDENTIFIER");
return (int) Tokens.SQL_IDENTIFIER;
}
[a-zA-Z_][a-zA-Z_0-9]* {
Console.WriteLine("REGULAR_IDENTIFIER");
return (int) Tokens.REGULAR_IDENTIFIER;
}
```
These two rules corresponds to the [<SQL language identifier>](http://savage.net.au/SQL/sql-92.bnf.html#xref-SQL%20language%20identifier) and the [<regular identifier>](http://savage.net.au/SQL/sql-92.bnf.html#xref-regular%20identifier) rules of the BNF.
After compilation when I try to check SQL files with test samples Parser recognizes all identifiers as SQL_IDENTIFIER. For example for the following SQL:
```
SELECT * FROM (SELECT * FROM table_name) t;
```
it shows:
```
Parsing SQL: SELECT * FROM (SELECT * FROM table_name) t;
SELECT
ASTERISK
FROM
LEFT_PAREN
SELECT
ASTERISK
FROM
SQL_IDENTIFIER
RIGHT_PAREN
SQL_IDENTIFIER
SEMICOLON
EOF
DONE!
```
All parser's rules are in the following format
```
regular_identifier:
SQL_ID;
```
without any C# actions and respective rules are:
```
...
actual_identifier:
DOUBLE_QUOTED_STRING | regular_identifier;
regular_identifier:
SQL_ID;
...
character_set_specification:
schema_name PERIOD sql_language_identifier
| sql_language_identifier;
sql_language_identifier:
SQL_ID;
```
I expect that program (parser + lexer) should show REGULAR_IDENTIFIER instead of all SQL_IDENTIFIER but it shows SQL_IDENTIFIER for some reason. I'm stuck with it and don't know what to do next to fix the problem.
Could you help me to resolve this problem.
Thanks ;)
I am trying to create a SQL parser for the [SQL-92 BNF](http://savage.net.au/SQL/sql-92.bnf.html) that was converted by me to the lex/yacc grammar. I have the following two rules in the lexer's grammar:
```
[a-zA-Z][a-zA-Z_0-9]* {
Console.WriteLine("SQL_IDENTIFIER");
return (int) Tokens.SQL_IDENTIFIER;
}
[a-zA-Z_][a-zA-Z_0-9]* {
Console.WriteLine("REGULAR_IDENTIFIER");
return (int) Tokens.REGULAR_IDENTIFIER;
}
```
These two rules corresponds to the [<SQL language identifier>](http://savage.net.au/SQL/sql-92.bnf.html#xref-SQL%20language%20identifier) and the [<regular identifier>](http://savage.net.au/SQL/sql-92.bnf.html#xref-regular%20identifier) rules of the BNF.
After compilation when I try to check SQL files with test samples Parser recognizes all identifiers as SQL_IDENTIFIER. For example for the following SQL:
```
SELECT * FROM (SELECT * FROM table_name) t;
```
it shows:
```
Parsing SQL: SELECT * FROM (SELECT * FROM table_name) t;
SELECT
ASTERISK
FROM
LEFT_PAREN
SELECT
ASTERISK
FROM
SQL_IDENTIFIER
RIGHT_PAREN
SQL_IDENTIFIER
SEMICOLON
EOF
DONE!
```
All parser's rules are in the following format
```
regular_identifier:
SQL_ID;
```
without any C# actions and respective rules are:
```
...
actual_identifier:
DOUBLE_QUOTED_STRING | regular_identifier;
regular_identifier:
SQL_ID;
...
character_set_specification:
schema_name PERIOD sql_language_identifier
| sql_language_identifier;
sql_language_identifier:
SQL_ID;
```
I expect that program (parser + lexer) should show REGULAR_IDENTIFIER instead of all SQL_IDENTIFIER but it shows SQL_IDENTIFIER for some reason. I'm stuck with it and don't know what to do next to fix the problem.
Could you help me to resolve this problem.
Thanks ;)