Add unsigned integer constant support.

This commit is contained in:
Bill Currie 2010-12-23 19:32:28 +09:00
parent 7934e29473
commit 28740bb57f
2 changed files with 21 additions and 9 deletions

View file

@ -117,24 +117,33 @@ FRAMEID {ID}(\.{ID})*
^{s}*#{s}*pragma.*$ /* skip */
{DIGIT}+ {
{DIGIT}+[uU]? {
const char *c = yytext + yyleng - 1;
int uint = 0;
yylval.integer_val = atoi (yytext);
return INT_VAL;
if (*c == 'u' || *c == 'U')
uint = 1;
return uint ? UINT_VAL : INT_VAL;
}
0[xX]{XDIGIT}+ {
0[xX]{XDIGIT}+[uU]? {
const char *c = yytext + 2;
yylval.integer_val = 0;
int uint = 0;
yylval.uinteger_val = 0;
while (*c) {
yylval.integer_val *= 16;
yylval.integer_val += *c - '0';
if (*c == 'u' || *c == 'U') {
uint = 1;
break;
}
yylval.uinteger_val *= 16;
yylval.uinteger_val += *c - '0';
if (*c > '9')
yylval.integer_val -= 'A' - '9' - 1;
yylval.uinteger_val -= 'A' - '9' - 1;
if (*c > 'F')
yylval.integer_val -= 'a' - 'A';
yylval.uinteger_val -= 'a' - 'A';
c++;
}
return INT_VAL;
return uint ? UINT_VAL : INT_VAL;
}
{FLOAT}* {

View file

@ -107,6 +107,7 @@ expr_t *argv_expr (void);
struct typedef_s *typename;
struct expr_s *expr;
int integer_val;
unsigned uinteger_val;
float float_val;
const char *string_val;
float vector_val[3];
@ -151,6 +152,7 @@ expr_t *argv_expr (void);
%token <string_val> CLASS_NAME NAME STRING_VAL
%token <integer_val> INT_VAL
%token <uinteger_val> UINT_VAL
%token <float_val> FLOAT_VAL
%token <vector_val> VECTOR_VAL
%token <quaternion_val> QUATERNION_VAL
@ -1189,6 +1191,7 @@ const
| VECTOR_VAL { $$ = new_vector_expr ($1); }
| QUATERNION_VAL { $$ = new_quaternion_expr ($1); }
| INT_VAL { $$ = new_integer_expr ($1); }
| UINT_VAL { $$ = new_uinteger_expr ($1); }
| NIL { $$ = new_nil_expr (); }
;