scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 0e8267d8687f3ac331ef9d69911f796f0bd722c7
parent f749001508b3a9a2c1abc07748051dbec97be6ad
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 25 Jan 2018 16:45:27 +0000

[as-z80] Change [] to ()

Zilog and AT&T use (), only Intel uses []. So the decision is clear.

Diffstat:
Mas/expr.c | 60++++++++++++++++++++++++++++++------------------------------
1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/as/expr.c b/as/expr.c @@ -318,10 +318,7 @@ next(void) case '\'': c = character(); break; - case '$': - case '.': case '_': - case '%': c = iden(); break; default: @@ -350,27 +347,29 @@ expect(int token) next(); } +static Node *expr(void); + Node * -content(Node *np) +zilog(void) { int op; + Node *np = expr(); switch (np->addr) { case AREG: op = AINDIR; - goto new_node; + break; case AREG_OFF: op = AINDEX; - goto new_node; + break; case ANUMBER: op = ADIRECT; - new_node: - np = node(op, np, NULL); - np->addr = op; break; default: abort(); } + np = node(op, np, NULL); + np->addr = op; return np; } @@ -378,8 +377,6 @@ content(Node *np) /* grammar functions */ /*************************************************************************/ -static Node *expr(void); - static Node * primary(void) { @@ -406,12 +403,6 @@ primary(void) np = expr(); expect(')'); break; - case '[': - next(); - np = expr(); - expect(']'); - np = content(np); - break; default: unexpected(); } @@ -426,6 +417,10 @@ unary(void) Node *np; switch (tok = yytoken) { + case '%': + case '$': + case '.': + /* TODO: implement identifiers with %, $ and . */ case '!': case '-': case '+': @@ -539,29 +534,34 @@ operand(char **strp) { int imm = 0; Node *np; - char *s = *strp; - - while (isspace(*s)) - ++s; - textp = s; - switch (*s) { - case '\0': + textp = *strp; + switch (next()) { + case EOS: np = NULL; break; + case '(': + next(); + np = zilog(); + expect(')'); + break; + case REG: + np = node(yytoken, NULL, NULL); + np->sym = yylval.sym; + np->addr = AREG; + next(); + break; case '$': + next(); imm = 1; - textp++; default: - next(); np = expr(); if (imm) np->addr = AIMM; - if (yytoken != ',' && yytoken != EOS) - error("trailing characters in expression '%s'", textp); - s = endp; } + if (yytoken != ',' && yytoken != EOS) + error("trailing characters in expression '%s'", textp); + *strp = endp; - *strp = s; return np; }