[antlr-interest] Problem removing warning
Jim Idle
jimi at temporal-wave.com
Fri Mar 19 11:38:37 PDT 2010
Yes - you can retain all that stuff, but if you try to do it the way you have it, you won't get a tree that makes sense. You can see a much more complicated example using my C# parser, which is online at:
http://www.temporal-wave.com/index.php?option=com_psrrun&view=psrrun&Itemid=58
All you need do is not kill the information I am killing. (and add | DOT element to the expr). However, you know what you want :-)
jim
> -----Original Message-----
> From: Gerald Rosenberg [mailto:gerald at certiv.net]
> Sent: Friday, March 19, 2010 11:24 AM
> To: Jim Idle
> Cc: antlr-interest interest
> Subject: Re: [antlr-interest] Problem removing warning
>
> Thanks, Jim. Please understand though that I dumbed down the test
> grammar to minimally illustrate the problem I was asking about - my
> actual grammar shapes a much more complex tree and uses "tidy
> tokens";). The revision you suggest unfortunately looses a bit too
> much
> intrinsic information that would be difficult to infer if at all in a
> later pass. As I mentioned, the order, existence and position of the
> parens and leading dots are significant - (foo), .foo, (.foo), and foo
> are not equivalent and need to be distinctly represented in the tree.
>
> On 3/19/2010 10:41 AM, Jim Idle wrote:
> > That will give a tree that isn't very useful ;-) You need to express
> this in LL form such that the things that can be elements of your
> compound appear at the bottom of the tree. Then use DOT and not '.',
> make that be the root node and do not try to impose any semantic
> verification via syntactical specifications. You get:
> >
> >
> > grammar T;
> >
> > options { output=AST; }
> >
> > tokens { EXPR; FUNC;}
> >
> > aago : (expr NL)+ EOF
> > ->^(EXPR expr)+
> > ;
> >
> > expr
> > : element (DOT^ element)*
> > ;
> >
> > element
> > : LPAREN! expr RPAREN! // Sometimes you want to preserve the
> LPAREN here
> > | ID (LPAREN^ expr RPAREN)? // function call
> > ;
> >
> > LPAREN : '(' ;
> > RPAREN : ')' ;
> > ID : ('A'..'Z')+ ;
> > DOT : '.' ;
> > NL : ('\n'|'\r')+ ;
> > ANY : . {skip();} ;
> >
> >
> >
> >> -----Original Message-----
> >> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> >> bounces at antlr.org] On Behalf Of Gerald Rosenberg
> >> Sent: Friday, March 19, 2010 10:01 AM
> >> To: antlr-interest interest
> >> Subject: [antlr-interest] Problem removing warning
> >>
> >> Having a bit of difficulty in figuring out how to unambiguously
> parse
> >> this into an AST.
> >> Order of the elements is significant, the parens are significant,
> and
> >> the leading dot is significant.
> >>
> >> (.buf_unittest.complex_opt1).foo;
> >> .buf_unittest.complex_opt1.fum;
> >> (buf_unittest.complex_opt1).(.buf_unittest.quux);
> >> (.buf_unittest.complex_opt1).(buf_unittest.corge).qux;
> >> (complex_opt2).baz;
> >> (complex_opt2).(grault);
> >> (complex_opt2).bar.foo;
> >> (complex_opt2).bar.(quux);
> >> (complex_opt2).bar.(buf_unittest.corge).qux;
> >> (complex_opt2).(garply).foo;
> >> (complex_opt2).(garply).(.buf_unittest.quux);
> >> (complex_opt2).(buf_unittest.garply).(corge).qux;
> >> (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo;
> >> (complex_opt2).fred.waldo;
> >> (buf_unittest.complex_opt3).qux;
> >> (complex_opt3).complexoptiontype5.plugh;
> >> (complexopt6).xyzzy;
> >>
> >> The rule ident_parens following appears to work, but Antlr is
> >> complaining "Decision can match input such as "'.' ID" using
> multiple
> >> alternatives: 1, 2" on both identN and identO. I can see the
> >> theoretical overlap, but cannot tell if the warning is actually
> >> significant or how to fix the rules to avoid the warning.
> >>
> >> ident_parens
> >> : (identM | identN | identO ) ('.' ( identM | identO ) )*
> >> ;
> >>
> >> identM
> >> : '(' '.' ipd+=ID ( '.' ipd+=ID )* ')' -> ^(
> IDENT_PARENSDOT
> >> $ipd+ )
> >> | '(' ip+=ID ( '.' ip+=ID )* ')' -> ^( IDENT_PARENS
> $ip+
> >> )
> >> ;
> >>
> >> identN
> >> : '.' id+=ID ( '.' id+=ID )* -> ^( IDENT_DOT
> $id+ )
> >> ;
> >>
> >> identO
> >> : i+=ID ( '.' i+=ID )* -> ^( IDENT $i+ )
> >> ;
> >>
> >>
> >> Thanks...
> >>
> >
> >
> >
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: http://www.antlr.org/mailman/options/antlr-
> interest/your-email-address
> >
> >
>
>
More information about the antlr-interest
mailing list