1
2
3
4
5
6 classmap IntermediateCodeClassMap;
7
8 tokens IntermediateCodeTokens
9 {
10 (CU, "'cu'"), (ID, "identifier"), (TYPES, "'types'"), (DATA, "'data'"), (FUNCTION, "'function'"), (ONCE, "'once'"),
11 (STORE, "'store'"), (ARG, "'arg'"), (JMP, "'jmp'"), (BRANCH, "'branch'"), (CALL, "'call'"), (RET, "'ret'"), (SWITCH, "'switch'"), (NOP, "'nop'"), (SAVE, "'save'"),
12 (NOT, "'not'"), (NEG, "'neg'"), (SIGNEXTEND, "'signextend'"), (ZEROEXTEND, "'zeroextend'"), (TRUNCATE, "'truncate'"), (BITCAST, "'bitcast'"),
13 (INTTOFLOAT, "'inttofloat'"), (FLOATTOINT, "'floattoint'"), (INTTOPTR, "'inttoptr'"), (PTRTOINT, "'ptrtoint'"),
14 (ADD, "'add'"), (SUB, "'sub'"), (MUL, "'mul'"), (DIV, "'div'"), (MOD, "'mod'"), (AND, "'and'"), (OR, "'or'"), (XOR, "'xor'"), (SHL, "'shl'"), (SHR, "'shr'"),
15 (EQUAL, "'equal'"), (LESS, "'less'"), (PARAM, "'param'"), (LOCAL, "'local'"), (LOAD, "'load'"), (ELEMADDR, "'elemaddr'"), (PTROFFSET, "'ptroffset'"), (PTRDIFF, "'ptrdiff'"), (TRAP, "'trap'"),
16 (TYPE, "'type'"), (OFFSET, "'offset'"), (SIZE, "'size'"), (ALIGNMENT, "'alignment'"),
17 (VOID, "'void'"), (BOOL, "'bool'"), (SBYTE, "'sbyte'"), (BYTE, "'byte'"), (SHORT, "'short'"), (USHORT, "'ushort'"), (INT, "'int'"), (UINT, "'uint'"), (LONG, "'long'"), (ULONG, "'ulong'"),
18 (FLOAT, "'float'"), (DOUBLE, "'double'"),
19 (TRUE, "'true'"), (FALSE, "'false'"), (NULL, "'null'"), (CONV, "'conv'"), (METADATA, "'metadata'"),
20 (LPAREN, "'('"), (RPAREN, "')'"), (COMMA, "','"), (LBRACE, "'{'"), (RBRACE, "'}'"), (AST, "'*'"), (COLON, "':'"), (SEMICOLON, "';'"), (LBRACKET, "'['"), (RBRACKET, "']'"), (ASSIGN, "'='"),
21 (AT, "'@'"), (DOLLAR, "'$'"), (EXCLAMATION, "'!'"), (TYPEID, "type identifier"), (CLSID, "class identifier"), (STRING, "string"), (NUMBER, "number"), (HEXNUM, "hex number")
22 }
23
24 keywords IntermediateCodeKeywords
25 {
26 ("cu", CU), ("types", TYPES), ("data", DATA), ("function", FUNCTION), ("once", ONCE),
27 ("store", STORE), ("arg", ARG), ("jmp", JMP), ("branch", BRANCH), ("call", CALL), ("ret", RET), ("switch", SWITCH), ("nop", NOP), ("save", SAVE),
28 ("not", NOT), ("neg", NEG), ("signextend", SIGNEXTEND), ("zeroextend", ZEROEXTEND), ("truncate", TRUNCATE), ("bitcast", BITCAST),
29 ("inttofloat", INTTOFLOAT), ("floattoint", FLOATTOINT), ("inttoptr", INTTOPTR), ("ptrtoint", PTRTOINT),
30 ("add", ADD), ("sub", SUB), ("mul", MUL), ("div", DIV), ("mod", MOD), ("and", AND), ("or", OR), ("xor", XOR), ("shl", SHL), ("shr", SHR),
31 ("equal", EQUAL), ("less", LESS), ("param", PARAM), ("local", LOCAL), ("load", LOAD), ("elemaddr", ELEMADDR), ("ptroffset", PTROFFSET), ("ptrdiff", PTRDIFF), ("trap", TRAP),
32 ("type", TYPE), ("offset", OFFSET), ("size", SIZE), ("alignment", ALIGNMENT),
33 ("void", VOID), ("bool", BOOL), ("sbyte", SBYTE), ("byte", BYTE), ("short", SHORT), ("ushort", USHORT), ("int", INT), ("uint", UINT), ("long", LONG), ("ulong", ULONG),
34 ("float", FLOAT), ("double", DOUBLE),
35 ("true", TRUE), ("false", FALSE), ("null", NULL), ("conv", CONV), ("metadata", METADATA)
36 }
37
38 expressions
39 {
40 ws = "[ \t\n\r]+";
41 id = "({idstart}|_)({idcont}|@|_)*";
42 digit = "[0-9]";
43 typeidentifier = "$T{digit}+";
44 hexdigit = "[0-9a-fA-F]";
45 clsid = "clsid\({hexdigit}+\)";
46 string = "\"[^\"\r\n]*\"";
47 sign = "[+-]";
48 fraction = "{digit}*\.{digit}+|{digit}+\.";
49 number = "{sign}?({fraction}|{digit}+)([eE]{sign}?{digit}+)?";
50 hexnum = "{hexdigit}+";
51 }
52
53 lexer IntermediateCodeLexer
54 {
55 "{ws}" {}
56 "{clsid}" { return CLSID; }
57 "{id}" { int kw = GetKeywordToken(token.match); if (kw == INVALID_TOKEN) return ID; else return kw; }
58 "{typeidentifier}" { return TYPEID; }
59 "{string}" { return STRING; }
60 "{number}" { return NUMBER; }
61 "{hexnum}" { return HEXNUM; }
62 "\(" { return LPAREN; }
63 "\)" { return RPAREN; }
64 "," { return COMMA; }
65 "\{" { return LBRACE; }
66 "\}" { return RBRACE; }
67 "\*" { return AST; }
68 ":" { return COLON; }
69 ";" { return SEMICOLON; }
70 "\[" { return LBRACKET; }
71 "\]" { return RBRACKET; }
72 "=" { return ASSIGN; }
73 "@" { return AT; }
74 "$" { return DOLLAR; }
75 "!" { return EXCLAMATION; }
76 }