From 1c02aa84d85b4382e8d97332bf83fb98e1b65d0f Mon Sep 17 00:00:00 2001 From: Sanjar Ahmadov Date: Fri, 19 Feb 2021 19:03:02 -0500 Subject: [PATCH] Added cexpr --- src/main/cup/chocopy/pa1/ChocoPy.cup | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/cup/chocopy/pa1/ChocoPy.cup b/src/main/cup/chocopy/pa1/ChocoPy.cup index 40f819a..e4004ff 100644 --- a/src/main/cup/chocopy/pa1/ChocoPy.cup +++ b/src/main/cup/chocopy/pa1/ChocoPy.cup @@ -403,7 +403,7 @@ literal ::= NONE:n {: RESULT = new NoneLi /* expr */ -expr ::= pexpr:ce {: RESULT = ce; :} +expr ::= cexpr:ce {: RESULT = ce; :} | NOT:n expr:exp {: RESULT = new UnaryExpr(nxleft, expxright, n, exp); :} | expr:e1 AND:a expr:e2 {: RESULT = new BinaryExpr(e1xleft, e2xright, e1, a, e2); :} | expr:e1 OR:o expr:e2 {: RESULT = new BinaryExpr(e1xleft, e2xright, e1, o, e2); :} @@ -412,29 +412,23 @@ expr ::= pexpr:ce {: RESULT = ce; :} /* cexpr */ -/* -cexpr ::= pexpr:pe {: RESULT = new Expr(pexleft, pexright); :} - | cmp_pexpr:cp {: RESULT = new Expr(cpxleft, cpxright); :} +cexpr ::= pexpr:pe {: RESULT = pe; :} + | pexpr:p1 comp_op:co cexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, co.value, p2); :} ; -cmp_pexpr ::= pexpr:p comp_op:co cmp_pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, co, p2); :} - | pexpr:p {: RESULT = new Expr(pxleft, pxright); :} - ; -*/ /* pexpr */ pexpr ::= identifier:id {: RESULT = id; :} | literal:l {: RESULT = l; :} | LBR:lbr expr_list:l RBR:rbr {: RESULT = new ListExpr(lbrxleft, rbrxright, l); :} - | LPAR:lpar expr:e RPAR:rpar {: RESULT = e; :} + | LPAR:lpar expr:e RPAR:rpar {: RESULT = e; :} | member_expr:m {: RESULT = m; :} | 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 bin_op:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo.value, p2); :} | MINUS:m pexpr:p {: RESULT = new UnaryExpr(mxleft, pxright, m, p); :} - | pexpr:p1 comp_op:co pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, co.value, p2); :} ; expr_list ::= expr:e {: RESULT = single(e); :}