From 491fd81c97c9331d5595592cc3c5284f1816fed6 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 1 Mar 2014 00:35:16 +0900 Subject: [PATCH] add an alias 'yylval' linked to '*yylvalp' --- src/scan.l | 58 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/scan.l b/src/scan.l index 84a622eb..4e24ba8a 100644 --- a/src/scan.l +++ b/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; } "#|" { - yylvalp->i++; + yylval.i++; } "|#" { - if (yylvalp->i == 0) + if (yylval.i == 0) BEGIN(INITIAL); else - yylvalp->i--; + yylval.i--; } .|\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(); } "\"" { - 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); } -alarm { yylvalp->c = '\a'; BEGIN(INITIAL); return tCHAR; } -backspace { yylvalp->c = '\b'; BEGIN(INITIAL); return tCHAR; } -delete { yylvalp->c = 0x7f; BEGIN(INITIAL); return tCHAR; } -escape { yylvalp->c = 0x1b; BEGIN(INITIAL); return tCHAR; } -newline { yylvalp->c = '\n'; BEGIN(INITIAL); return tCHAR; } -null { yylvalp->c = '\0'; BEGIN(INITIAL); return tCHAR; } -return { yylvalp->c = '\r'; BEGIN(INITIAL); return tCHAR; } -space { yylvalp->c = ' '; BEGIN(INITIAL); return tCHAR; } -tab { yylvalp->c = '\t'; BEGIN(INITIAL); return tCHAR; } -. { yylvalp->c = yytext[0]; BEGIN(INITIAL); return tCHAR; } +alarm { yylval.c = '\a'; BEGIN(INITIAL); return tCHAR; } +backspace { yylval.c = '\b'; BEGIN(INITIAL); return tCHAR; } +delete { yylval.c = 0x7f; BEGIN(INITIAL); return tCHAR; } +escape { yylval.c = 0x1b; BEGIN(INITIAL); return tCHAR; } +newline { yylval.c = '\n'; BEGIN(INITIAL); return tCHAR; } +null { yylval.c = '\0'; BEGIN(INITIAL); return tCHAR; } +return { yylval.c = '\r'; BEGIN(INITIAL); return tCHAR; } +space { yylval.c = ' '; BEGIN(INITIAL); return tCHAR; } +tab { yylval.c = '\t'; BEGIN(INITIAL); return tCHAR; } +. { 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); } [ \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); } } ")" {