summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2010-05-24 11:29:02 -0700
committerCarl Worth <cworth@cworth.org>2010-05-24 11:29:02 -0700
commit03f6d5d2d4a6c42a197ee8eb4e26b87c87bbe43e (patch)
tree9e35f695214ac5d20554540a2a4d1a245fab9f01
parent35419095f8d92f7dc5de472da3a0271d343cbcba (diff)
Add support for octal and hexadecimal integer literals.
In addition to the decimal literals which we already support. Note that we use strtoll here to get the large-width integers demanded by the specification.
-rw-r--r--glcpp-lex.l19
1 files changed, 16 insertions, 3 deletions
diff --git a/glcpp-lex.l b/glcpp-lex.l
index fe95508a32..ee1f6e3aee 100644
--- a/glcpp-lex.l
+++ b/glcpp-lex.l
@@ -45,10 +45,13 @@ NONSPACE [^[:space:]]
NEWLINE [\n]
HSPACE [ \t]
HASH ^{HSPACE}*#{HSPACE}*
-INTEGER [0-9]+
IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
TOKEN [^[:space:](),]+
+DECIMAL_INTEGER [1-9][0-9]*[uU]?
+OCTAL_INTEGER 0[0-7]*[uU]?
+HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]?
+
%%
{HASH}if{HSPACE}* {
@@ -61,8 +64,18 @@ TOKEN [^[:space:](),]+
return ELIF;
}
-<ST_IF>{INTEGER} {
- yylval.ival = atoi (yytext);
+<ST_IF>{DECIMAL_INTEGER} {
+ yylval.ival = strtoll (yytext, NULL, 10);
+ return INTEGER;
+}
+
+<ST_IF>{OCTAL_INTEGER} {
+ yylval.ival = strtoll (yytext + 1, NULL, 8);
+ return INTEGER;
+}
+
+<ST_IF>{HEXADECIMAL_INTEGER} {
+ yylval.ival = strtoll (yytext + 2, NULL, 16);
return INTEGER;
}