× News Cego SysMT Croom Web Statistics Impressum
SysMT Logo

The Dragon Parser Generator

7   Semantic actions
Back to TOC

While parsing an input file, after each reduction of a grammar production a semantic action can be performed. A semantic action in terms of dragon is implemented as a derived method of the parser class. The action method are defined as virtual in the main parser class without any input args. The corresponding token values of the reduced production can be read with the provided

7.1   Sample action method

We will extend the method A1 of the G1 grammar sample in a way that the tokens are printed to stdout, which have been scanned by the scanner.

void A1() {

   Chain* pToken = getTokenList().First();
   while ( pToken )
   {
	cout << Token is :  << *pToken;
   }    
}

With the getTokenList() method provided by the parser class G1, the current list of tokens are provided to the semantic action. The list contains each token in string format ( base class Chain ) and the first element in the list is the last reduced token.