[antlr-interest] advice on creating a grammar for a given DSL example

aryoo howaryoo at gmail.com
Tue Aug 17 13:55:06 PDT 2010


Dear Jim,

I followed your recommendations, avoided the "I don't want delimiters in my
language" temptation, and created the grammar from scratch using ANTLRWorks
successfully.
Next steps for me: AST + StringTemplate output.

Thanks a lot for your answer. It was exactly what I needed.

Sincerely,
Arye.

Remove your tokens section and place those keywords as real lexer rules that
> are listed before the ID rule.
> Remove any 'literals' in your parser and make these real lexer rules and
> tokens.
> Change your ANY rule to just: ANY :. { issue error message; skip(); };
> Use {skip();} rather than HIDDEN unless you need the whitespace later for
> some reason;
>
> Then you have to look at where you are putting your NEWLINEs in the
> grammar.
> It looks like you have too many specified and are expecting NEWLINE NEWLINE
> at some point. You should try skipping newlines and see how ambiguous your
> grammar is. If this is your own language, don't fall for the "I don't want
> delimiters in my language" myth as it makes giving out informative error
> messages nigh on impossible.
>
> But more than all this, you need to run your grammar in the ANTLR works
> debugger, which will allow you to trace out what is wrong with your grammar
> specification.
>
> Jim
>


More information about the antlr-interest mailing list