> Hi,
> 
> In my language specification (using EBNF), including the following
> contents:
> 
> ...
> value = ivalue | fvalue
> ivalue = any positive integer
> fvalue = any positive integer or float
> ...
> 
> 
> Now I have written an garmer file and generate java code. I hope when the
> parser read the token of ivalue, fvalue, it can recognized it's a value
> and
> then return the value.
> I have added the code as the following in my gramer file.
> 
> ...
> ivalue returns [int value]
>     :IVALUE {$value=Integer.parseInt($IVALUE.text);}
>     ;
> ...
> 
> IVALUE : '1'..'9'('0'..'9')*;
> FVALUE :IVALUE | (('0' | ('1'..'9')*) '.' ('1'..'9')*);
> 
> My problem is fvalue,  it may be integer or float, that means the return
> type is flexible. So I don't know the type of return value.
> 
> fvalue returms [?? value]
> ....
> 
> And the value mentioned above (may be integer or float) has the same
> problem.
> How can I solve this problems? Can someone give me some advice?  Thank
> you!

For this kind of question, please use the antlr-interest mailing list. 
antlr-dev is only for tool and target developer problems (and those who are 
following these discussions). But back to your problem.

Create a class which holds an enum, a float and an integer. Use the enum to 
designate if currently an integer or float has the valid value. In languages 
with unions the data part could be made more compact, but with Java this is 
optimum.

Johannes
> 
> Cheers!
> 
> Xiaohua

-- 
Nur bis 31.05.: GMX FreeDSL Komplettanschluss mit DSL 6.000 Flatrate und
Telefonanschluss nur 17,95 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org/mailman/listinfo/antlr-dev

Reply via email to