shithub: riscv

Download patch

ref: 20e695c1787144dd922002c55a3f0a2dc16cb198
parent: 7d18756b39cc33482f8cf5574b20a51331c4cea3
author: aiju <devnull@localhost>
date: Sat Mar 31 08:30:48 EDT 2018

forp: fix precedence for []

--- a/sys/src/cmd/forp/parse.c
+++ b/sys/src/cmd/forp/parse.c
@@ -291,12 +291,8 @@
 	mpint *num;
 	int t;
 	
-	if(level == MAXPREC+1){
+	if(level == MAXPREC+2){
 		switch(t = lex()){
-		case '~': return node(ASTUN, OPCOM, expr(level));
-		case '!': return node(ASTUN, OPNOT, expr(level));
-		case '+': return expr(level);
-		case '-': return node(ASTUN, OPNEG, expr(level));
 		case '(':
 			a = expr(0);
 			expect(')');
@@ -318,7 +314,7 @@
 		default:
 			error(nil, "unexpected %t", t);
 		}
-	}else if(level == MAXPREC){
+	}else if(level == MAXPREC+1){
 		a = expr(level + 1);
 		if(got('[')){
 			b = expr(0);
@@ -330,6 +326,14 @@
 			a = node(ASTIDX, a, b, c);
 		}
 		return a;
+	}else if(level == MAXPREC){
+		switch(t = lex()){
+		case '~': return node(ASTUN, OPCOM, expr(level));
+		case '!': return node(ASTUN, OPNOT, expr(level));
+		case '+': return expr(level);
+		case '-': return node(ASTUN, OPNEG, expr(level));
+		default: superman(t); return expr(level+1); break;
+		}
 	}else if(level == 3){
 		a = expr(level + 1);
 		if(got('?')){