[antlr-interest] How to use an optional rule attribute in an action?

troy runkel trunkel at gmail.com
Tue Jun 26 11:50:35 PDT 2007


Greetings,

I'm using ANTLR v3 with the C-target and have a situation like the
following.  I have an optional rule called number and I want to access
the text attribute of that rule if and only if the rule was applied.
Using the C-target, $number is uninitialized if the rule wasn't
applied.  Is there a way, in the action, to determine if $number.text
is valid?

create_procedure :
        'CREATE' ('PROC' | 'PROCEDURE') procedure_name ( ';' number )?
        {
            if ($number is valid)
                someFunction($number.text);
        }

Thanks.

Troy Runkel


More information about the antlr-interest mailing list