|
6 | 6 | tokens = (
|
7 | 7 | 'NAME','NUMBER', 'STRING', 'COMMA', 'SC',
|
8 | 8 | 'PLUS','MINUS','TIMES','DIVIDE','EQUALS',
|
9 |
| - 'LPAREN','RPAREN', 'LBRACKET', 'RBRACKET', |
| 9 | + 'LPAREN','RPAREN', 'LBRACKET', 'RBRACKET', |
| 10 | + 'LSBRACKET', 'RSBRACKET', |
10 | 11 | 'PRINT', 'READ', 'RETURN',
|
11 | 12 | 'ITER', 'IF', 'ELSE', 'FOR',
|
12 | 13 | 'LT', 'GT', 'LEQ', 'GEQ', 'DE', 'NE',
|
|
26 | 27 | t_RPAREN = r'\)'
|
27 | 28 | t_LBRACKET = r'\{'
|
28 | 29 | t_RBRACKET = r'\}'
|
| 30 | +t_LSBRACKET = r'\[' |
| 31 | +t_RSBRACKET = r'\]' |
29 | 32 | t_SC = r';'
|
30 | 33 | t_LT = r'<'
|
31 | 34 | t_GT = r'>'
|
@@ -142,9 +145,12 @@ def p_statement_value(t):
|
142 | 145 | def p_value(t):
|
143 | 146 | '''value : STRING
|
144 | 147 | | NUMBER
|
145 |
| - | NAME''' |
| 148 | + | NAME |
| 149 | + | NAME dim''' |
146 | 150 | t[0] = t[1]
|
147 | 151 |
|
| 152 | +#arr[3] = 2 |
| 153 | + |
148 | 154 | ############################### COMPARISONS
|
149 | 155 |
|
150 | 156 | def p_value_lt(t):
|
@@ -349,6 +355,48 @@ def p_statement_for4(t):
|
349 | 355 | def p_error(t):
|
350 | 356 | print("Syntax error at '%s'" % t.value)
|
351 | 357 |
|
| 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 | + |
352 | 400 | import ply.yacc as yacc
|
353 | 401 | yacc.yacc()
|
354 | 402 |
|
|
0 commit comments