[antlr-interest] TokenStreamRewriteEngine: possible to use non-terminals instead of tokens?
Terence Parr
parrt at cs.usfca.edu
Wed Feb 4 10:42:10 PST 2004
On Feb 4, 2004, at 6:52 AM, SainTiss wrote:
> Using the java.g grammar, what I would like to do now is delete the
> type
> specifier from a declaration statement:
> "int myInt = 7;" => "myInt = 7;"
>
> This should only be done when the declaration is a statement, and not
> when it
> is a class field for example...
> So it should only apply for the rule:
> statement
> : (declaration)=> declaration SEMI!
>
> However, it seems that the rewriteEngine can only delete a range of
> tokens.
> SEMI is a token, but "declaration" is not so it seems (I guess its
> type is
> "void" since that's the return type of the declaration() method?).
> Still, I
> can't put the replace action where the type token is, because that's
> in the
> "identifier" rule, which would mean all identifiers would be deleted...
>
> So is there a way I can "navigate" from "declaration" to the typeSpec
> and then
> to the identifier token in order to remove it?
You need context info to trickle into typeSpec so that it knows when to
remove that token. you can pass a parameter around or set a context
instance variable (ick). Or, go the other way: just set an index in
typeSpec as to the index of the ID token. Then later if you ever want
to delete it, you know the index.
Ter
--
Professor Comp. Sci., University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Co-founder, http://www.jguru.com
Co-founder, http://www.knowspam.net enjoy email again!
Co-founder, 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