add an alias 'yylval' linked to '*yylvalp'

This commit is contained in:
Yuichi Nishiwaki 2014-03-01 00:35:16 +09:00
parent cbad58f560
commit 491fd81c97
1 changed files with 30 additions and 28 deletions

View File

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