shithub: scc

Download patch

ref: 81e3671bc0195954d80cb3a212009b94f33cf49f
parent: 6ac8cd278169f186325f03e7c0947da6318b8e19
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Jan 25 11:45:27 EST 2018

[as-z80] Change [] to ()

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

--- a/as/expr.c
+++ b/as/expr.c
@@ -318,10 +318,7 @@
 	case '\'':
 		c = character();
 		break;
-	case '$':
-	case '.':
 	case '_':
-	case '%':
 		c = iden();
 		break;
 	default:
@@ -350,27 +347,29 @@
 	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 @@
 /* grammar functions                                                     */
 /*************************************************************************/
 
-static Node *expr(void);
-
 static Node *
 primary(void)
 {
@@ -406,12 +403,6 @@
 		np = expr();
 		expect(')');
 		break;
-	case '[':
-		next();
-		np = expr();
-		expect(']');
-		np = content(np);
-		break;
 	default:
 		unexpected();
 	}
@@ -426,6 +417,10 @@
 	Node *np;
 
 	switch (tok = yytoken) {
+	case '%':
+	case '$':
+	case '.':
+		/* TODO: implement identifiers with %, $ and . */
 	case '!':
 	case '-':
 	case '+':
@@ -539,29 +534,34 @@
 {
 	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;
 }