forked from michellegao715/SimpleJava-Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplejava.jj
More file actions
566 lines (512 loc) · 18.9 KB
/
simplejava.jj
File metadata and controls
566 lines (512 loc) · 18.9 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
options {
JAVA_UNICODE_ESCAPE = true;
IGNORE_CASE=false;
DEBUG_PARSER=true;
}
PARSER_BEGIN(simplejava)
public class simplejava {
}
PARSER_END(simplejava)
TOKEN_MGR_DECLS :
{
public static int numcomments = 0;
}
SKIP :
{
< "/*" > { numcomments++; SwitchTo(IN_COMMENT);}
}
<IN_COMMENT>
SKIP:
{
< "*/" > { numcomments--; if (numcomments == 0) SwitchTo(DEFAULT);}
}
<IN_COMMENT>
SKIP:
{
< ~[] >
}
SKIP : /* White space */
{
"\t"
| " "
| "\n"
| "\f"
| "\r"
}
TOKEN: /* Single line comment */
{
<SINGLELINECOMMENT: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")>
}
TOKEN: /* RESERVED WORDS AND LITERALS */
{
< FOR: "for" >
| < UNDERLINE: "_" >
| < IF: "if" >
| < WHILE: "while" >
| < DO: "do">
| < ELSE: "else" >
| < CLASS: "class" >
| < TRUE: "true" >
| < FALSE: "false" >
| < RETURN: "return" >
| < NEW: "new" >
| < READ: "read" >
| < PRINT: "print" >
| < PRINTLN: "println" >
}
TOKEN : /* Integer Literals */
{
< INTEGER_LITERAL: (["0"-"9"])+ >
}
TOKEN: /* Identifiers */
{
<IDENTIFIER: (["a"-"z","A"-"Z","_"])(["a"-"z","A"-"Z","0"-"9"])* >
}
TOKEN: /* Symbol */
{
< PLUS: "+" >
| < SEMICOLON: ";">
| < MINUS: "-" >
| < MULTIPLY: "*" >
| < DIVIDE: "/" >
| < LPAREN: "(" >
| < RPAREN: ")" >
| < LBRACE: "{" >
| < RBRACE: "}" >
| < LBRACKET: "[" >
| < RBRACKET: "]" >
| < PERIOD: "." >
| < COMMA: "," >
| < EQUALEQUAL: "==" >
| < GETS: "=" >
| < NOTEQUALTO: "!=" >
| < NOT: "!" >
| < LESSTHAN: "<" >
| < LESSTHANOREQUALTO: "<=" >
| < GREATERTHAN: ">" >
| < GREATERTHANOREQUALTO: ">=" >
| < AND: "&&" >
| < OR: "||" >
}
/*****************************************
* SimpleJava Language Grammar Starts Here
*****************************************/
ASTProgram program():
{ASTProgram result; ASTFunctionDefinitions fds;ASTFunctionDefinition fd; ASTClass astclass;ASTClasses classes;}
{
// (ClassDefinition()| FunctionDeclaration())* <EOF>
{classes = new ASTClasses();fds = new ASTFunctionDefinitions();}(astclass=ClassDefinition(){classes.addElement(astclass);}
| fd = FunctionDeclaration(){fds.addElement(fd);})* <EOF>
{result = new ASTProgram(classes, fds, 0);}
{return result;}
}
ASTClass ClassDefinition():
{ASTClass result; Token t;Token name; ASTInstanceVariableDefs variabledefs; ASTVariableDefStatement vd;}
{
// <CLASS> <IDENTIFIER> <LBRACE> (VariableDeclarationStatement())* <RBRACE>
{ variabledefs = new ASTInstanceVariableDefs(); }
t = <CLASS> name = <IDENTIFIER> <LBRACE> (vd = VariableDeclarationStatement() {variabledefs.addElement(new ASTInstanceVariableDef(vd.type(), vd.name(), vd.arraydimension(), vd.line()));})* <RBRACE>
{result = new ASTClass(name.image, variabledefs, t.beginLine);}
{return result;}
}
/*Two kinds of Function Declarations: FunctionProtoype or FunctionDefinition. */
ASTFunctionDefinition FunctionDeclaration():
{ASTFunctionDefinition result; Token t1;Token t2; ASTFormals formals; ASTStatements body; }
{
t1 = <IDENTIFIER> t2= <IDENTIFIER> formals = FormalParameterList() (<SEMICOLON> {result = new ASTPrototype(t1.image, t2.image, formals, t1.beginLine);}
| <LBRACE> body = StatementList() <RBRACE> {result = new ASTFunction(t1.image, t2.image, formals, body, t1.beginLine);} )
{return result;}
}
ASTPrototype FunctionPrototype():
{ASTPrototype result; String type; Token name; ASTFormals formals; Token t;}
{
type = FunctionType() name = <IDENTIFIER> formals = FormalParameterList() t = <SEMICOLON>
{result = new ASTPrototype(type, name.image, formals, t.beginLine);}
{return result;}
}
ASTFunction FunctionDefinition():
{ASTFunction result; String type; Token name; ASTFormals formals; ASTStatement body;}
{
type = FunctionType() name = <IDENTIFIER> formals = FormalParameterList() <LBRACE> body = StatementList() <RBRACE>
{result = new ASTFunction(type, name.image, formals, body, name.beginLine);}
{return result;}
}
ASTFunctionDefinitions FunctionDefinitions():
{ASTFunctionDefinitions result; ASTFunctionDefinition functionDefinition;}
{
{result = new ASTFunctionDefinitions();}
(functionDefinition = FunctionDefinition() { result.addElement(functionDefinition);})*
{return result;}
}
String FunctionType():
{Token t;}
{
t = <IDENTIFIER> {return t.image;}
}
String VariableType():
{Token t;}
{
t = <IDENTIFIER> {return t.image;}
}
// 5th Expression
/*void NewExpression():
{}
{
LOOKAHEAD(3)<NEW> VariableType()<LPAREN><RPAREN>
| <NEW> VariableType()<LBRACKET>Variable()<RBRACKET>(<LBRACKET><RBRACKET>)*
}*/
ASTNewClassExpression NewClassExpression():
{ASTNewClassExpression result; String type; Token t; }
{
t = <NEW> type = VariableType() <LPAREN> <RPAREN>
{result = new ASTNewClassExpression(type, t.beginLine);}
{return result;}
}
ASTNewArrayExpression NewArrayExpression():
{ASTNewArrayExpression result; Token t; String type; ASTExpression elements;int arraydimension;}
{
{arraydimension=0;} t=<NEW> type = VariableType() <LBRACKET> elements = integerConstant() <RBRACKET> (<LBRACKET><RBRACKET> {arraydimension++;} )*
{result = new ASTNewArrayExpression(type, elements, arraydimension, t.beginLine);}
{return result;}
}
ASTFormals FormalParameterList():
{ASTFormals result; ASTFormal formal;}
{
// <LPAREN> (FormalParameter() (<COMMA> FormalParameter())*)? <RPAREN>
{result =new ASTFormals();}
<LPAREN> (formal = FormalParameter() {result.addElement(formal);}(<COMMA> formal = FormalParameter() {result.addElement(formal);})*)? <RPAREN>
{return result;}
// {result = new ASTStatements();}
// (statement = Statement() {result.addElement(statement);})*
// {return result;i}
}
ASTFormal FormalParameter():
{String type; Token name;ASTFormal result;int arraydimension; }
{
{arraydimension=0;} type = VariableType() name = <IDENTIFIER> (<LBRACKET><RBRACKET> {arraydimension++;})*
{result = new ASTFormal(type, name.image, arraydimension, name.beginLine);}
{return result;}
}
/* All Expressions are OrOperatorExpression, and put NewArrayExpression and NewClassExpression in the bottom of OrOperatorExpression.*/
/* ASTExpression Expression():
{ASTExpression result;}
{
LOOKAHEAD(3) FunctionCall()|LOOKAHEAD(3) OrOperatorExpression() |LOOKAHEAD(2) Variable()| ConstantExpression()| NewExpression()
LOOKAHEAD(3) result = FunctionCall()|LOOKAHEAD(3) result = OrOperatorExpression() |LOOKAHEAD(3) var = Variable() {result = new ASTVariableExpression(var, var.line());} | result = booleanConstant()|result = integerConstant()|LOOKAHEAD(3)result = NewClassExpression() | LOOKAHEAD(3)result = NewArrayExpression()/
{result = NewClassExpression();}
| {result = NewArrayExpression();}
| {result = OrOperatorExpression();}
{return result;}
}*/
// Two kinds of constant expression: boolean or integer.
ASTBooleanLiteral booleanConstant():
{ASTBooleanLiteral result; Token t;}
{
(t = <TRUE>| t = <FALSE>)
{result = new ASTBooleanLiteral(Boolean.valueOf(t.image), t.beginLine);}
// if(t.kind == TRUE)
// if(t.image == "true")
// result = new ASTBooleanLiteral(true, t.beginLine);
//else
// result = new ASTBooleanLiteral(false, t.beginLine);
{return result;}
}
ASTIntegerLiteral integerConstant():
{ ASTIntegerLiteral result; Token t;}
{
t = <INTEGER_LITERAL>
{result = new ASTIntegerLiteral(Integer.parseInt(t.image), t.beginLine);}
{return result;}
}
// First Expression.
/*void ConstantExpression():
{}
{
<INTEGER_LITERAL>|<TRUE>|<FALSE>
}
*/
// Three kinds of variables: BaseVariable, ClassVariable, ArrayVariable.
//B = id; C=V.id; A=V[exp]; V =A|B|C; So:
// V = id([exp] | (.id))*, V is ArrayVariable if ended with [exp], V is ClassVariable if ended with (.id);So I added base() to be id([exp]|(.id))*.
ASTVariable Variable():
{ASTVariable tmp; ASTExpression exp;Token t;}
{
tmp = baseVariable() (<LBRACKET> exp = OrOperatorExpression() <RBRACKET> {tmp = new ASTArrayVariable(tmp, exp, tmp.line());} | <PERIOD> t = <IDENTIFIER> {tmp = new ASTClassVariable(tmp, t.image, tmp.line());})*
{return tmp;}
//result = baseVariable() | result = arrayVariable()| result = classVariable()
//{return result;}
// LOOKAHEAD(2) ArrayVariable()| PrimitiveVariableTypeOrClassVariable()
}
ASTBaseVariable baseVariable():
{ASTBaseVariable result ; Token t;}
{
t = <IDENTIFIER>
{result = new ASTBaseVariable(t.image, t.beginLine);}
{return result;}
}
/*
ASTVariable base():
{ASTVariable result; ASTExpression exp; Token t;}
{
t=<IDENTIFIER>(exp = Expression()| (<PERIOD><IDENTIFIER>))*
{result = new ASTVariable();}
{return result;}
}
ASTArrayVariable arrayVariable():
{ASTArrayVariable result; ASTVariable base; ASTExpression index;}
{
base = Variable() <LBRACKET> index = Expression() <RBRACKET>
{result = new ASTArrayVariable(base,index,base.line());}
{return result;}
// <IDENTIFIER><LBRACKET>(Variable())?<RBRACKET>
}
ASTClassVariable classVariable():
{ASTClassVariable result; ASTVariable base; Token t; }
{
base = Variable()(<PERIOD> t=<IDENTIFIER>)*
{result = new ASTClassVariable(base,t.image,t.beginLine);}
{return result;}
// LOOKAHEAD(2)<IDENTIFIER>(<PERIOD><IDENTIFIER>)*
//| <IDENTIFIER>(<PERIOD>ArrayVariable())*
}
*/
// Three built-in function: readfunction,printfunction and printlnfunction.
ASTFunctionCallExpression ReadFunctionCall():
{ASTFunctionCallExpression result; Token t;}
{
//<READ><LPAREN><RPAREN>
t = <READ><LPAREN><RPAREN>
{result = new ASTFunctionCallExpression(t.image, t.beginLine);}
{return result;}
}
//TODO make sure print(int value)
ASTFunctionCallExpression PrintFunctionCall():
{Token t; ASTExpression param; ASTVariable var; ASTFunctionCallExpression result;}
{
// <PRINT><LPAREN> FormalParameterList() <RPAREN>
t=<PRINT><LPAREN> (param = integerConstant() | var = Variable() {param = new ASTVariableExpression(var, var.line());}) <RPAREN>
{result = new ASTFunctionCallExpression(t.image, param, t.beginLine);}
{return result;}
}
ASTFunctionCallExpression PrintlnFunctionCall():
{ASTFunctionCallExpression result; Token t;}
{
t = <PRINTLN><LPAREN><RPAREN>
{result = new ASTFunctionCallExpression(t.image, t.beginLine);}
{return result;}
}
ASTFunctionCallExpression CustomizedFunctionCall():
{ASTFunctionCallExpression result; Token t; ASTExpression formal;}
{
t = <IDENTIFIER><LPAREN>(formal = OrOperatorExpression())* <RPAREN>
{result = new ASTFunctionCallExpression(t.image, t.beginLine);}
{return result;}
}
//Three built-in function and a customized function.
ASTFunctionCallExpression FunctionCall():
{ASTFunctionCallExpression result; }
{
/* ReadFunctionCall()
| PrintFunctionCall()
| PrintlnFunctionCall()
| CustomizedFunctionCall() */
result= ReadFunctionCall()
| result = PrintFunctionCall()
| result = PrintlnFunctionCall()
| result = CustomizedFunctionCall()
{return result;}
}
//The OperatorExpression
ASTExpression OrOperatorExpression():
{ASTExpression result; ASTExpression andExp; Token t;}
{
result = AndExpression() (t=<OR> andExp = AndExpression() {result = new ASTOperatorExpression(andExp, andExp, 6, t.beginLine);})*
/*andExp = AndExpression() t = <OR> andExp = AndExpression()
{result = new ASTOperatorExpression(andExp,andExp,6,t.beginLine);} */
{return result;}
}
ASTExpression AndExpression():
{ASTExpression result; Token t; ASTExpression lhs; ASTExpression rhs;}
{
result = NotExpression() (t = <AND> rhs = NotExpression() { result = new ASTOperatorExpression(result, rhs, 5, t.beginLine);})*
{return result;}
}
ASTExpression NotExpression():
{ASTExpression result; ASTExpression operand; Token t;}
{
result = CompareExpression() (t = <NOT> operand = CompareExpression() {result = new ASTUnaryOperatorExpression(operand, t.image, t.beginLine);})*
{return result;}
}
ASTExpression CompareExpression():
{ASTExpression result; ASTExpression rhs; Token t;}
{
result = MathExpression() ((t= <EQUALEQUAL>|t = <NOTEQUALTO>|t = <LESSTHAN>|t = <LESSTHANOREQUALTO>|t = <GREATERTHAN>|t = <GREATERTHANOREQUALTO>) rhs = MathExpression() {result = new ASTOperatorExpression(result,rhs,t.image,t.beginLine);})*
{return result;}
}
ASTExpression MathExpression():
{ASTExpression result; Token t; ASTExpression rhs;}
{
result = term() ((t = <PLUS> | t = <MINUS> ) rhs = term()
{ result = new ASTOperatorExpression(result, rhs, t.image, t.beginLine); })*
{return result;}
}
ASTExpression term():
{Token t;ASTExpression result; ASTExpression rhs;}
{
// factor() ( (<MULTIPLY> | <DIVIDE>) factor() )*
result = factor() ((t = <MULTIPLY> | t = <DIVIDE> ) rhs = factor()
{ result = new ASTOperatorExpression(result, rhs, t.image, t.beginLine); })*
{return result;}
}
ASTExpression factor():
{ASTExpression result; Token t; ASTVariable variableExp;}
{
t = <INTEGER_LITERAL> {return new ASTIntegerLiteral(Integer.parseInt(t.image), t.beginLine); }
| t= <MINUS> result = factor() {return new ASTOperatorExpression(new ASTIntegerLiteral(0, t.beginLine), result, ASTOperatorExpression.MINUS,t.beginLine); }
| LOOKAHEAD(2) variableExp = Variable() {return new ASTVariableExpression(variableExp,variableExp.line());}
| <LPAREN> result = OrOperatorExpression() <RPAREN> {return result;}
| result = FunctionCall() { return result;}
| LOOKAHEAD(3)result = NewClassExpression() {return result;}
| LOOKAHEAD(3)result = NewArrayExpression() {return result;}
}
// zero or more statements.
ASTStatements StatementList():
{ASTStatements result; ASTStatement statement;}
{
//(Statement())*
{result = new ASTStatements();}
(statement = Statement() {result.addElement(statement);})*
{return result;}
}
// 11 kinds of statement
// Assignment, Increment, Block are ASTStatement;
ASTStatement Statement():
{ ASTStatement result; }
{
LOOKAHEAD(3) result = AssignmentStatement()
{return result;}
| LOOKAHEAD(3) result = IncrementStatement()
{return result;}
| LOOKAHEAD(2) result = VariableDeclarationStatement()
{return result;}
| LOOKAHEAD(3) result = IfStatement()
{return result;}
| result = WhileStatement()
{return result;}
| result = DoWhileStatement()
{return result;}
| result= ForStatement()
{return result;}
| result = FunctionCallStatement()
{return result;}
| result = ReturnStatement()
{return result;}
| result= EmptyStatement()
{return result;}
| result= BlockStatement()
{return result;}
}
ASTAssignmentStatement AssignmentStatement():
{ASTAssignmentStatement result; ASTVariable variable; ASTExpression value;Token t;}
{
variable = Variable() t = <GETS> value = OrOperatorExpression()<SEMICOLON>
{result = new ASTAssignmentStatement(variable,value,t.beginLine);}
{return result;}
}
// Incrementstatement just like <variable>++ or <variable>-- : x++ converted to x=x+1
ASTAssignmentStatement IncrementStatement():
{ASTAssignmentStatement result; ASTVariable variable; Token t; ASTExpression value;
ASTOperatorExpression operatorExp;}
{
LOOKAHEAD(3) variable = Variable() t=<PLUS><PLUS>
| LOOKAHEAD(3) variable = Variable() t = <MINUS><MINUS>
{result = new ASTAssignmentStatement(variable, new ASTOperatorExpression(new ASTVariableExpression(variable, variable.line()), new ASTIntegerLiteral(1, variable.line()),t.image,t.beginLine), t.beginLine);}
{return result;}
}
// result = new ASTAssignmentStatement(variable, new ASTOperatorExpression(value,Integer.parseInt(),1,value.line()));
// x = x+1 , this is an assignment statement, x is a variable, x+1 is an operatorExpression,
// 1 is a ASTIntegerLiteral
ASTVariableDefStatement VariableDeclarationStatement():
{ASTVariableDefStatement result; Token type; Token name; ASTExpression init; ASTVariable variable; int arrdim;}
{
LOOKAHEAD(3) {init = null;} (type = <IDENTIFIER>) name = <IDENTIFIER> (<GETS> init=OrOperatorExpression())? <SEMICOLON> {result = new ASTVariableDefStatement(type.image, name.image, init, type.beginLine);} {return result;}
| {init = null; arrdim = 0;} (type = <IDENTIFIER>) name = <IDENTIFIER> (<LPAREN> <RPAREN> {arrdim++;})+ (<GETS> init=OrOperatorExpression())? <SEMICOLON>
{result = new ASTVariableDefStatement(type.image, name.image, init, type.beginLine);}
{ return result;}
}
ASTIfStatement IfStatement():
{Token t; ASTIfStatement result; ASTExpression expression; ASTStatement thenstatement;ASTStatement elseStatement;}
{
t = <IF> <LPAREN> expression = OrOperatorExpression() <RPAREN> thenstatement = Statement() (<ELSE> elseStatement = Statement())
//t = <if> <lparen> expression =OrOperatorExpression() <rparen> thenstatement = statement() (lookahead(1) <else> elseStatement = statement())
{result = new ASTIfStatement( expression, thenstatement, elseStatement, t.beginLine);}
{return result;}
}
// <WHILE> <LPAREN> Expression() <RPAREN> Statement()
ASTWhileStatement WhileStatement():
{Token t; ASTWhileStatement result; ASTExpression test; ASTStatement body;}
{
t = <WHILE> <LPAREN> test = OrOperatorExpression() <RPAREN> body = Statement()
{result =new ASTWhileStatement(test, body, t.beginLine);}
{return result;}
}
ASTDoWhileStatement DoWhileStatement():
// do {body} while {test} = body; while(test) {body}
{Token t; ASTDoWhileStatement result; ASTStatement body; ASTExpression test;}
{
t = <DO> body = Statement() <WHILE> <LPAREN> test = OrOperatorExpression() <RPAREN> <SEMICOLON>
{result = new ASTDoWhileStatement (test,body, t.beginLine);}
{return result;}
// <DO> Statement() <WHILE> <LPAREN> Expression() <RPAREN> <SEMICOLON>
}
ASTForStatement ForStatement():
{Token t; ASTForStatement result; ASTStatement initialize; ASTExpression test; ASTStatement increment; ASTStatement body;}
{
//<FOR> <LPAREN> ForInit() Expression()<SEMICOLON> IncrementStatement() < RPAREN> Statement()
t = <FOR> <LPAREN> initialize = ForInit() test = OrOperatorExpression()<SEMICOLON> increment = IncrementStatement() <RPAREN> body = Statement()
{result = new ASTForStatement(initialize, test, increment, body, t.beginLine);}
{return result;}
}
//ForInit: variable declarations, increment statements(which is assignment statement), assignment statements, or empty statements.
ASTStatement ForInit():
{ ASTStatement result; }
{
LOOKAHEAD(2)result = VariableDeclarationStatement()
| LOOKAHEAD(3)result = IncrementStatement()
| result = AssignmentStatement()
| result = EmptyStatement()
{return result;}
}
ASTEmptyStatement EmptyStatement():
{ASTEmptyStatement result; Token t;}
{
t = <SEMICOLON>
{result = new ASTEmptyStatement(t.beginLine);}
{return result;}
}
//ASTFormal: {arraydimension=0;} type = VariableType() name = <IDENTIFIER> (<LBRACKET><RBRACKET> {arraydimension++;})*
/*{result =new ASTFormals();}
<LPAREN> (formal = FormalParameter() {result.addElement(formal);}(<COMMA> formal = FormalParameter() {result.addElement(formal);})*)? <RPAREN>
{return result;}
*/
ASTFunctionCallStatement FunctionCallStatement():
{ASTFunctionCallStatement result; Token t; ASTExpression formal;}
{
//<IDENTIFIER> <LPAREN>(Expression()(<COMMA>Expression())*)? <RPAREN> <SEMICOLON>
t=<IDENTIFIER> {result = new ASTFunctionCallStatement(t.image, t.beginLine);} <LPAREN> (formal = OrOperatorExpression() {result.addElement(formal);})? <RPAREN> <SEMICOLON>
{return result;}
}
ASTReturnStatement ReturnStatement():
{ASTReturnStatement result; ASTExpression value;Token t1; Token t2;}
{
// <RETURN> Expression() <SEMICOLON>
t1 = <RETURN> value = OrOperatorExpression() t2 = <SEMICOLON>
{result = new ASTReturnStatement(value, t1.beginLine);}
{return result;}
}
ASTStatements BlockStatement():
{ASTStatements result;}
{
<LBRACE> result = StatementList()<RBRACE>
{return result;}
}