Commit 8abcdee1 authored by Russ Cox's avatar Russ Cox

implement optional semicolons with help from the lexer,

instead of having to double the type and statement grammars.

R=ken
OCL=29987
CL=29998
parent e9e38841
......@@ -622,6 +622,7 @@ void importfile(Val*);
void cannedimports(char*, char*);
void unimportfile();
int32 yylex(void);
void yyoptsemi(int);
void typeinit(void);
void lexinit(void);
char* lexname(int);
......@@ -1017,6 +1018,10 @@ EXTERN Prog* breakpc;
EXTERN Prog* pc;
EXTERN Prog* firstpc;
EXTERN int yylast;
EXTERN int yynext;
EXTERN int yysemi;
void allocparams(void);
void cgen_as(Node *nl, Node *nr);
void cgen_callmeth(Node *n, int proc);
......
This diff is collapsed.
......@@ -8,6 +8,8 @@
#include "y.tab.h"
#include <ar.h>
extern int yychar;
#define DBG if(!debug['x']);else print
enum
{
......@@ -366,8 +368,8 @@ isfrog(int c)
return 0;
}
int32
yylex(void)
static int32
_yylex(void)
{
int c, c1, clen;
vlong v;
......@@ -941,6 +943,44 @@ caseout:
return LLITERAL;
}
/*
* help the parser. if the next token is not c and not ';',
* insert a ';' before it.
*/
void
yyoptsemi(int c)
{
if(c == 0)
c = -1;
if(yychar <= 0)
yysemi = c;
}
int32
yylex(void)
{
// if we delayed a token, return that one.
if(yynext) {
yylast = yynext;
yynext = 0;
return yylast;
}
yylast = _yylex();
// if there's an optional semicolon needed,
// delay the token we just read.
if(yysemi) {
if(yylast != ';' && yylast != yysemi) {
yynext = yylast;
yylast = ';';
}
yysemi = 0;
}
return yylast;
}
int
getc(void)
{
......
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