shithub: scc

Download patch

ref: 08c42cdfaea4d0cc3bf0bc00ee3e7cf2e5a9664a
parent: 5cf98c2919bf514ab5508c46fd777b8aecaf7d8b
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Apr 10 03:08:07 EDT 2014

Add add and sub

These operators have the same precedence level, so
they are implemented in the same function.

--- a/expr.c
+++ b/expr.c
@@ -265,6 +265,24 @@
 	}
 }
 
+static struct node *
+add(void)
+{
+	register char op;
+	register Node *np;
+
+	np = mul();
+	for (;;) {
+		switch (yytoken) {
+		case '+': op = OADD; break;
+		case '-': op = OSUB; break;
+		default:  return np;
+		}
+		next();
+		np = arithmetic(op, np, mul());
+	}
+}
+
 Node *
 expr(void)
 {
@@ -271,7 +289,7 @@
 	register Node *np;
 
 	do
-		np = mul();
+		np = add();
 	while (yytoken == ',');
 	return np;
 }