any advice on how can I get the return value
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!
Cheers!
Xiaohua
<div><p>Hi,<br><br>In my language specification (using EBNF), including the following contents: <br><br>...<br>value = ivalue | fvalue<br>ivalue = any positive integer<br>fvalue = any positive integer or float<br>...<br><br><br>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.<br>
I have added the code as the following in my gramer file. <br><br>...<br>ivalue returns [int value] <br> :IVALUE {$value=Integer.parseInt($IVALUE.text);}<br> ;<br>...<br><br>IVALUE : '1'..'9'('0'..'9')*;<br>
FVALUE :IVALUE | (('0' | ('1'..'9')*) '.' ('1'..'9')*);<br><br>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. <br><br>fvalue returms [?? value]<br>....<br><br>And the value mentioned above (may be integer or float) has the same problem.<br>How can I solve this problems? Can someone give me some advice? Thank you!<br><br>Cheers!<br><br>
Xiaohua<br><br><br></p></div>