[antlr-interest] Re: ambiguous grammar
cintyram <cintyram at yahoo.com>
cintyram at yahoo.com
Sat Jan 18 19:37:12 PST 2003
hi , i have included a small part from one of my previous grammars.
i followed the suggestions i got on this list and did not have a
seperate token type for '.' DOT but tried to match it where ever
required ;
also for your $.1 rule you might try
rule : DOLLAR FLOATING ;
with k set appropriately , because now FLOATING is the expected token
for two rules.
please tell if this does not work ;
--- excerpt ---
protected ALPHA : ('a'..'z' | 'A'..'Z'|'_') ;
protected DIGIT : '0'..'9' ;
ID
options {
testLiterals = true;
}
: ALPHA (ALPHA|DIGIT)* ;
protected SUFFIX : ('k'|'M') ; /// kilo mega etc.
protected EXPONENT : ( ('e')('+'|'-')?(DIGIT)+ ) ;
protected INT : (DIGIT) + ; /// match the integral part
123
protected FLOATING : ( '.' (DIGIT)+ ) ;
NUM : INT ( FLOATING ) ? ( SUFFIX )? (EXPONENT ) ?
| ( FLOATING ) ( SUFFIX )? (EXPONENT ) ?
--- end ---
cheers
ram
--- In antlr-interest at yahoogroups.com, "beeh1973 <hastur4711 at b...>"
<hastur4711 at b...> wrote:
> hi,
>
> in my language i have float literals like .1 and
> expressions like $.1
>
> i am using the following lexer rule to recognize numbers
>
> NUMBER
> : '.' { _ttype = DOT; } // a single dot
> (((DIGIT)+ { _ttype = FLOAT} ) // a float number
> ((EXPONENT))?)?
> |
> // some more cases for integers and floats > 1
> ...
>
> DOLLAR : '$' ;
>
>
> in the parser i try to match $.1 with this rule:
>
> component:
> DOLLAR^ DOT NUMBER
> ;
>
> while parsing $.1 i get an error that FLOAT is unexpected at that
> point.
>
> while i understand why this is happening; a call to nextToken simply
> returns the next token which is a FLOAT no DOT, i do not understand
> how to
> fix the grammar. can anybody help me with this?
>
> thanks in advance,
> alphonse bendt
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list