[antlr-interest] Re: Simple Question

micheal_jor open.zone at virgin.net
Mon Jun 16 17:38:28 PDT 2003


<SNIP>

> modelica_file
>     : (within_clause)? (("final")? class_definition SEMI!)* EOF!
>         { ## = #([FILE, "FILE"], ##); }
>     ;
> 
>  
> Note, specifically, the use of "#([FILE, "FILE"], ...)"

<SNIP>

> tokens {
>     FILE<AST=FileNode>; DECLARATION; DEFINITION; FUNCTION_CALL; 
TYPE;
>    ...
> }
>  
> Note the "File<AST=FileNode>..." part.

> So, is my assessment correct (i.e. this feature doesn't work with 
synthetic nodes...of which I have *many*).  Or am I doing something 
wrong?

Mike,

You didn't mention which language you are using so this is a rather 
generic answer by neccesity:

In the scenario above, the ANTLR codegen *should* have created a node 
for your imaginary FILE tokenID using an instance of the FileNode 
class (I assume that this class correctly implements the AST 
interface). IOW, you don't seem to be doing anything wrong...*

[* More access to your grammar might change this opinion however ;-)]

There is [at least?] another way to declare a custom class for an 
imaginary AST node. You can use the [<TokenID>, <TokenText>, 
<TokenClass>] form of the ANTLR node constructor syntax. E.g.

     {  ## = #([FILE, "FILE", "FileNode"], ##);  }

Cheers,

Micheal
ANTLR/C# codegen



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list