epdv | 1 Jun 2009 08:09
Picon
Picon

Tokens and types: Size/Maximum available?

Hello!

I'm asking here, because when trying to access 
"gmane.comp.parsers.antlr.general", the web interface always tells me
"No such group.". Seems, a user group has been listed at gmane but was closed.

However, my question is about how to access the amount of tokens and token types,
preferrably as a static constant or method. I'd guess, the antlr parser
generator will know at runtime, but I cannot find any value.

Could You give me a hint, where to find it or which option to activate?

Kind regards

Peter Nabbefeld

xiaohua guo | 1 Jun 2009 19:00
Picon

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:&nbsp; <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>&nbsp;&nbsp;&nbsp; :IVALUE {$value=Integer.parseInt($IVALUE.text);}<br>&nbsp;&nbsp;&nbsp; ;<br>...<br><br>IVALUE : '1'..'9'('0'..'9')*;<br>
FVALUE :IVALUE | (('0' | ('1'..'9')*) '.' ('1'..'9')*);<br><br>My problem is fvalue,&nbsp; 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?&nbsp; Thank you!<br><br>Cheers!<br><br>
Xiaohua<br><br><br></p></div>
Johannes Luber | 1 Jun 2009 23:05
Picon
Picon

Re: 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!

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

Gmane