Hello,
My goal is to write a parser which parses a C file and inserts C code
at certain points of interest to me in this file. I use antlr-3.2 and
antlrworks-1.4.
To begin with, I took the ANSI C grammar I found on the antlr examples
page and modified it accordingly to recognize my input file. My
immediate goal is to have this file parsed and printed out in an
output file and console, just to see that things are working. The
changes I made are as follows:
tokens {
PREPROCINCL = '#include';
MODELDECLINPUT = 'Declare_Input_None';
....
}
and the following parser rules:
program
: preprocdef+ modeldeclinput
;
preprocdef
: WS* PREPROCINCL ' ' '"' cheaderfile
'"' {System.out.println($PREPROCINCL.text + " " + $cheaderfile.text);}
;
cheaderfile
: IDENTIFIER '.h'
;
modeldeclinput
: MODELDECLINPUT {System.out.println($MODELDECLINPUT.text);}
;
....
When running the grammar I receive the error:
"required (..)+ loop did not match anything at input
'Declare_Input_None' ".
I debugged the grammar with antlrworks and when reaching
"Declare_Input_None" I get a EarlyExitException node in the parse
tree During debugging, I put the second token in the lexer rules with
semantic actions which simply prints out the token to console
MODELDECLINPUT
: 'Declare_Input_None' { System.out.println("Declare_Input_None"); }
;
I've also kept the third rule I added to the parser: modeldeclinput.
The tokens are printed out to console, but the error still appears,
probably because of the modeldeclinput rule. It seems that the token
gets past the lexer but the parser doesn't see it.
Could you please tell me what I am doing wrong ?
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.