scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 68ccb5a199aa86efb8b07f550a64860cb5da950d
parent 84ae6c8c605f208229ccf38cfcc6b42ae735b1db
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 10 May 2015 11:58:33 +0200

Add yylen variable

This variable holds the length of the current lexem.

Diffstat:
Mcc1/lex.c | 9++++-----
1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/cc1/lex.c b/cc1/lex.c @@ -29,6 +29,7 @@ uint8_t lex_ns = NS_IDEN; uint8_t yytoken; struct yystype yylval; char yytext[IDENTSIZ + 1]; +unsigned short yylen; static uint8_t safe; static Input *input; @@ -206,12 +207,10 @@ repeat: static void tok2str(void) { - size_t len; - - if ((len = input->p - input->begin) > IDENTSIZ) + if ((yylen = input->p - input->begin) > IDENTSIZ) error("token too big"); - strncpy(yytext, input->begin, len); - yytext[len] = '\0'; + strncpy(yytext, input->begin, yylen); + yytext[yylen] = '\0'; fprintf(stderr ,"%s\n", yytext); input->begin = input->p; }