Commit 58f5f4f1 authored by Russ Cox's avatar Russ Cox

use separate lex buf for better errors:

package main
func main() { func(){}() + + }

x.go:2: syntax error near _f001

becomes

x.go:2: syntax error near func

R=ken
OCL=27047
CL=27047
parent 8d8225d5
...@@ -533,6 +533,7 @@ EXTERN char* package; ...@@ -533,6 +533,7 @@ EXTERN char* package;
EXTERN Biobuf* bout; EXTERN Biobuf* bout;
EXTERN int nerrors; EXTERN int nerrors;
EXTERN char namebuf[NSYMB]; EXTERN char namebuf[NSYMB];
EXTERN char lexbuf[NSYMB];
EXTERN char debug[256]; EXTERN char debug[256];
EXTERN Sym* hash[NHASH]; EXTERN Sym* hash[NHASH];
EXTERN Sym* dclstack; EXTERN Sym* dclstack;
......
...@@ -370,12 +370,12 @@ l0: ...@@ -370,12 +370,12 @@ l0:
if(c >= Runeself) { if(c >= Runeself) {
/* all multibyte runes are alpha */ /* all multibyte runes are alpha */
cp = namebuf; cp = lexbuf;
goto talph; goto talph;
} }
if(isalpha(c)) { if(isalpha(c)) {
cp = namebuf; cp = lexbuf;
goto talph; goto talph;
} }
...@@ -388,13 +388,13 @@ l0: ...@@ -388,13 +388,13 @@ l0:
return -1; return -1;
case '_': case '_':
cp = namebuf; cp = lexbuf;
goto talph; goto talph;
case '.': case '.':
c1 = getc(); c1 = getc();
if(isdigit(c1)) { if(isdigit(c1)) {
cp = namebuf; cp = lexbuf;
*cp++ = c; *cp++ = c;
c = c1; c = c1;
c1 = 0; c1 = 0;
...@@ -413,7 +413,7 @@ l0: ...@@ -413,7 +413,7 @@ l0:
case '"': case '"':
/* "..." */ /* "..." */
strcpy(namebuf, "\"<string>\""); strcpy(lexbuf, "\"<string>\"");
cp = mal(sizeof(int32)); cp = mal(sizeof(int32));
clen = sizeof(int32); clen = sizeof(int32);
...@@ -437,7 +437,7 @@ l0: ...@@ -437,7 +437,7 @@ l0:
case '`': case '`':
/* `...` */ /* `...` */
strcpy(namebuf, "`<string>`"); strcpy(lexbuf, "`<string>`");
cp = mal(sizeof(int32)); cp = mal(sizeof(int32));
clen = sizeof(int32); clen = sizeof(int32);
...@@ -719,7 +719,7 @@ asop: ...@@ -719,7 +719,7 @@ asop:
talph: talph:
/* /*
* cp is set to namebuf and some * cp is set to lexbuf and some
* prefix has been stored * prefix has been stored
*/ */
for(;;) { for(;;) {
...@@ -748,7 +748,7 @@ talph: ...@@ -748,7 +748,7 @@ talph:
*cp = 0; *cp = 0;
ungetc(c); ungetc(c);
s = lookup(namebuf); s = lookup(lexbuf);
if(s->lexical == LIGNORE) if(s->lexical == LIGNORE)
goto l0; goto l0;
...@@ -768,7 +768,7 @@ talph: ...@@ -768,7 +768,7 @@ talph:
tnum: tnum:
c1 = 0; c1 = 0;
cp = namebuf; cp = lexbuf;
if(c != '0') { if(c != '0') {
for(;;) { for(;;) {
*cp++ = c; *cp++ = c;
...@@ -790,7 +790,7 @@ tnum: ...@@ -790,7 +790,7 @@ tnum:
continue; continue;
if(c >= 'A' && c <= 'F') if(c >= 'A' && c <= 'F')
continue; continue;
if(cp == namebuf+2) if(cp == lexbuf+2)
yyerror("malformed hex constant"); yyerror("malformed hex constant");
goto ncu; goto ncu;
} }
...@@ -826,7 +826,7 @@ ncu: ...@@ -826,7 +826,7 @@ ncu:
ungetc(c); ungetc(c);
yylval.val.u.xval = mal(sizeof(*yylval.val.u.xval)); yylval.val.u.xval = mal(sizeof(*yylval.val.u.xval));
mpatofix(yylval.val.u.xval, namebuf); mpatofix(yylval.val.u.xval, lexbuf);
if(yylval.val.u.xval->ovf) { if(yylval.val.u.xval->ovf) {
yyerror("overflow in constant"); yyerror("overflow in constant");
mpmovecfix(yylval.val.u.xval, 0); mpmovecfix(yylval.val.u.xval, 0);
...@@ -880,7 +880,7 @@ caseout: ...@@ -880,7 +880,7 @@ caseout:
ungetc(c); ungetc(c);
yylval.val.u.fval = mal(sizeof(*yylval.val.u.fval)); yylval.val.u.fval = mal(sizeof(*yylval.val.u.fval));
mpatoflt(yylval.val.u.fval, namebuf); mpatoflt(yylval.val.u.fval, lexbuf);
if(yylval.val.u.fval->val.ovf) { if(yylval.val.u.fval->val.ovf) {
yyerror("overflow in float constant"); yyerror("overflow in float constant");
mpmovecflt(yylval.val.u.fval, 0.0); mpmovecflt(yylval.val.u.fval, 0.0);
......
...@@ -23,7 +23,7 @@ yyerror(char *fmt, ...) ...@@ -23,7 +23,7 @@ yyerror(char *fmt, ...)
vfprint(1, fmt, arg); vfprint(1, fmt, arg);
va_end(arg); va_end(arg);
if(strcmp(fmt, "syntax error") == 0) if(strcmp(fmt, "syntax error") == 0)
print(" near %s", namebuf); print(" near %s", lexbuf);
print("\n"); print("\n");
if(debug['h']) if(debug['h'])
*(int*)0 = 0; *(int*)0 = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment