[antlr-interest] Re: ANTLR 3.0 question about common actions
Thomas Brandon
tom at psy.unsw.edu.au
Thu Aug 5 01:37:43 PDT 2004
While considering actions you might think about the syntax of
actions, especially if you are planning to break backwards
compatibility in this area. This is a bit of a nasty area in the
Antlr parser\lexer. As action blocks can include arbitrary text
(from the point of view of the Antlr parser which is ideally target-
language specific), some tricky handling of them is required.
Currently the Antlr lexer looks for the matching end marker (']' for
arg actions, '}' for normal actions) with special handling for
nested target-language blocks using []\{} and appearances in
comments and strings.
This means the current Antlr grammar is somewhat target language
specific, limited to languages with C++ style comments (// single
line, /* */ multi-line) and chars\strings ('' and "", pretty
universal). Consider for instance a VB code generator with ';' as
comment delimeter (not likely to be a problem).
And care must be taken with delimeters inside actions, for instance,
using '<' and '>' for templated actions as Ter suggest would seem
problematic. What do you do about "{if (some-condition) <somefunc
(i>x)>;}".
Having more complex action delimeters would seem to be a good
idea, "<a:skip()>" ('a' for action) while more verbose is less
likely to clash with a desired target language expression.
Tom.
--- In antlr-interest at yahoogroups.com, Terence Parr <parrt at c...>
wrote:
>
> On Jul 28, 2004, at 1:48 PM, Monty Zukowski wrote:
> > Currently you have an escape mechanism that says "this is all
target
> > language
<snip>
> NEWLINE : '\n' {if (some-condition) <skip()>;} ;
<snip>
> Ter
> --
> CS Professor & Grad Director, University of San Francisco
> Creator, ANTLR Parser Generator, http://www.antlr.org
> Cofounder, http://www.jguru.com
> Cofounder, http://www.knowspam.net enjoy email again!
> Cofounder, http://www.peerscope.com pure link sharing
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list