I have an ANTLR grammar and am defining a function in my language that allows an optional parameter. How can I check whether the optional parameter is passed in or not within the code generation block?
I'm basically looking for the syntax to do something like this hypothetical tree grammar statement:
myFunc returns [int retval] : 'myFunc' arg1=number arg2=string?
{
// Check if arg2 exists.
if (/* arg2 exists */) { $retval = $arg1.value + 10; }
else { $retval = $arg1.value; }
}
Any suggestions or pointers to documentation are greatly appreciated!