[antlr-interest] Assign words to a variable inside a rule ????

John B. Brodie jbb at acm.org
Tue Oct 30 09:19:11 PDT 2007


Greetings!

OJAY78 wrote:
>I have a problem with assigning words to variables inside a rule. This is the function:
>
>fillStrFunction returns[String value]
>	:
>	'fill' '(' source = parameter '|' ( mode='left' | mode ='right')  '|' replace = STRING_CONST '|' length = STRING_CONST ')' 
>	{
>		$value = FELHelper.fillStrFunction($source.value, $mode.text, $replace.text, $length.text);
>	}
>	;
>
>and here is the call of my function:
>fill( "678" | left | "0" | 8 ) -> "00000678"
...........................^^^---should this be in quotes.
>
>
>It results in a NoViableAltException, but why? Can anyone explain me
>I can access such words inside a rule?
>


I do not know what the rule for STRING_CONST looks like, but if it is
meant to be like its name e.g. to recognize a quoted sequence of
characters; then maybe the 4th item in your call has the wrong syntax?

As far as I know, NoViableAltException is raised when you actually try
to execute your generated parser.  While issues with rule labels
should arise when running the org.antlr.Tool.

When does the NoViableAltException happen?

Your fillStrFunction rule above looks okay to me; did not try running it
through the org.antlr.Tool though... (assuming the call to
FELHelper.fillStrFunction is proper, which ANTLR can't check)

   -jbb


More information about the antlr-interest mailing list