add an alias 'yylval' linked to '*yylvalp'
This commit is contained in:
parent
cbad58f560
commit
491fd81c97
58
src/scan.l
58
src/scan.l
|
@ -9,6 +9,8 @@
|
|||
|
||||
#define YY_DECL int yylex_(YYSTYPE *yylvalp, yyscan_t yyscanner)
|
||||
|
||||
#define yylval (*yylvalp)
|
||||
|
||||
/* NOTE:
|
||||
* An internal function `yy_fatal_error` takes yyscanner for its second
|
||||
* argument but doesn't use it. This invokes a `unused variable` compiler
|
||||
|
@ -70,16 +72,16 @@ infnan "+inf.0"|"-inf.0"|"+nan.0"|"-nan.0"
|
|||
|
||||
"#|" {
|
||||
BEGIN(BLOCK_COMMENT);
|
||||
yylvalp->i = 0;
|
||||
yylval.i = 0;
|
||||
}
|
||||
<BLOCK_COMMENT>"#|" {
|
||||
yylvalp->i++;
|
||||
yylval.i++;
|
||||
}
|
||||
<BLOCK_COMMENT>"|#" {
|
||||
if (yylvalp->i == 0)
|
||||
if (yylval.i == 0)
|
||||
BEGIN(INITIAL);
|
||||
else
|
||||
yylvalp->i--;
|
||||
yylval.i--;
|
||||
}
|
||||
<BLOCK_COMMENT>.|\n {
|
||||
/* skip block comment */
|
||||
|
@ -98,23 +100,23 @@ infnan "+inf.0"|"-inf.0"|"+nan.0"|"-nan.0"
|
|||
",@" return tUNQUOTE_SPLICING;
|
||||
|
||||
{boolean} {
|
||||
yylvalp->i = (yytext[1] == 't');
|
||||
yylval.i = (yytext[1] == 't');
|
||||
return tBOOLEAN;
|
||||
}
|
||||
|
||||
{integer} {
|
||||
yylvalp->i = atoi(yytext);
|
||||
yylval.i = atoi(yytext);
|
||||
return tINT;
|
||||
}
|
||||
|
||||
{real} {
|
||||
yylvalp->f = atof(yytext);
|
||||
yylval.f = atof(yytext);
|
||||
return tFLOAT;
|
||||
}
|
||||
|
||||
{identifier} {
|
||||
yylvalp->str.buf = yytext;
|
||||
yylvalp->str.len = yyleng;
|
||||
yylval.str.buf = yytext;
|
||||
yylval.str.len = yyleng;
|
||||
return tSYMBOL;
|
||||
}
|
||||
|
||||
|
@ -125,8 +127,8 @@ infnan "+inf.0"|"-inf.0"|"+nan.0"|"-nan.0"
|
|||
yymore();
|
||||
}
|
||||
<STRING>"\"" {
|
||||
yylvalp->str.buf = yytext;
|
||||
yylvalp->str.len = yyleng - 1;
|
||||
yylval.str.buf = yytext;
|
||||
yylval.str.len = yyleng - 1;
|
||||
BEGIN(INITIAL);
|
||||
return tSTRING;
|
||||
}
|
||||
|
@ -134,22 +136,22 @@ infnan "+inf.0"|"-inf.0"|"+nan.0"|"-nan.0"
|
|||
#\\ {
|
||||
BEGIN(CHAR);
|
||||
}
|
||||
<CHAR>alarm { yylvalp->c = '\a'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>backspace { yylvalp->c = '\b'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>delete { yylvalp->c = 0x7f; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>escape { yylvalp->c = 0x1b; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>newline { yylvalp->c = '\n'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>null { yylvalp->c = '\0'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>return { yylvalp->c = '\r'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>space { yylvalp->c = ' '; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>tab { yylvalp->c = '\t'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>. { yylvalp->c = yytext[0]; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>alarm { yylval.c = '\a'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>backspace { yylval.c = '\b'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>delete { yylval.c = 0x7f; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>escape { yylval.c = 0x1b; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>newline { yylval.c = '\n'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>null { yylval.c = '\0'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>return { yylval.c = '\r'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>space { yylval.c = ' '; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>tab { yylval.c = '\t'; BEGIN(INITIAL); return tCHAR; }
|
||||
<CHAR>. { yylval.c = yytext[0]; BEGIN(INITIAL); return tCHAR; }
|
||||
|
||||
"#u8(" {
|
||||
BEGIN(BYTEVECTOR);
|
||||
yylvalp->blob.len = 0;
|
||||
yylvalp->blob.capa = 10;
|
||||
yylvalp->blob.dat = calloc(10, 1);
|
||||
yylval.blob.len = 0;
|
||||
yylval.blob.capa = 10;
|
||||
yylval.blob.dat = calloc(10, 1);
|
||||
}
|
||||
<BYTEVECTOR>[ \r\n\t] {
|
||||
/* skip whitespace */
|
||||
|
@ -158,10 +160,10 @@ infnan "+inf.0"|"-inf.0"|"+nan.0"|"-nan.0"
|
|||
int i = atoi(yytext);
|
||||
if (0 > i || i > 255)
|
||||
REJECT;
|
||||
yylvalp->blob.dat[yylvalp->blob.len++] = (char)i;
|
||||
if (yylvalp->blob.len > yylvalp->blob.capa) {
|
||||
yylvalp->blob.capa *= 2;
|
||||
yylvalp->blob.dat = yyrealloc(yylvalp->blob.dat, yylvalp->blob.capa, yyscanner);
|
||||
yylval.blob.dat[yylval.blob.len++] = (char)i;
|
||||
if (yylval.blob.len > yylval.blob.capa) {
|
||||
yylval.blob.capa *= 2;
|
||||
yylval.blob.dat = yyrealloc(yylval.blob.dat, yylval.blob.capa, yyscanner);
|
||||
}
|
||||
}
|
||||
<BYTEVECTOR>")" {
|
||||
|
|
Loading…
Reference in New Issue