scc

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

commit 69e7535d59c4e567c5279bea077e2ee7e24cb59a
parent eb99e511ae17e585239954aa02821a05be94eb08
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  4 Jun 2012 21:25:41 +0200

Added basic token for integers

This patch adds the tokenizer for integer numbers, without testing sizes,
formats or other aspects. This version is only s stub.

Diffstat:
Mlex.c | 19++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/lex.c b/lex.c @@ -95,6 +95,22 @@ void init_lex(void) } } +static char number(void) +{ + register char *bp; + register char ch; + + for (bp = yytext; bp < yytext + TOKSIZ_MAX; *bp++ = ch) { + if (!isdigit(ch = getc(yyin))) + break; + } + if (bp == yytext + TOKSIZ_MAX) + error("identifier too long %s", yytext); + ungetc(ch, yyin); + *bp = '\0'; + return CONSTANT; +} + static unsigned char iden(void) { register struct keyword *kwp; @@ -140,7 +156,8 @@ unsigned char next(void) ungetc(ch, yyin); ch = iden(); } else if (isdigit(ch)) { - ; + ungetc(ch, yyin); + ch = number(); } else { switch (ch) { case '&': case '|':