Comments

The Metal compiler automatically generates abstract syntax operators to handle comments. But the language offers no mechanism to describe the concrete syntax of these comments. We must do this in the lexical description. For simple comment needs, such as one line comments, we only need to add a line to the tokens file indicating how the comment begins. For Exp, we specify that comments begin with a % symbol. In the Exp.tokens file, include one line with the appropriate regular expression and action just before the lines we previously modified. The result should be:


   <sentences>"%"               BEGIN comment;\
   <sentences>[A-Z][A-Z0-9_]*   return(ID);\
   <sentences>[0-9][0-9]*       return(INTEGER);\

When it encounters a %, the parser tells Centaur to store the text read until the end of the line in one of two predefined annotations named prefix and postfix.


Tutorial