revert silly changes to hoc made long ago, but keep production for +1, and π=PI. Reference: /n/atom/patch/applied2013/hocrevert Date: Wed Jun 19 22:16:44 CES 2013 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/hoc/hoc.h Wed Jun 19 22:15:48 2013 +++ /sys/src/cmd/hoc/hoc.h Wed Jun 19 22:15:48 2013 @@ -52,7 +52,6 @@ extern void restore(Symbol*); extern void restoreall(void); extern void execerror(char*, char*); -extern void runeexecerror(char*, Rune*); extern void define(Symbol*, Formal*), verify(Symbol*); extern Datum pop(void); extern void initcode(void), push(Datum), xpop(void), constpush(void); @@ -79,4 +78,5 @@ extern void init(void); extern int yyparse(void); +extern void execerror(char*, char*); extern void *emalloc(unsigned); --- /sys/src/cmd/hoc/hoc.y Wed Jun 19 22:15:48 2013 +++ /sys/src/cmd/hoc/hoc.y Wed Jun 19 22:15:48 2013 @@ -1,7 +1,4 @@ %{ -#include -#include - #include "hoc.h" #define code2(c1,c2) code(c1); code(c2) #define code3(c1,c2,c3) code(c1); code(c2); code(c3) @@ -137,6 +134,8 @@ ; %% /* end of grammar */ +#include +#include #include #include char *progname; @@ -149,7 +148,7 @@ char **gargv; /* global argument list */ int gargc; -int r = L'\n'; /* global for use by warning() */ +int c = '\n'; /* global for use by warning() */ int backslash(int), follow(int, int, int); void defnonly(char*), run(void); @@ -157,66 +156,65 @@ yylex(void) /* hoc6 */ { - while ((r=Bgetrune(bin)) == L' ' || r == L'\t') + while ((c=Bgetc(bin)) == ' ' || c == '\t') ; - if (r < 0) + if (c < 0) return 0; - if (r == L'\\') { - r = Bgetrune(bin); - if (r == L'\n') { + if (c == '\\') { + c = Bgetc(bin); + if (c == '\n') { lineno++; return yylex(); } } - if (r == L'#') { /* comment */ - while ((r = Bgetrune(bin)) != L'\n' && r >= 0) + if (c == '#') { /* comment */ + while ((c=Bgetc(bin)) != '\n' && c >= 0) ; - if (r == L'\n') + if (c == '\n') lineno++; - return r; + return c; } - if (r == L'.' || isdigit(r)) { /* number */ + if (c == '.' || isdigit(c)) { /* number */ double d; - Bungetrune(bin); + Bungetc(bin); Bgetd(bin, &d); yylval.sym = install("", NUMBER, d); return NUMBER; } - if (isalpharune(r) || r == L'_') { + if (isalpha(c) || c == '_' || c >= 0x80) { Symbol *s; - Rune sbuf[100], *p = sbuf; - char cbuf[100*UTFmax]; + char sbuf[100], *p = sbuf; do { if (p >= sbuf + sizeof(sbuf) - 1) { - *p = 0; - runeexecerror("name too long", sbuf); + *p = '\0'; + execerror("name too long", sbuf); } - *p++ = r; - } while ((r = Bgetrune(bin)) >= 0 && (isalpharune(r) || r == L'_')); - Bungetrune(bin); - *p = 0; - snprint(cbuf, sizeof cbuf, "%S", sbuf); - if ((s=lookup(cbuf)) == 0) - s = install(cbuf, UNDEF, 0.0); + *p++ = c; + } while ((c=Bgetc(bin)) >= 0 && (isalnum(c) || c == '_' || c >= 0x80)); + Bungetc(bin); + *p = '\0'; + if ((s=lookup(sbuf)) == 0) + s = install(sbuf, UNDEF, 0.0); yylval.sym = s; return s->type == UNDEF ? VAR : s->type; } - if (r == L'"') { /* quoted string */ - Rune sbuf[100], *p; - for (p = sbuf; (r = Bgetrune(bin)) != L'"'; p++) { - if (r == L'\n' || r == Beof) - execerror("missing quote", 0); + if (c == '"') { /* quoted string */ + char sbuf[100], *p; + for (p = sbuf; (c=Bgetc(bin)) != '"'; p++) { + if (c == '\n' || c == Beof) + execerror("missing quote", ""); if (p >= sbuf + sizeof(sbuf) - 1) { - *p =0; - runeexecerror("string too long", sbuf); + *p = '\0'; + execerror("string too long", sbuf); } - *p = backslash(r); + *p = backslash(c); } *p = 0; - yylval.sym = (Symbol*)smprint("%S", sbuf); + yylval.sym = (Symbol *)emalloc(strlen(sbuf)+1); + strcpy((char*)yylval.sym, sbuf); return STRING; } - switch (r) { + switch (c) { case '+': return follow('+', INC, follow('=', ADDEQ, '+')); case '-': return follow('-', DEC, follow('=', SUBEQ, '-')); case '*': return follow('=', MULEQ, '*'); @@ -229,34 +227,28 @@ case '|': return follow('|', OR, '|'); case '&': return follow('&', AND, '&'); case '\n': lineno++; return '\n'; - default: return r; + default: return c; } } -int -backslash(int r) /* get next char with \'s interpreted */ +backslash(int c) /* get next char with \'s interpreted */ { static char transtab[] = "b\bf\fn\nr\rt\t"; - char *p; - - if (r != L'\\') - return r; - r = Bgetrune(bin); - if(r >= Runeerror) - return r; - if (islower(r) && (p = strchr(transtab, (char)r))) - return (int)p[1]; - return r; + if (c != '\\') + return c; + c = Bgetc(bin); + if (islower(c) && strchr(transtab, c)) + return strchr(transtab, c)[1]; + return c; } -int follow(int expect, int ifyes, int ifno) /* look ahead for >=, etc. */ { - int r = Bgetrune(bin); + int c = Bgetc(bin); - if (r == expect) + if (c == expect) return ifyes; - Bungetrune(bin); + Bungetc(bin); return ifno; } @@ -267,23 +259,11 @@ warning(s, (char *)0); longjmp(begin, 0); rob*/ - execerror(s, 0); -} - -void -runeexecerror(char* s, Rune *t) /* recover from run-time error */ -{ - char buf[256]; - - snprint(buf, sizeof buf, "%S", t); - warning(s, buf); - Bseek(bin, 0L, 2); /* flush rest of file */ - restoreall(); - longjmp(begin, 0); + execerror(s, (char *)0); } void -execerror(char* s, char *t) /* recover from run-time error */ +execerror(char* s, char* t) /* recover from run-time error */ { warning(s, t); Bseek(bin, 0L, 2); /* flush rest of file */ @@ -294,7 +274,7 @@ void fpecatch(void) /* catch floating point exceptions */ { - execerror("floating point exception", 0); + execerror("floating point exception", (char *) 0); } void @@ -390,7 +370,7 @@ } void -warning(char *s, char *t) /* print warning message */ +warning(char* s, char* t) /* print warning message */ { fprint(2, "%s: %s", progname, s); if (t) @@ -398,8 +378,8 @@ if (infile) fprint(2, " in %s", infile); fprint(2, " near line %d\n", lineno); - while (r != L'\n' && r != Beof) - if((r = Bgetrune(bin)) == L'\n') /* flush rest of input line */ + while (c != '\n' && c != Beof) + if((c = Bgetc(bin)) == '\n') /* flush rest of input line */ lineno++; }