master
bill 3 years ago
parent ab6c72e690
commit b2536564bc

@ -316,11 +316,11 @@ class_body_defs ::= class_body_defs:defs var_def:vd {: RESULT = combine(de
/* fun_def */ /* 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 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; :} 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); :} typed_vars ::= typed_var:tv {: RESULT= single(tv); :}
@ -427,11 +427,11 @@ pexpr ::= identifier:id {: RESULT = id; :}
| index_expr:i {: RESULT = i; :} | index_expr:i {: RESULT = i; :}
| member_expr:m LPAR expr_list:l RPAR:rpar {: RESULT = new MethodCallExpr(mxleft, rparxright, m, l); :} | 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); :} | 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 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 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 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 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 MOD:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :}
| MINUS:m pexpr:p {: RESULT = new UnaryExpr(mxleft, pxright, m, p); :} | 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>(); :} | {: RESULT = new ArrayList<Expr>(); :}
; ;
/* bin_op */ //We may still be able to use bin_op, so I left it here.
/* bin_op */
bin_op ::= PLUS:a {: RESULT = new StringLiteral(axleft, axright, "+"); :} bin_op ::= PLUS:a {: RESULT = new StringLiteral(axleft, axright, "+"); :}
| MINUS:a {: RESULT = new StringLiteral(axleft, axright, "-"); :} | MINUS:a {: RESULT = new StringLiteral(axleft, axright, "-"); :}
| MUL: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, "%"); :} | 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, "=="); :} comp_op ::= EQUAL:a {: RESULT = new StringLiteral(axleft, axright, "=="); :}
| NEQ:a {: RESULT = new StringLiteral(axleft, axright, "!="); :} | NEQ:a {: RESULT = new StringLiteral(axleft, axright, "!="); :}
| LEQ:a {: RESULT = new StringLiteral(axleft, axright, "<="); :} | LEQ:a {: RESULT = new StringLiteral(axleft, axright, "<="); :}

@ -46,7 +46,6 @@ import java.util.ArrayList;
/** Return a terminal symbol of syntactic category TYPE and semantic /** Return a terminal symbol of syntactic category TYPE and semantic
* value VALUE at the current source location. */ * value VALUE at the current source location. */
private Symbol symbol(int type, Object value) { private Symbol symbol(int type, Object value) {
//System.out.println(yytext() + ChocoPyTokens.terminalNames[type]);
return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[type], type, return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[type], type,
new ComplexSymbolFactory.Location(yyline + 1, yycolumn + 1), new ComplexSymbolFactory.Location(yyline + 1, yycolumn + 1),
new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()), new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()),
@ -136,7 +135,6 @@ if True:
AFTER state. AFTER state.
*/ */
pop(); pop();
//System.out.println("dedent");
return symbol(ChocoPyTokens.DEDENT, currIndent); return symbol(ChocoPyTokens.DEDENT, currIndent);
} }
/*Otherwise, we will start dealing with the rest /*Otherwise, we will start dealing with the rest
@ -149,7 +147,6 @@ if True:
current level should have, start a new level which will have current level should have, start a new level which will have
`currIndent' indents. `currIndent' indents.
*/ */
//System.out.println("indent");
push(currIndent); push(currIndent);
return symbol(ChocoPyTokens.INDENT, currIndent); return symbol(ChocoPyTokens.INDENT, currIndent);

Loading…
Cancel
Save