[antlr-interest] $ in action comments

Thomas Brandon tbrandonau at gmail.com
Thu Feb 21 19:37:08 PST 2008


On Fri, Feb 22, 2008 at 5:53 AM, Gavin Lambert <antlr at mirality.co.nz> wrote:
> At 06:30 22/02/2008, Ian Moor wrote:
>   >I have finally tracked down two errors from generating a tree
>   >parser:
>   >error(111): pico/Gen.g:16:9: reference to attribute outside of a
>
>   >rule: zero
>   >error(114): pico/Gen.g:454:11: attribute is not a token,
>  parameter,
>   >or return value: v0
>   >
>   > in the first case there is a  // comment in the
>  members  sections
>   >containing $zero, and in the second case there is a comment  in
>  an
>   >action containing a $v0.
>
>  ANTLR doesn't understand the syntax of the target language, so it
>  doesn't know what are comments and what aren't.  The only things
>  it looks for are $s (to expand), }s (to terminate the block), and
>  {s (to avoid terminating too early).
>
>
ANTLR first delineates actions in the main lexer, then actions are
analysed by a seperate lexer and converted into chunks.
When delineating actions ANTLR handles strings (" or '), single\multi
line comments (/* and //) and nested blocks delimited by {}. In the
case of argument actions comments and ' delimited strings aren't
handled and the block delimiter is [].
However when analysing the actions it just looks for the various $ and
% sequences.
So in fact ANTLR does make assumptions about the comment syntax of
target languages so perhaps it should be extended to deal with them in
the action analysis phase.

Tom.


More information about the antlr-interest mailing list