Often we wish to group a set of lexemes together into lexeme classes if they logically behave in some uniform manner; for example, if they act uniformly in a lexical rule. By grouping related lexemes together into a class we can refer to them succinctly by their class name.
The syntax of a lexeme class declaration is
Lexeme_Class_Decl ::= lexeme class Lexeme_Class_Eq and ¼ and Lexeme_Class_Eq ; Lexeme_Class_Eq ::= Id = Lexeme_Spec - ¼ - Lexeme_Spec Lexeme_Spec ::= String | Id Regexp
The following example,
the lexeme classes MainKeywords, Symbols, and Literals
are defined.
lexeme class MainKeywords =
"rewrite" | "inference" | "match" | "matchall" | "matchscan"
| "refine" | "classof" | "type" | "datatype" | "instantiate"
| "lexeme" | "bitfield" | "begin" | "syntax"
| "dataflow" | "module" | "signature" | "constraint" | "declare"
| "procedure" | "fun" | "function" | "domain"
| "graphtype" | "graphrewrite"
and Symbols =
".." | "..." | "<->" | "::" | "&&" | "||" | "++" | "--" | "->"
| "<<" | ">>" | ">=" | "<=" | "+=" | "-=" | "*=" | "/=" | "%=" | "=="
| "!=" | "<<=" | ">>=" | "&=" | "|=" | "^=" | "=>" | "<-" | "<=>"
| ":=" | ":-" | LONG_BAR /\-\-\-\-\-+/
and Literals =
INT_TOK /{integer}/
| REAL_TOK /{real}/
| CHAR_TOK /{character}/
| STRING_TOK /{string}/
;