ref: ec930b3a10f49ba89a48694fac9e0ca121408f78
parent: fca65d578482bb75a341943d97153e8b5f87a457
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Apr 10 02:56:25 EDT 2014
Add multiplication, division and modulo These three operations have the same precedence level, so they go in the same function.
--- a/cc.h
+++ b/cc.h
@@ -219,7 +219,7 @@
enum {
OCAST, OPTR, OADD, OARY, OSIZE, OMUL, OSUB,
- OINC, ODEC, OPINC, OPDEC
+ OINC, ODEC, OPINC, OPDEC, ODIV, OMOD
};
extern void
--- a/code.c
+++ b/code.c
@@ -13,7 +13,9 @@
[OPINC] = ";+",
[OPDEC] = ";=",
[OSIZE] = "#",
- [OPTR] = "@"
+ [OPTR] = "@",
+ [OMOD] = "*",
+ [ODIV] = "/'"
};
Node *
--- a/expr.c
+++ b/expr.c
@@ -246,13 +246,32 @@
return unary();
}
+static struct node *
+mul(void)
+{
+ register Node *np;
+ register char op;
+
+ np = cast();
+ for (;;) {
+ switch (yytoken) {
+ case '*': op = OMUL; break;
+ case '/': op = ODIV; break;
+ case '%': op = OMOD; break;
+ default: return np;
+ }
+ next();
+ np = arithmetic(op, np, cast());
+ }
+}
+
Node *
expr(void)
{
- Node *np;
+ register Node *np;
do
- np = cast();
+ np = mul();
while (yytoken == ',');
return np;
}
--
⑨