34 lines
541 B
Python
34 lines
541 B
Python
|
|
reserved = {
|
|
'C': 'C',
|
|
}
|
|
|
|
tokens = [
|
|
'LPAREN',
|
|
'RPAREN',
|
|
'SEMICOLON',
|
|
'STRING',
|
|
'ID',
|
|
] + list(reserved.values())
|
|
|
|
t_LPAREN = r'\('
|
|
t_RPAREN = r'\)'
|
|
t_SEMICOLON = r';'
|
|
t_STRING = r'"([^"])*"'
|
|
|
|
t_ignore = ' \t\r'
|
|
|
|
def t_ID(t):
|
|
r'[a-zA-Z_][a-zA-Z_0-9]*'
|
|
t.type = reserved.get(t.value, 'ID')
|
|
return t
|
|
|
|
def t_newline(t):
|
|
r'\n+'
|
|
t.lexer.lineno += len(t.value)
|
|
return None
|
|
|
|
def t_error(t):
|
|
print 'Illegal character "%s"' % t.value[0]
|
|
t.lexer.skip(1)
|