[antlr-interest] Debugging doesn't work with grammar

Thomas Brandon tbrandonau at gmail.com
Thu Jul 5 20:43:11 PDT 2007


On 7/6/07, Johannes Luber <jaluber at gmx.de> wrote:
> Hi!
>
> The attached grammar doesn't work quite right. In the C# version of the
> grammar the lexer doesn't recognize a valid grammar of my own and
> complains in ACTION_STRING_LITERAL, that it can't find a closing quote
> sign till the end of the file. And with another one I get the following
> exception:
>
> "A first chance exception of type 'System.NullReferenceException'
> occurred in Antlr3.Runtime.dll"
Without the input you used I can't be sure, but it looks like a
problem with non-matched "s in actions. To avoid non-LL* issues the
grammar uses a fixed lookahead in the NESTED_ACTION rule, so upon
seeing a " it decides it must be an ACTION_STRING_LITERAL, if there is
no closing " it will swallow input until the end of the file. Looks
like it's not finding that matching " for some reason.
> Testing a Java version of the file with the same input as for the
> exception results, that the remote debugger doesn't connect with parser
> (mind you, I've used the normal debug menu here).
I was able to debug the attached grammar so not sure what's going on
there. Did you get any errors in the console? Is the code generated
correctly? Did you try remote debugging? Are you able to debug other
grammars?
> As it is a grammar
> adapted from Terence' work I'm at a complete loss. I didn't change the
> basic structure so I suppose that either the grammar has an error or
> ANTLR itself. I've attached the Java version of the grammar for your
> perusal.
This part of the grammar changed from the v2 grammar which used
syntactic predicates so it is quite possible Ter has not actually
tested this much.

>
> Best regards,
> Johannes Luber
>

> ARG_ACTION
>         :       NESTED_ARG_ACTION
>         ;
>
> fragment
> NESTED_ARG_ACTION :
>         '['!
>         (       options {greedy=false; k=1;}
>         :       NESTED_ARG_ACTION
>         |       ACTION_STRING_LITERAL
>         |       ACTION_CHAR_LITERAL
>         |       .
>         )*
>         ']'!
>         ;
>
> ACTION
>         :       NESTED_ACTION ( '?' {$type = SEMPRED;} )?
>         ;
>
> fragment
> NESTED_ACTION :
>         '{'
>         (       options {greedy=false; k=3;}
>         :       NESTED_ACTION
> //      |       DOC_COMMENT
>         |       SL_COMMENT
>         |       ML_COMMENT
>         |       ACTION_STRING_LITERAL
>         |       ACTION_CHAR_LITERAL
>         |       .
>         )*
>         '}'
>    ;
>
> fragment
> ACTION_CHAR_LITERAL
>         :       '\'' (ACTION_ESC|.) '\''
>         ;
>
> fragment
> ACTION_STRING_LITERAL
>         :       '"' (ACTION_ESC|.) (ACTION_ESC|.)* '"'
>         ;
>
> fragment
> ACTION_ESC
>         :       '\\\''
>         |       '\\"'
>         |       '\\' ~('\''|'"')
>         ;

Tom.


More information about the antlr-interest mailing list