|
|
|
@ -316,11 +316,11 @@ class_body_defs ::= class_body_defs:defs var_def:vd {: RESULT = combine(de
|
|
|
|
|
|
|
|
|
|
/* fun_def */
|
|
|
|
|
fun_def ::= DEF:def identifier:id LPAR typed_vars:params RPAR ret_type:rt COLON:col NEWLINE INDENT fun_body_decs:fbd stmt_list:sl DEDENT
|
|
|
|
|
{: TypeAnnotation _rt = rt;if(rt.getLocation()[0] == -2) _rt = new ClassType( colxright, colxright, "<None>");RESULT = new FuncDef(defxleft, getRight(sl), id, params, _rt, fbd, sl); :}
|
|
|
|
|
{: TypeAnnotation _rt = rt;if((rt instanceof ClassType) && ((ClassType)rt).className == "<None>") _rt = new ClassType( colxright, colxright, "<None>");RESULT = new FuncDef(defxleft, getRight(sl), id, params, _rt, fbd, sl); :}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
ret_type ::= ARROW type:t {: RESULT= t; :}
|
|
|
|
|
| {: RESULT= new ClassType(new ComplexSymbolFactory.Location(-2,-1), new ComplexSymbolFactory.Location(-1,-1),"<None>"); :}
|
|
|
|
|
| {: RESULT= new ClassType(null, null,"<None>"); :}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
typed_vars ::= typed_var:tv {: RESULT= single(tv); :}
|
|
|
|
@ -427,11 +427,11 @@ pexpr ::= identifier:id {: RESULT = id; :}
|
|
|
|
|
| index_expr:i {: RESULT = i; :}
|
|
|
|
|
| member_expr:m LPAR expr_list:l RPAR:rpar {: RESULT = new MethodCallExpr(mxleft, rparxright, m, l); :}
|
|
|
|
|
| identifier:id LPAR expr_list:l RPAR:rpar {: RESULT = new CallExpr(idxleft, rparxright, id, l); :}
|
|
|
|
|
| pexpr:p1 PLUS:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :}
|
|
|
|
|
| pexpr:p1 MINUS:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :}
|
|
|
|
|
| pexpr:p1 MUL:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :}
|
|
|
|
|
| pexpr:p1 DIV:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :}
|
|
|
|
|
| pexpr:p1 MOD:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :}
|
|
|
|
|
| pexpr:p1 PLUS:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :}
|
|
|
|
|
| pexpr:p1 MINUS:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :}
|
|
|
|
|
| pexpr:p1 MUL:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :}
|
|
|
|
|
| pexpr:p1 DIV:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :}
|
|
|
|
|
| pexpr:p1 MOD:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :}
|
|
|
|
|
| MINUS:m pexpr:p {: RESULT = new UnaryExpr(mxleft, pxright, m, p); :}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
@ -440,17 +440,16 @@ expr_list ::= expr:e {: RESULT = single(e);
|
|
|
|
|
| {: RESULT = new ArrayList<Expr>(); :}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* bin_op */
|
|
|
|
|
/* bin_op */ //We may still be able to use bin_op, so I left it here.
|
|
|
|
|
bin_op ::= PLUS:a {: RESULT = new StringLiteral(axleft, axright, "+"); :}
|
|
|
|
|
| MINUS:a {: RESULT = new StringLiteral(axleft, axright, "-"); :}
|
|
|
|
|
| MUL:a {: RESULT = new StringLiteral(axleft, axright, "*"); :}
|
|
|
|
|
| DIV:a {: RESULT = new StringLiteral(axleft, axright, "/"); :}
|
|
|
|
|
| DIV:a {: RESULT = new StringLiteral(axleft, axright, "//"); :} //Section 2.6.3 in chocopy language reference
|
|
|
|
|
| MOD:a {: RESULT = new StringLiteral(axleft, axright, "%"); :}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* comp_op */
|
|
|
|
|
/* comp_op */ //this might also need some change in order not to break left associativity
|
|
|
|
|
comp_op ::= EQUAL:a {: RESULT = new StringLiteral(axleft, axright, "=="); :}
|
|
|
|
|
| NEQ:a {: RESULT = new StringLiteral(axleft, axright, "!="); :}
|
|
|
|
|
| LEQ:a {: RESULT = new StringLiteral(axleft, axright, "<="); :}
|
|
|
|
|