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: [email protected] [mailto:antlr-interest-
> [email protected]] 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

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to