Question

I have the following grammar rule:

pacman
  : section section map section
  ;

I want to write a Java action for this rule that processes the three different sections differently. What are the handles for the three different instances?


This is psuedocode showing what I want:

pacman
  : section section map section
  {
    processFirstSection($section[0]);
    if(checkSecondSection($section[1]))
    {
      //The if statement isn't important itself;
      //the point is that I do completely different
      //things with each section
      handleThirdSection($section[2]);
    }
  }
  ;
Was it helpful?

Solution

pacman
  : section1=section section2=section map section3=section
  {
    processFirstSection($section1);
    if(checkSecondSection($section2))
    {
      handleThirdSection($section3);
    }
  }

In general, the rule

 rule : name=Token otherName=rule

lets you access the token Token using $name and the rule rule using $otherName.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top