diff options
author | spew <devnull@localhost> | 2017-02-03 18:55:02 -0600 |
---|---|---|
committer | spew <devnull@localhost> | 2017-02-03 18:55:02 -0600 |
commit | 3b24eb4c1f4f7bccd6335002e0e37b98a54bf7fd (patch) | |
tree | baabafee00e4ad17f53e73d8de6ee150e4892edc /sys/src/games | |
parent | 7f124310099b0ab12463b28f9d39104a8f17bc82 (diff) |
games/mix: implement Knuth's specification for comments
Diffstat (limited to 'sys/src/games')
-rw-r--r-- | sys/src/games/mix/examples/primes.m | 3 | ||||
-rw-r--r-- | sys/src/games/mix/mix.c | 46 |
2 files changed, 36 insertions, 13 deletions
diff --git a/sys/src/games/mix/examples/primes.m b/sys/src/games/mix/examples/primes.m index 31b7b86f0..dce91d04d 100644 --- a/sys/src/games/mix/examples/primes.m +++ b/sys/src/games/mix/examples/primes.m @@ -1,3 +1,5 @@ +* EXAMPLE PROGRAM ... TABLE OF PRIMES +* L EQU 500 PRINTER EQU 18 PRIME EQU -1 @@ -34,6 +36,7 @@ START IOC 0(PRINTER) LD4 24,4 J5N 2B HLT +* INITIAL CONTENTS OF TABLES AND BUFFERS ORIG PRIME+1 CON 2 ORIG BUF0-5 diff --git a/sys/src/games/mix/mix.c b/sys/src/games/mix/mix.c index f1b4d251c..dc9809465 100644 --- a/sys/src/games/mix/mix.c +++ b/sys/src/games/mix/mix.c @@ -298,10 +298,33 @@ Ifmt(Fmt *f) return fmtprint(f, "%d\t%d,%d(%d | %d:%d)", opc, apart, ipart, fpart, a, b); } +Rune +getr(void) +{ + static int bol = 1; + Rune r; + + r = Bgetrune(&bin); + switch(r) { + case '*': + if(!bol) + break; + case '#': + skipto('\n'); + case '\n': + line++; + bol = 1; + return '\n'; + } + bol = 0; + return r; +} + long yylex(void) { static Rune buf[11]; + static int bol; Rune r, *bp, *ep; static char cbuf[100]; int isnum; @@ -310,7 +333,7 @@ yylex(void) return -1; Loop: - r = Bgetrune(&bin); + r = getr(); switch(r) { case Beof: return -1; @@ -318,35 +341,32 @@ Loop: case ' ': goto Loop; case '\n': - line++; + case '*': case '+': case '-': - case '*': case ':': case ',': case '(': case ')': case '=': + bol = 0; return r; case '/': - r = Bgetrune(&bin); - if(r == '/') + r = getr(); + if(r == '/') { + bol = 0; return LSS; - else + } else Bungetrune(&bin); return '/'; case '"': for(bp = buf; bp < buf+5; bp++) { - *bp = Bgetrune(&bin); + *bp = getr(); } - if(Bgetrune(&bin) != '"') + if(getr() != '"') yyerror("Bad string literal\n"); yylval.rbuf = buf; return LSTR; - case '#': - skipto('\n'); - line++; - return '\n'; } bp = buf; ep = buf+nelem(buf)-1; @@ -359,7 +379,7 @@ Loop: *bp++ = r; if(isnum && (r >= Runeself || !isdigit(r))) isnum = 0; - r = Bgetrune(&bin); + r = getr(); switch(r) { case Beof: case '\t': |