Discussion:
what is wrong with this grammar
lin q
2012-12-05 23:35:46 UTC
Permalink
Hi,

I have a simple grammar like this -

grammar string;

string : 'var' Name_string
;

Name_String
: 'a'..'z' +
;

WS : ('\t' | ' ')+ {$channel = HIDDEN;};


In AntlrWorks I give the test data as "var ab", but I get
MissingTokenException when it comes to parse "ab".

Do you see what is the problem?

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
lin q
2012-12-06 19:01:14 UTC
Permalink
One line left in my post,

New_Line : ('\r' | '\n')+ ;

But looks like AntlrWorks has some issue. With same grammar, with some
printf action added, I can compile the grammar, compile the generated code
and parse the same testing data ( var ab ).
Post by lin q
Hi,
I have a simple grammar like this -
grammar string;
string : 'var' Name_string
;
Name_String
: 'a'..'z' +
;
WS : ('\t' | ' ')+ {$channel = HIDDEN;};
In AntlrWorks I give the test data as "var ab", but I get
MissingTokenException when it comes to parse "ab".
Do you see what is the problem?
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
John B. Brodie
2012-12-06 23:16:51 UTC
Permalink
your grammar works for me ---- after fixing the spelling of
"Name_string" in your string rule to match its spelling in its lexer
rule. Didn't ANTLR give an error message about that?

i do not use ANTLRWorks, but rather work from the command line.

if you are using the interpreter in ANTLRWorks, do not do that. Use the
debugger instead.

Hope this helps....
-jbb
Post by lin q
One line left in my post,
New_Line : ('\r' | '\n')+ ;
But looks like AntlrWorks has some issue. With same grammar, with some
printf action added, I can compile the grammar, compile the generated code
and parse the same testing data ( var ab ).
Post by lin q
Hi,
I have a simple grammar like this -
grammar string;
string : 'var' Name_string
;
Name_String
: 'a'..'z' +
;
WS : ('\t' | ' ')+ {$channel = HIDDEN;};
In AntlrWorks I give the test data as "var ab", but I get
MissingTokenException when it comes to parse "ab".
Do you see what is the problem?
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
lin q
2012-12-07 19:51:19 UTC
Permalink
Maybe I accidentally make that spelling mistake and later on corrected in a
way, so it could be my bad originally.

Anyway, my question is what is the efficient way to debug grammar just
using command line. I cannot find any doc on this topic. ANTLRworks is nice
when it works right, but when it does not, it drives me crazy.
your grammar works for me ---- after fixing the spelling of "Name_string"
in your string rule to match its spelling in its lexer rule. Didn't ANTLR
give an error message about that?
i do not use ANTLRWorks, but rather work from the command line.
if you are using the interpreter in ANTLRWorks, do not do that. Use the
debugger instead.
Hope this helps....
-jbb
Post by lin q
One line left in my post,
New_Line : ('\r' | '\n')+ ;
But looks like AntlrWorks has some issue. With same grammar, with some
printf action added, I can compile the grammar, compile the generated code
and parse the same testing data ( var ab ).
Hi,
Post by lin q
I have a simple grammar like this -
grammar string;
string : 'var' Name_string
;
Name_String
: 'a'..'z' +
;
WS : ('\t' | ' ')+ {$channel = HIDDEN;};
In AntlrWorks I give the test data as "var ab", but I get
MissingTokenException when it comes to parse "ab".
Do you see what is the problem?
List: http://www.antlr.org/mailman/**listinfo/antlr-interest<http://www.antlr.org/mailman/listinfo/antlr-interest>
Unsubscribe: http://www.antlr.org/mailman/**options/antlr-interest/your-*
*email-address<http://www.antlr.org/mailman/options/antlr-interest/your-email-address>
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
Loading...