add lexer skeleton

This commit is contained in:
Josh Holtrop 2011-08-29 10:01:23 -04:00
commit 2b4de69ff8
2 changed files with 38 additions and 0 deletions

0
parser/__init__.py Normal file
View File

38
parser/lexer.py Normal file
View File

@ -0,0 +1,38 @@
import ply.lex as lex
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)
def get_lexer():
return lex.lex()