Skip to content

Commit dc03943

Browse files
committed
Added array translation skeleton.
1 parent 2ab46cb commit dc03943

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

pls.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
tokens = (
77
'NAME','NUMBER', 'STRING', 'COMMA', 'SC',
88
'PLUS','MINUS','TIMES','DIVIDE','EQUALS',
9-
'LPAREN','RPAREN', 'LBRACKET', 'RBRACKET',
9+
'LPAREN','RPAREN', 'LBRACKET', 'RBRACKET',
10+
'LSBRACKET', 'RSBRACKET',
1011
'PRINT', 'READ', 'RETURN',
1112
'ITER', 'IF', 'ELSE', 'FOR',
1213
'LT', 'GT', 'LEQ', 'GEQ', 'DE', 'NE',
@@ -26,6 +27,8 @@
2627
t_RPAREN = r'\)'
2728
t_LBRACKET = r'\{'
2829
t_RBRACKET = r'\}'
30+
t_LSBRACKET = r'\['
31+
t_RSBRACKET = r'\]'
2932
t_SC = r';'
3033
t_LT = r'<'
3134
t_GT = r'>'
@@ -142,9 +145,12 @@ def p_statement_value(t):
142145
def p_value(t):
143146
'''value : STRING
144147
| NUMBER
145-
| NAME'''
148+
| NAME
149+
| NAME dim'''
146150
t[0] = t[1]
147151

152+
#arr[3] = 2
153+
148154
############################### COMPARISONS
149155

150156
def p_value_lt(t):
@@ -349,6 +355,48 @@ def p_statement_for4(t):
349355
def p_error(t):
350356
print("Syntax error at '%s'" % t.value)
351357

358+
359+
######################### ARRAYS
360+
#int[ ][ ] aryNumbers = new int[2][3]
361+
def p_array(t):
362+
'''statement : type dim NAME'''
363+
dimension = '[]' * t[2].count('[')
364+
t[0] = "%s %s %s = new %s %s"%(t[1],dimension,t[3],t[1],t[2])
365+
366+
def p_multidim(t):
367+
'''dim : dim dim'''
368+
t[0] = "%s %s"%(t[1],t[2])
369+
370+
def p_dim(t):
371+
'''dim : LSBRACKET NUMBER RSBRACKET'''
372+
t[0] = "[%s]"%t[2]
373+
374+
375+
#num[3] = 2
376+
377+
#multidimention?
378+
#statement?
379+
380+
######################### TABLES
381+
382+
######################### GRAPHS
383+
384+
385+
386+
387+
388+
389+
390+
391+
392+
393+
394+
395+
396+
397+
398+
399+
352400
import ply.yacc as yacc
353401
yacc.yacc()
354402

0 commit comments

Comments
 (0)