forked from Grooben/Not-C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokentable.py
63 lines (53 loc) · 2.92 KB
/
tokentable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#Author : Craig Clephane
#Last edited : 10/03/2019
#File which contains all the names of tokens, as well as symbols and keywords.
#Must remain the same order - do NOT change without authors permission
TokenEOF, TokenMultiply, TokenDivide, TokenMod, TokenAdd, \
TokenSubtract, TokenNegate, TokenNOT, TokenLss, TokenLeq, \
TokenGTR, TokenGEQ, TokenEQ, TokenNeg, TokenAssign, \
TokenAND, TokenOR, TokenIF, TokenELSE, TokenWHILE, \
TokenPrint, TokenPutc, TokenLparen, TokenRparen, TokenLbrace, \
TokenRbrace, TokenSemi, TokenComma, TokenIdent, TokenInteger, \
TokenString, TokenINT, TokenSTRING, TokenEOL = range(34)
#Must remain the same order - do NOT change without authors permission
all_syms = ['End_of_File', 'OMulti', 'ODivide','OMod', 'OAdd',
'OSub', 'ONeg', 'ONot', 'OLess','OLessequal',
'OGreater','OperationGreaterequal', 'OperationEqual', 'ONotequal', 'Oassign',
'OAnd', 'Oor', 'KeywordIF', 'KeywordELSE', 'KeywordWHILE',
'KeywordPRINT', 'KeywordPutc', 'LeftParen', 'RightPaaren', 'LeftBrace',
'RightBrace', 'SemiColon', 'Comma', 'Identifier', 'Integer',
'String', 'KeywordInt', 'KeywordSTRING', 'EOL']
#changed comparaters to "compare" rather then "Operator"
categories = ['EOF', 'Operator', 'Operator', 'Operator', 'Operator',
'Operator', 'Operator', 'Operator', 'Operator', 'Operator',
'Operator', 'Operator', 'Operator', 'Operator', 'Assignment',
'Operator', 'Operator', 'Function', 'Function', 'Function',
'Function', 'Punctuator', 'Punctuator', 'Punctuator', 'Punctuator',
'Punctuator','StatementTerminator','Comma','Variable','Variable', ##comma added by peter for a unique priority in parse tree.
'Variable', 'Operator', 'Operator', 'EOL']
#translation table from front end to back end. WIP.
translation = ['End_of_File', 'OMulti', 'ODivide','OMod', 'OAdd',
'OSub', 'ONeg', 'ONot', 'OLess','OLessequal',
'OGreater','OperationGreaterequal', 'OperationEqual', 'ONotequal', 'Oassign',
'OAnd', 'Oor', 'KeywordIF', 'KeywordELSE', 'KeywordWHILE',
'KeywordPRINT', 'KeywordPutc', 'LeftParen', 'RightPaaren', 'LeftBrace',
'RightBrace', 'SemiColon', 'Comma', 'Identifier', 'Integer',
'String', 'KeywordInt', 'KeywordSTRING', 'EOL']
Symbols = { '{': TokenLbrace,
'}': TokenRbrace,
'(': TokenLparen,
')': TokenRparen,
'+': TokenAdd,
'-': TokenSubtract,
'*': TokenMultiply,
'%': TokenMod,
';': TokenSemi,
',': TokenComma }
#Keywords of the complier
keyWords = { 'if': TokenIF,
'else':TokenELSE,
'print': TokenPrint,
'putc': TokenPutc,
'while': TokenWHILE,
'Int': TokenINT,
'String': TokenSTRING}