[antlr-interest] 3.1.4 + C runtime: Imaginary tokens lost their names?
Richard Thrippleton
richard.thrippleton at progress.com
Fri Apr 3 02:27:57 PDT 2009
Gary R. Van Sickle wrote:
> Here's a new one: My imaginary tokens aren't getting printable names now
> unless I explicitly set them via a rule like this:
>
> struct_or_union_specifier
> : [...whatever...]
> | lc='struct' IDENTIFIER -> ^(STRUCT[$lc, "STRUCT"] IDENTIFIER)
> ....
>
> If in my calling program I do this:
>
> printf((const char*)TheAST.tree->toStringTree(TheAST.tree)->chars);
>
> I get the following:
>
> ( ( int) (DIRECT_DECLARATOR abc (PARAM_TYPE_LIST ( ( ( int)
> (DIRECT_DECLARATOR nothing))))) (COMPOUND_STATEMENT (RETURN 1))) ( ( int)
> (DIRECT_DECLARATOR main (PARAM_TYPE_LIST ( ( ( int) (DIRECT_DECLARATOR
> dummy))))) (COMPOUND_STATEMENT ( ( int) ( (DIRECT_DECLARATOR var)))
> (FUNCTION_CALL call1 1.2 0) (FUNCTION_CALL CreateThread thread1)
> (FUNCTION_CALL CreateThread thread2) (FUNCTION_CALL StartMultitasking)
> (RETURN 0)))
>
> Every one of the "( "'s up there is an imaginary token that I can't do the
> "$lc" thing to because they derive from nonterminals.
Is there any reason that you can't do STRUCT["STRUCT"] (in the case
where you don't have a token to derive from such as $lc)?
Also, if you want to derive from a nonterminal such as the output of a
rule, $rule.start can be derived from (the first token successfully
matched by that rule).
Richard
More information about the antlr-interest
mailing list