Skip to content

Commit 2248226

Browse files
committed
sync
1 parent d2072d5 commit 2248226

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

Diff for: lexer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
55
# File Name : lexer.py
66
# Creation Date : 21-03-2012
7-
# Last Modified : Thu 10 May 2012 07:32:48 PM EEST
7+
# Last Modified : Thu 10 May 2012 09:03:45 PM EEST
88
#_._._._._._._._._._._._._._._._._._._._._.*/
99

1010
# Build the lexer
@@ -25,7 +25,7 @@ def main():
2525
if not tok:
2626
break
2727
#uncomment to print tokens
28-
#print tok
28+
print tok
2929
else:
3030
print "No input given"
3131
exit(-1)

Diff for: prules.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
55
# File Name : parserules.py
66
# Creation Date : 02-04-2012
7-
# Last Modified : Thu 10 May 2012 08:26:24 PM EEST
7+
# Last Modified : Thu 10 May 2012 10:26:53 PM EEST
88
#_._._._._._._._._._._._._._._._._._._._._.*/
99

1010
from tokrules import *
@@ -66,6 +66,23 @@ def p_error(p):
6666
else:
6767
errors.append(p)
6868

69+
70+
71+
72+
def p_type(p):
73+
'''
74+
type : simple_type
75+
| simple_type '[' ']'
76+
'''
77+
#p[0] = gen_p_out('type',p)
78+
pass
79+
80+
81+
82+
def p_ret_type(p):
83+
84+
85+
6986
def p_program(p):
7087
'''
7188
program : letdef program

Diff for: sample/helloworld.bob

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
print("hello world\n");
2+
print("hello world\n");
3+
print("hello world\n");
4+
print("hello world\n");
5+
print("hello world\n");
6+
print("hello world\n");

Diff for: tokrules.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
55
# File Name : tokrules.py
66
# Creation Date : 29-03-2012
7-
# Last Modified : Thu 10 May 2012 08:26:12 PM EEST
7+
# Last Modified : Thu 10 May 2012 09:47:14 PM EEST
88
#_._._._._._._._._._._._._._._._._._._._._.*/
99
from sys import argv
1010
terrors = []
@@ -21,15 +21,15 @@
2121
'else' : 't_Else',
2222
'for' : 't_For',
2323
'while' : 't_While',
24+
'true' : 't_True',
25+
'false' : 't_False',
2426
'return' : 't_Ret'
2527
}
2628

2729
literals = [ '+', '-', '*', '/', '(', ')', ';', '!', '<', '>', '^', '%', '{', '}', '[', ']', ',', ':' ]
2830

29-
tokens = [ 'Func', 'BSlash',
30-
'RealPlus', 'RealMinus', 'RealMul', 'RealDiv', 'Pow', 'BINAND', 'OR',
31-
'DomEQ', 'LEQ', 'GEQ', 'EQ', 'NOTEQ', 'ASSIGN',
32-
'Constructor','Const_str','Const_int','Const_float','Const_char', 'Comment', 'ccomment',
31+
tokens = [ 'BINAND', 'OR', 'LEQ', 'GEQ', 'EQ', 'NOTEQ', 'ASSIGN',
32+
'Const_str','Const_int','Const_char', 'Comment', 'ccomment',
3333
'Identifier' ] + list(reserved.values())
3434

3535
# Tokens
@@ -43,6 +43,7 @@
4343
t_ASSIGN = r':='
4444

4545
t_Const_str = r'\"([^\\\n]|(\\.))*?\"'
46+
#t_Const_str = r'[a-zA-Z_]?\"(\\.|[^\\"])*\"'
4647
t_Const_int = r'[0-9]+'
4748
t_Const_char = r'\'(\\[nrt0\\\"\']|\\x[0-9a-fA-F]{2}|[a-zA-Z])\''
4849
t_ignore_Comment = r'//.*'
@@ -111,7 +112,7 @@ def t_ccomment_error(t):
111112
t.lexer.skip(1)
112113

113114
def t_Reserved(t):
114-
r'[a-z][a-zA-Z0-9_]*'
115+
r'[a-zA-Z][a-zA-Z0-9_]*'
115116
t.type = reserved.get(t.value,'Identifier') # Check for reserved words
116117
return t
117118

0 commit comments

Comments
 (0)