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