1
2
3
4
5
6 classmap LexerFileClassMap;
7
8 prefix "sng2html/sng2html";
9
10 tokens LexerFileTokens
11 {
12 (CLASSMAP, "'classmap'"), (PREFIX, "'prefix'"), (TOKENS, "'tokens'"), (KEYWORDS, "'keywords'"), (EXPRESSIONS, "'expressions'"), (LEXER, "'lexer'"),
13 (VARIABLES, "''variables'"), (ACTIONS, "'actions'"), (API, "'api'"), (INCLUDE, "'include'"),
14 (FILEPATH, "file path"), (DOLLAR, "'$'"), (EXCLAMATION, "'!'"),
15 (AUTO, "'auto'"), (REGISTER, "'register'"), (STATIC, "'static'"), (EXTERN, "'extern'"), (MUTABLE, "'mutable'"),
16 (CHAR, "'char'"), (WCHART, "'wchar_t'"), (BOOL, "'bool'"), (SHORT, "'short'"), (INT, "'int'"), (LONG, "'long'"), (SIGNED, "'signed'"), (UNSIGNED, "'unsigned'"),
17 (FLOAT, "'float'"), (DOUBLE, "'double'"), (VOID, "'void'"),
18 (TYPEDEF, "'typedef'"), (CONST, "'const'"), (VOLATILE, "'volatile'"), (USING, "'using'"), (NAMESPACE, "'namespace'"), (THROW, "'throw'"), (SIZEOF, "'sizeof'"), (OPERATOR, "'operator'"),
19 (DYNAMICCAST, "'dynamic_cast'"), (STATICCAST, "'static_cast'"), (REINTERPRETCAST, "'reinterpret_cast'"), (CONSTCAST, "'const_cast'"), (TYPEID, "'typeid'"), (THIS, "'this'"),
20 (NEW, "'new'"), (DELETE, "'delete'"), (TRUE, "'true'"), (FALSE, "'false'"), (NULLPTR, "'nullptr'"),
21 (CASE, "'case'"), (DEFAULT, "'default'"), (IF, "'if'"), (ELSE, "'else'"), (SWITCH, "'switch'"), (WHILE, "'while'"), (DO, "'do'"), (FOR, "'for'"),
22 (BREAK, "'break'"), (CONTINUE, "'continue'"), (RETURN, "'return'"), (GOTO, "'goto'"), (TRY, "'try'"), (CATCH, "'catch'"),
23 (ID, "identifier"), (INTLIT, "integer literal"), (FLOATINGLIT, "floating literal"), (CHARLIT, "character literal"), (STRINGLIT, "string literal"),
24 (DISJUNCTION, "'||'"), (AMPAMP, "'&&'"), (DOTSTAR, "'.*'"), (ARROWSTAR, "'->*'"),
25 (BITOR, "'|'"), (BITXOR, "'^'"), (AMP, "'&'"), (EQ, "'=='"), (NEQ, "'!='"), (LEQ, "'<='"), (GEQ, "'>='"), (SHIFTLEFT, "'<<'"), (SHIFTRIGHT, "'>>'"),
26 (PLUS, "'+'"), (MINUS, "'-'"), (STAR, "'*'"), (DIV, "'/'"), (REM, "'%'"), (PLUSPLUS, "'++'"), (MINUSMINUS, "'--'"), (CPL, "'~'"), (DOT, "'.'"), (ARROW, "'->'"), (QUEST, "'?'"),
27 (LPAREN, "'('"), (RPAREN, "')'"), (LBRACE, "'{'"), (RBRACE, "'}'"), (LBRACKET, "'['"), (RBRACKET, "']'"), (LANGLE, "'<'"), (RANGLE, "'>'"), (ELLIPSIS, "'...'"),
28 (COLONCOLON, "'::'"), (COLON, "':'"), (SEMICOLON, "';'"), (HASH, "'#'"), (COMMA, "','"), (ASSIGN, "'='"), (MULASSIGN, "'*='"), (DIVASSIGN, "'/='"), (REMASSIGN, "'%='"),
29 (PLUSASSIGN, "'+='"), (MINUSASSIGN, "'-='"), (SHIFTLEFTASSIGN, "'<<='"), (SHIFTRIGHTASSIGN, "'>>='"), (ANDASSIGN, "'&='"), (XORASSIGN, "'^='"), (ORASSIGN, "'|='")
30 }
31
32 keywords LexerFileKeywords
33 {
34 ("classmap", CLASSMAP), ("prefix", PREFIX), ("tokens", TOKENS), ("keywords", KEYWORDS), ("expressions", EXPRESSIONS), ("lexer", LEXER),
35 ("variables", VARIABLES), ("actions", ACTIONS), ("api", API), ("include", INCLUDE),
36 ("auto", AUTO), ("register", REGISTER), ("static", STATIC), ("extern", EXTERN), ("mutable", MUTABLE),
37 ("char", CHAR), ("wchar_t", WCHART), ("bool", BOOL), ("short", SHORT), ("int", INT), ("long", LONG), ("signed", SIGNED), ("unsigned", UNSIGNED),
38 ("float", FLOAT), ("double", DOUBLE), ("void", VOID),
39 ("typedef", TYPEDEF), ("const", CONST), ("volatile", VOLATILE), ("using", USING), ("namespace", NAMESPACE), ("throw", THROW), ("sizeof", SIZEOF), ("operator", OPERATOR),
40 ("dynamic_cast", DYNAMICCAST), ("static_cast", STATICCAST), ("reinterpret_cast", REINTERPRETCAST), ("const_cast", CONSTCAST), ("typeid", TYPEID), ("this", THIS),
41 ("new", NEW), ("delete", DELETE), ("true", TRUE), ("false", FALSE), ("nullptr", NULLPTR),
42 ("case", CASE), ("default", DEFAULT), ("if", IF), ("else", ELSE), ("switch", SWITCH), ("while", WHILE), ("do", DO), ("for", FOR),
43 ("break", BREAK), ("continue", CONTINUE), ("return", RETURN), ("goto", GOTO), ("try", TRY), ("catch", CATCH)
44 }
45
46 expressions
47 {
48 ws = "[\n\r\t ]";
49 newline = "\r\n|\n|\r";
50 linecomment = "//[^\n\r]*{newline}";
51 blockcomment = "/\*([^*]|\*[^/])*\*/";
52 comment = "{linecomment}|{blockcomment}";
53 separators = "({ws}|{comment})+";
54 id = "{idstart}{idcont}*";
55 decdigit="[0-9]";
56 octaldigit="[0-7]";
57 hexdigit="[0-9a-fA-F]";
58 hex4 = "{hexdigit}{hexdigit}{hexdigit}{hexdigit}";
59 hex8 = "{hex4}{hex4}";
60 octalliteral = "0{octaldigit}*";
61 decimalliteral = "[1-9]{decdigit}*";
62 hexliteral = "(0x|0X){hexdigit}+";
63 unsignedsuffix = "u|U";
64 longlongsuffix = "ll|LL";
65 longsuffix = "l|L";
66 integersuffix = "{unsignedsuffix}({longlongsuffix}|{longsuffix})?";
67 integerliteral = "({octalliteral}|{decimalliteral}|{hexliteral}){integersuffix}?";
68 fraction = "{decdigit}*\.{decdigit}+|{decdigit}+\.";
69 sign = "\+|-";
70 exponent = "(e|E){sign}?{decdigit}+";
71 floatingsuffix="f|F|l|L";
72 floatingliteral = "({fraction}{exponent}?|{decdigit}+{exponent}){floatingsuffix}?";
73 escape = "\\((x|X){hexdigit}+|(d|D){decdigit}+|{octaldigit}+|u{hex4}|U{hex8}|(a|b|f|n|r|t|v|.))";
74 cchar = "[^'\\\n\r]|{escape}";
75 narrowcharliteral = "'{cchar}+'";
76 universalcharliteral = "(u|U)'{cchar}+'";
77 widecharliteral = "L'{cchar}+'";
78 charliteral = "{narrowcharliteral}|{universalcharliteral}|{widecharliteral}";
79 schar = "[^\"\\\n\r]|{escape}";
80 encodingprefix = "u8|u|U|L";
81 stringliteral = "{encodingprefix}?\"{schar}*\"";
82 }
83
84 lexer LexerFileLexer
85 {
86 "{separators}" {}
87 "{id}" { int kw = GetKeywordToken(token.match); if (kw == INVALID_TOKEN) return ID; else return kw; }
88 "{integerliteral}" { return INTLIT; }
89 "{floatingliteral}" { return FLOATINGLIT; }
90 "{charliteral}" { return CHARLIT; }
91 "{stringliteral}" { return STRINGLIT; }
92 "<[^\n>]*>" { return FILEPATH; }
93 "$" { return DOLLAR; }
94 "\|\|" { return DISJUNCTION; }
95 "&&" { return AMPAMP; }
96 "\.\*"{ return DOTSTAR; }
97 "->\*"{ return ARROWSTAR; }
98 "\|" { return BITOR; }
99 "^" { return BITXOR; }
100 "&" { return AMP; }
101 "==" { return EQ; }
102 "!=" { return NEQ; }
103 "<=" { return LEQ; }
104 ">=" { return GEQ; }
105 "<" { return LANGLE; }
106 ">" { return RANGLE; }
107 "<<"{ return SHIFTLEFT; }
108 ">>" $(0) { return SHIFTRIGHT; }
109 "\+" { return PLUS; }
110 "-" { return MINUS; }
111 "\*" { return STAR; }
112 "/" { return DIV; }
113 "%" { return REM; }
114 "\+\+" { return PLUSPLUS; }
115 "--" { return MINUSMINUS; }
116 "!" { return EXCLAMATION; }
117 "\?" { return QUEST; }
118 "~" { return CPL; }
119 "\." { return DOT; }
120 "->" { return ARROW; }
121 "\[" { return LBRACKET; }
122 "\]" { return RBRACKET; }
123 "\(" { return LPAREN; }
124 "\)" { return RPAREN; }
125 "\{" { return LBRACE; }
126 "\}" { return RBRACE; }
127 "\.\.\." { return ELLIPSIS; }
128 "::"{ return COLONCOLON; }
129 ":" { return COLON; }
130 ";" { return SEMICOLON; }
131 "#" { return HASH; }
132 "," { return COMMA; }
133 "=" { return ASSIGN; }
134 "\*=" { return MULASSIGN; }
135 "/=" { return DIVASSIGN; }
136 "%=" { return REMASSIGN; }
137 "\+=" { return PLUSASSIGN; }
138 "-=" { return MINUSASSIGN; }
139 "<<=" { return SHIFTLEFTASSIGN; }
140 ">>=" { return SHIFTRIGHTASSIGN; }
141 "&=" { return ANDASSIGN; }
142 "^=" { return XORASSIGN; }
143 "\|=" { return ORASSIGN; }
144
145 variables
146 {
147 int leftAngleCount;
148 }
149
150 actions
151 {
152 $(0)={ if (leftAngleCount > 0) return INVALID_TOKEN; }
153 }
154 }