I don’t see why the following antlr grammar does not generate the tree for the input “b b b”
but it generates the tree for the input “a a a”
statement
|
a a a
Do you have some ideas? Thanks.
grammar Test2;
options {
language = Java;
}
statement: ( a|b )*;
a: 'a';
b: 'b';
WS: ('\n'|' '|'\t'|'r'|'\f')+ {$channel=HIDDEN;};
Can anyone tries this one in ANTLR IDE eclipse plugin
http://antlrv3ide.sourceforge.net/
In my Eclipse, it does behave strangely as I reported above.
It recognizes both both
"a a a"and"b b b", as it should. To check for yourself, add a little debug-print statement to yourstatementrule:and then test the parser with the following class:
After generating a lexer & parser and compiling all
.javasource files:you can test the parser with
"a a a"as input:and with
"b b b"as input:As you can see, in both cases no error is reported, and the input is printed back to the console.
My guess is that you’re using ANTLRWorks’ interpreter. Don’t. It is notoriously buggy. Either use ANTLRWorks’ debugger (it’s great!), or use a small test class you write yourself (similar to my
Mainclass).EDIT
Note that the ANTLR IDE Eclipse plugin uses the interpreter from ANTLRWorks, AFAIK.