1
2
3
4
5
6 classmap LexerFileClassMap;
7
8 tokens LexerFileTokens
9 {
10 (CLASSMAP, "'classmap'"), (TOKENS, "'tokens'"), (KEYWORDS, "'keywords'"), (EXPRESSIONS, "'expressions'"), (LEXER, "'lexer'"),
11 (VARIABLES, "''variables'"), (ACTIONS, "'actions'"), (DOLLAR, "'$'"),
12 (ASSERT, "'assert'"), (ELIF, "'elif'"), (ENDIF, "'endif'"), (BOOL, "'bool'"), (TRUE, "'true'"), (FALSE, "'false'"),
13 (SBYTE, "'sbyte'"), (BYTE, "'byte'"), (SHORT, "'short'"), (USHORT, "'ushort'"), (INT, "'int'"),
14 (UINT, "'uint'"), (LONG, "'long'"), (ULONG, "'ulong'"), (FLOAT, "'float'"), (DOUBLE, "'double'"), (CHAR, "'char'"), (WCHAR, "'wchar'"), (UCHAR, "'uchar'"), (VOID, "'void'"),
15 (ENUM, "'enum'"), (CAST, "'cast'"), (INTERFACE, "'interface'"), (NAMESPACE, "'namespace'"), (USING, "'using'"),
16 (STATIC, "'static'"), (EXTERN, "'extern'"), (AS, "'as'"), (IS, "'is'"), (EXPLICIT, "'explicit'"), (DELEGATE, "'delegate'"), (INLINE, "'inline'"), (CDECL, "'cdecl'"), (NOTHROW, "'nothrow'"),
17 (PUBLIC, "'public'"), (PROTECTED, "'protected'"), (PRIVATE, "'private'"), (INTERNAL, "'internal'"), (VIRTUAL, "'virtual'"), (ABSTRACT, "'abstract'"), (OVERRIDE, "'override'"),
18 (SUPPRESS, "'suppress'"), (OPERATOR, "'operator'"), (CLASS, "'class'"), (RETURN, "'return'"),
19 (IF, "'if'"), (ELSE, "'else'"), (SWITCH, "'switch'"), (CASE, "'case'"), (DEFAULT, "'default'"),
20 (WHILE, "'while'"), (DO, "'do'"), (FOR, "'for'"), (BREAK, "'break'"), (CONTINUE, "'continue'"), (GOTO, "'goto'"), (TYPEDEF, "'typedef'"), (TYPENAME, "'typename'"), (TYPEID, "'typeid'"),
21 (CONST, "'const'"), (CONSTEXPR, "'constexpr'"), (NULLLIT, "'null'"), (THIS, "'this'"), (BASE, "'base'"), (CONSTRUCT, "'construct'"), (DESTROY, "'destroy'"),
22 (NEW, "'new'"), (DELETE, "'delete'"), (SIZEOF, "'sizeof'"), (TRY, "'try'"), (CATCH, "'catch'"), (THROW, "'throw'"),
23 (CONCEPT, "'concept'"), (WHERE, "'where'"), (AXIOM, "'axiom'"), (AND, "'and'"), (OR, "'or'"), (EXCLAMATION, "'!'"), (UNIT_TEST, "'unit_test'"),
24 (ID, "identifier"), (FLOATINGLIT, "floating literal"), (INTLIT, "integer literal"), (CHARLIT, "character literal"), (STRINGLIT, "string literal"),
25 (EQUIVALENCE, "'<=>'"), (IMPLICATION, "'=>'"), (DISJUNCTION, "'||'"), (AMPAMP, "'&&'"),
26 (BITOR, "'|'"), (BITXOR, "'^'"), (AMP, "'&'"), (EQ, "'=='"), (NEQ, "'!='"), (LEQ, "'<='"), (GEQ, "'>='"), (SHIFTLEFT, "'<<'"), (SHIFTRIGHT, "'>>'"),
27 (PLUS, "'+'"), (MINUS, "'-'"), (STAR, "'*'"), (DIV, "'/'"), (REM, "'%'"), (PLUSPLUS, "'++'"), (MINUSMINUS, "'--'"), (CPL, "'~'"), (DOT, "'.'"), (ARROW, "'->'"),
28 (LBRACKET, "'['"), (RBRACKET, "']'"), (LPAREN, "'('"), (RPAREN, "')'"), (LANGLE, "'<'"), (RANGLE, "'>'"), (LBRACE, "'{'"), (RBRACE, "'}'"), (COMMA, "','"), (ASSIGN, "'='"),
29 (COLON, "':'"), (SEMICOLON, "';'"), (HASH, "'#'")
30 }
31
32 keywords LexerFileKeywords
33 {
34 ("classmap", CLASSMAP), ("tokens", TOKENS), ("keywords", KEYWORDS), ("expressions", EXPRESSIONS), ("lexer", LEXER),
35 ("variables", VARIABLES), ("actions", ACTIONS),
36 ("assert", ASSERT), ("elif", ELIF), ("endif", ENDIF), ("bool", BOOL), ("true", TRUE), ("false", FALSE),
37 ("sbyte", SBYTE), ("byte", BYTE), ("short", SHORT), ("ushort", USHORT), ("int", INT), ("uint", UINT), ("long", LONG), ("ulong", ULONG),
38 ("float", FLOAT), ("double", DOUBLE), ("char", CHAR), ("wchar", WCHAR), ("uchar", UCHAR), ("void", VOID), ("enum", ENUM), ("cast", CAST), ("interface", INTERFACE),
39 ("namespace", NAMESPACE), ("using", USING), ("static", STATIC), ("extern", EXTERN), ("as", AS), ("is", IS), ("explicit", EXPLICIT), ("delegate", DELEGATE), ("inline", INLINE), ("cdecl", CDECL), ("nothrow", NOTHROW),
40 ("public", PUBLIC), ("protected", PROTECTED), ("private", PRIVATE), ("internal", INTERNAL), ("virtual", VIRTUAL), ("abstract", ABSTRACT), ("override", OVERRIDE), ("suppress", SUPPRESS),
41 ("operator", OPERATOR), ("class", CLASS), ("return", RETURN), ("if", IF), ("else", ELSE),
42 ("switch", SWITCH), ("case", CASE), ("default", DEFAULT), ("while", WHILE), ("do", DO), ("for", FOR),
43 ("break", BREAK), ("continue", CONTINUE), ("goto", GOTO), ("typedef", TYPEDEF), ("typename", TYPENAME), ("typeid", TYPEID), ("const", CONST), ("constexpr", CONSTEXPR), ("null", NULLLIT), ("this", THIS), ("base", BASE),
44 ("construct", CONSTRUCT), ("destroy", DESTROY), ("new", NEW), ("delete", DELETE), ("sizeof", SIZEOF), ("try", TRY), ("catch", CATCH), ("throw", THROW),
45 ("concept", CONCEPT), ("where", WHERE), ("axiom", AXIOM), ("and", AND), ("or", OR), ("unit_test", UNIT_TEST)
46 }
47
48 expressions
49 {
50 ws = "[\n\r\t ]";
51 newline = "\r\n|\n|\r";
52 linecomment = "//[^\n\r]*{newline}";
53 blockcomment = "/\*([^*]|\*[^/])*\*/";
54 comment = "{linecomment}|{blockcomment}";
55 separators = "({ws}|{comment})+";
56 id = "{idstart}{idcont}*";
57 decdigits = "[0-9]+";
58 hexdigit = "[0-9a-fA-F]";
59 hexdigits = "{hexdigit}+";
60 hex4 = "{hexdigit}{hexdigit}{hexdigit}{hexdigit}";
61 hex8 = "{hex4}{hex4}";
62 octaldigits = "[0-7]+";
63 fraction = "{decdigits}?\.{decdigits}|{decdigits}\.";
64 sign = "\+|-";
65 exponent = "(e|E){sign}?{decdigits}";
66 integer = "(0{octaldigits}?|[1-9]{decdigits}?|0(x|X){hexdigits})(u|U)?";
67 floating = "({fraction}{exponent}?|{decdigits}{exponent})(f|F)?";
68 escape = "\\((x|X){hexdigits}|(d|D){decdigits}|{octaldigits}|u{hex4}|U{hex8}|(a|b|f|n|r|t|v|.))";
69 character = "(w|u)?'([^\\\r\n']+|{escape})'";
70 string = "((w|u)?@\"[^\"]*\")|(w|u)?\"([^\\\r\n\"]|{escape})*\"";
71 }
72
73 lexer LexerFileLexer
74 {
75 "{separators}" {}
76 "{id}" { int kw = GetKeywordToken(token.match); if (kw == INVALID_TOKEN) return ID; else return kw; }
77 "{integer}" { return INTLIT; }
78 "{floating}" { return FLOATINGLIT; }
79 "{character}" { return CHARLIT; }
80 "{string}" { return STRINGLIT; }
81 "$" { return DOLLAR; }
82 "<=>" { return EQUIVALENCE; }
83 "=>" { return IMPLICATION; }
84 "\|\|" { return DISJUNCTION; }
85 "&&" { return AMPAMP; }
86 "\|" { return BITOR; }
87 "^" { return BITXOR; }
88 "&" { return AMP; }
89 "==" { return EQ; }
90 "!=" { return NEQ; }
91 "<=" { return LEQ; }
92 ">=" { return GEQ; }
93 "<" { return LANGLE; }
94 ">" { return RANGLE; }
95 "<<" $(1) { return SHIFTLEFT; }
96 ">>" $(2) { return SHIFTRIGHT; }
97 "\+" { return PLUS; }
98 "-" { return MINUS; }
99 "\*" { return STAR; }
100 "/" { return DIV; }
101 "%" { return REM; }
102 "\+\+" { return PLUSPLUS; }
103 "--" { return MINUSMINUS; }
104 "!" { return EXCLAMATION; }
105 "~" { return CPL; }
106 "\." { return DOT; }
107 "->" { return ARROW; }
108 "\[" { return LBRACKET; }
109 "\]" { return RBRACKET; }
110 "\(" { return LPAREN; }
111 "\)" { return RPAREN; }
112 "\{" { return LBRACE; }
113 "\}" { return RBRACE; }
114 "," { return COMMA; }
115 "=" { return ASSIGN; }
116 ":" { return COLON; }
117 ";" { return SEMICOLON; }
118 "#" { return HASH; }
119
120 variables
121 {
122 double floatingLit;
123 bool floatingLitFloat;
124 ulong intLit;
125 bool intLitUnsigned;
126 uchar chrLit;
127 int chrLitPrefix;
128 ustring strLit;
129 int strLitPrefix;
130 int leftAngleCount;
131 bool parsingOperatorFunctionGroupId;
132 }
133
134 actions
135 {
136 $(1)={ if (parsingOperatorFunctionGroupId) return INVALID_TOKEN; }
137 $(2)={ if (leftAngleCount > 0) return INVALID_TOKEN; }
138 }
139 }