Commit Diff


commit - e9de881a9c92ad811717b8238eb1f2a8ddc73994
commit + 6be3eec6c0a53e627e1f2ec05179caaa7918b636
blob - af71f2f0c7017c92f2ae9edf574126b56d8e5a3f
blob + ae0042c91aa5434b5f01d7cedcbbc47b760e0a4b
--- cc/cc1/cc1.c
+++ cc/cc1/cc1.c
@@ -7,7 +7,7 @@
 
 // ERROR HANDLING
 
-int line;
+int line = 1;
 
 error (msg)
 char *msg;
@@ -42,7 +42,7 @@ readch (void)
 
 peekch (void)
 {
-	if (peekdch != EOF)
+	if (peekdch == EOF)
 		peekdch = readch ();
 
 	return peekdch;
@@ -100,7 +100,10 @@ lex (void)
 	case ')':
 	case '{':
 	case '}':
-		return ch;
+	case '=':
+	case ';':
+	case ',':
+		return nextch ();
 	case EOF:
 		return TK_EOF;
 	default:
@@ -210,10 +213,15 @@ decl (global)
 			return 1;
 		case '[':
 			return error ("TODO: arrays");
+		case '=':
+			// TODO: init expr
+			next ();
+			break;
 		case ';':
-			if (!first)
-				return 1;
-			// fallthrough
+			next ();
+			return 1;
+		case ',':
+			break;
 		default:
 			return error ("expected declaration");
 		}
@@ -228,7 +236,8 @@ decl (global)
 parse (void)
 {
 	while (peek () != TK_EOF) {
-		decl (1);
+		if (!decl (1))
+			return error ("expected declaration");
 	}
 
 	return 0;