--
Hi
I'm trying to parse an ANSI C file and am having trouble setting up the rules for array variable declarations. I'm trying the rules out with the following C statements:
Line
1 char szString10;
2
3 char szString1[];
4
5 char szString1[2];
6
7 char szString2[10];
My Grammar snippet is as follows:
grammar C;
cFile
: primaryExpression+
;
primaryExpression
: Identifier
| Constant
| StringLiteral+
| '(' expression ')'
| declaration
| preProcessorDirective
| blockComment
| lineComment
| genericSelection
;
declaration
: typeSpecifier Identifier '[' Dimension? ']') ';'
| typeSpecifier Identifier ';'
;
/* Lexer */
Dimension
: Digit+
;
fragment
Digit
: [0-9]
;
When I try to parse the C statements above, I get the following syntax error:
Lexer syntax error at 5:15 no viable alternative at input 'charszString1[2'
Stack:
Rule: 0 - cFile
Rule: 1 - primaryExpression
Line : char szString1[2];
Offending Symbol: [@10,56:56='2',<116>,5:15]
The parser has successfully parsed the statements on lines 1 and 3 but is objecting to the "Dimension" lexer rule.
Can anyone see what I'm doing wrong?
Thanks
Dave
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.