[antlr-interest] how to deal with optional parameters in ast
Dave Cramer
davec at postgresintl.com
Tue Mar 27 12:51:02 PDT 2007
On 27-Mar-07, at 3:36 PM, Gavin Lambert wrote:
> At 02:56 28/03/2007, Dave Cramer wrote:
>> I have a rule which is
>>
>> WAKEUP expr*NEWLINE-> ^(WAKEUP expr*)
>>
>> if the input is
>>
>> WAKEUP NEWLINE
>>
>> the ast will just be ^ WAKEUP
>>
>> What's the right way to deal with this ?
>
> That seems correct to me. What were you wanting it to do instead?
>
> If WAKEUP is always supposed to have a parameter, then you should
> change * to + in both places. If it's allowed to have no
> parameters, then what you have already seems like the best option
> (assuming your description is correct).
>
OK, then in the treewalker I am going to eventually call a function
called wakeUp(int seconds) where if the optional seconds is not
provided I will default it to something. The question really is how
to write the treewalker with two possibililties; one with the param,
one without ?
Dave
More information about the antlr-interest
mailing list