Add support for binary constants using the 0b prefix.

Just because :P (now that gcc support it, it seems worthwhile, I guess)
This commit is contained in:
Bill Currie 2013-01-04 19:32:04 +09:00
parent 7206756952
commit 34c0c82408
2 changed files with 16 additions and 3 deletions

View file

@ -93,10 +93,11 @@ extern QC_YYSTYPE qc_yylval;
s [ \t]
m [\-+]
D [0-9]
B [01]
X [0-9a-fA-F]
ID [a-zA-Z_][a-zA-Z_0-9]*
FLOAT ({D}+|{D}*\.{D}+|{D}+\.{D}*)([eE]{m}?{D}+)?
INT ({D}+|0[xX]{X}+)
INT ({D}+|0[xX]{X}+|0[bB]{B})
RANGE \.\.
ELLIPSIS \.\.\.
FRAMEID {ID}(\.{ID})*
@ -125,7 +126,12 @@ STRING \"(\\.|[^"\\])*\"
{INT}+[uU]? {
const char *c = yytext + yyleng - 1;
int i = strtol (yytext, 0, 0);
int i;
if (yytext[0] == '0' && tolower (yytext[1] == 'b'))
i = strtol (yytext + 2, 0, 2);
else
i = strtol (yytext, 0, 0);
if (*c == 'u' || *c == 'U')
qc_yylval.expr = new_integer_expr (i);//FIXME
else

View file

@ -31,6 +31,7 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <ctype.h>
#include "QF/hash.h"
@ -76,6 +77,7 @@ static int convert_relop (const char *relop);
s [ \t]
m [\-+]
D [0-9]
B [01]
X [0-9a-fA-F]
ID [a-zA-Z_][0-9a-zA-Z_]*
FLOAT ({D}+|{D}*\.{D}+|{D}+\.{D}*)([eE]{m}?{D}+)?
@ -109,7 +111,12 @@ FRAMEID {ID}(\.{ID})*
^#line{s}+{D}+{s}+\"(\.|[^"\n])*\".*$ { line_info (yytext + 1); }
{INTEGER} {
int i = strtol (yytext, 0, 0);
int i;
if (yytext[0] == '0' && tolower (yytext[1] == 'b'))
i = strtol (yytext + 2, 0, 2);
else
i = strtol (yytext, 0, 0);
qp_yylval.expr = new_integer_expr (i);
return VALUE;
}