add more lexer tokens
This commit is contained in:
parent
49a061da2f
commit
9063eb10ce
@ -5,11 +5,28 @@ class Lexer(object):
|
||||
def __init__(self):
|
||||
self.reserved = {
|
||||
'C': 'C',
|
||||
|
||||
# types
|
||||
'char': 'CHAR',
|
||||
'short': 'SHORT',
|
||||
'int': 'INT',
|
||||
'long': 'LONG',
|
||||
|
||||
# control
|
||||
'if': 'IF',
|
||||
'else': 'ELSE',
|
||||
'while': 'WHILE',
|
||||
'for': 'FOR',
|
||||
'return': 'RETURN',
|
||||
}
|
||||
|
||||
self.tokens = [
|
||||
'LPAREN',
|
||||
'RPAREN',
|
||||
'LBRACKET',
|
||||
'RBRACKET',
|
||||
'LCURLY',
|
||||
'RCURLY',
|
||||
'SEMICOLON',
|
||||
'STRING',
|
||||
'ID',
|
||||
@ -21,6 +38,10 @@ class Lexer(object):
|
||||
|
||||
self.t_LPAREN = r'\('
|
||||
self.t_RPAREN = r'\)'
|
||||
self.t_LBRACKET = r'\['
|
||||
self.t_RBRACKET = r'\]'
|
||||
self.t_LCURLY = r'\{'
|
||||
self.t_RCURLY = r'\}'
|
||||
self.t_SEMICOLON = r';'
|
||||
|
||||
self.t_ignore = ' \t\r'
|
||||
|
Loading…
x
Reference in New Issue
Block a user