-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlexer.py
More file actions
60 lines (55 loc) · 1.25 KB
/
lexer.py
File metadata and controls
60 lines (55 loc) · 1.25 KB
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
#!/usr/bin/env python
# -*- coding: utf-8
#
#* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
# File Name : lexer.py
# Creation Date : 21-03-2012
# Last Modified : Thu 10 May 2012 09:03:45 PM EEST
#_._._._._._._._._._._._._._._._._._._._._.*/
# Build the lexer
from tokrules import *
import ply.lex as lex
from sys import argv
import readline
lexer = lex.lex()
def main():
global lexer
if len(argv) > 1:
f = open(argv[1], "r")
for line in f:
lexer.input(line)
while 1:
tok = lexer.token()
if not tok:
break
#uncomment to print tokens
print tok
else:
print "No input given"
exit(-1)
if __name__ == "__main__":
main()
### Stuff for Parser later on ###
## Precedence rules for the arithmetic operators
#precedence = (
# ('left','Plus','Minus','RealPlus','RealMinus'),
# ('left','Mul','Div','RealMul','RealDiv'),
# ('left','Pow')
# )
#
## dictionary of names (for storing variables)
#names = { }
#
#
#def p_error(p):
# print("Syntax error at '%s'" % p.value)
#
#import ply.yacc as yacc
#yacc.yacc()
#
#while 1:
# try:
# s = raw_input('test test:')
# except EOFError:
# break
# yacc.parse(s)