[antlr-interest] Re: TreeParsing with various roots
Bryan Ewbank
ewbank at synopsys.com
Mon Nov 8 06:47:02 PST 2004
Paul,
Another option is to have each node have "type" (the usual beastie) and
provide a "subtype" field as well that contains the actual operator.
I'm doing that for qualifiers - "const", "static", etc all report as
#[QUALIFIER,name], but have a subtype field that contain a bitfield telling
me which qualifer was seen.
It requires intermediate rules in the parser to morph the tokens, but it
seems worth it to me...
qualifier:
: CONST { ## = #[QUALIFIER, CONST->getText()]; ## ->
setSubtype(QUAL_CONST); }
| STATIC { .... }
-- Bryan Ewbank
----- Original Message -----
From: "lgcraymer" <lgc at mail1.jpl.nasa.gov>
To: <antlr-interest at yahoogroups.com>
Sent: Wednesday, November 03, 2004 17:42
Subject: [antlr-interest] Re: TreeParsing with various roots
>
>
> Paul--
>
> Unfortunately, the answer to your question is "not yet". Alternatives
> for roots should be supported--I started to do that for 2.8, but did
> not finish--but 2.x currently does not support them.
>
> 3.0 will: Ter, Monty, and I discussed this at last summer's cabal.
>
> --Loring
>
>
> --- In antlr-interest at yahoogroups.com, "Paul J. Lucas"
> <pauljlucas at m...> wrote:
> > Suppose I have in a parser:
> >
> > compExpr
> > : re1rangeExpr
> > (co:compOp! re:rangeExpr!
> > {
> > ## = #(co, re1, re2)
> > }
> > )?
> > ;
> >
> > compOp
> > : EQ | NE | LT | LE | GT | GE
> > ;
> >
> > How to I write the corresponding Treeparser?
> >
> > compExpr
> > : #( xxx re1=rangeExpr re2=RangeExpr )
> > ;
> >
> > What goes in the place of the "xxx"? Ideally, I'd like to
> > share the code for all compOps.
> >
> > I *could* do:
> >
> > compOp
> > : (EQ | NE | LT | LE | GT | GE)
> > {
> > ##.setType( COMP_OP );
> > }
> > ;
> >
> > then:
> >
> > compExpr
> > : #( co:COMP_OP re1=rangeExpr re2=RangeExpr )
> > {
> > // do something with co.getText()
> > }
> > ;
> >
> > But having to use the text of the original token seems a bit
> > hokey to me. Is there a better way?
> >
> > - Paul
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
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