Transitional actions

Top  Previous  Next

Scripts > Productions > Actions > Transitional action

 

Besides the semantic actions there also is a type of very special "syntactic" actions.  A transitional action is executed after a token was accepted and before the next is recognized. This is the ideal time to insert of new dynamic tokens with AddToken, since the new token is then already available before the determination of the next token Transitional actions are necessary too, to assure that a production behaves just the same at its use for look-ahead in the text as normally. A divergent behavior could arise if during parsing new dynamic tokens are produced or if the text scope is changed. But if such a change is executed as a transition action, it is executed also during the look-ahead temporarily. Nevertheless, the set of the dynamic tokens and the text scope will remain the same before and after the look-ahead.

 

As transitional actions primarily are considered the functions: AddToken, PushScope and PopScope. As transitional actions they are executed, if they are appended to the expression for a token in conjunction with a dot.

 

Examples:

 

ID.AddToken(xState.str(), "CLASS")

ID[n].AddToken(xState.str(), "CLASS")

ID[n].AddToken(xState.str(), "CLASS", "NewScope").PushScope("NewScope");

 

It isn't possible to define a transitional action for a token, if a "normal" action is also assigned to it.

 

At the generation of C++ code the action only is copied, i.e. e.g. no automatic adaptation to the character type is carried out.

 

An interesting application is the recognition of constructors of c++ classes. Such constructors are indicated by an identifier followed by two colons and the same identifier again, e.g. "CParser::CParser". Normally the repeated identifier can easily be recognized by semantic code. However, such code isn't executed at a look-ahead. In this case you could defines a placeholder token "CLASS" and add the identifier to it during it's first recognition. The second occurrence is then recognized by the CLASS token.

 

 

IsScoped ::= 

ID "::" ID 

 

 

IsClass ::=

ID.AddToken(xState.str(), "CLASS")

"::"

CLASS

 

 

IF(IsScoped())

  IF(IsClass())

    ID.AddToken(xState.str(), "CLASS") 

    "::" CLASS  {{out << "class found"; }}

  ELSE

    ID "::" ID     {{out << "member function found"; }}

  END    

ELSE

  ID               {{out << "identifier found"; }}

END  

 

 

 

 



This page belongs to the TextTransformer Documentation

Home  Content  German