mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 15:01:41 +00:00
Cleanup QC's constant handling based on QP.
This commit is contained in:
parent
c38ea0b1bc
commit
ffea505678
2 changed files with 66 additions and 95 deletions
|
@ -82,20 +82,22 @@ int yylex_destroy (void);
|
|||
YY_DECL;
|
||||
|
||||
|
||||
static int type_or_name (char *token);
|
||||
static int keyword_or_id (char *token);
|
||||
|
||||
extern YYSTYPE yylval;
|
||||
|
||||
%}
|
||||
|
||||
DIGIT [0-9]
|
||||
XDIGIT [0-9a-fA-F]
|
||||
ID [a-zA-Z_][a-zA-Z_0-9]*
|
||||
FLOAT {DIGIT}+"."{DIGIT}*
|
||||
NUM ({DIGIT}+("."{DIGIT}*)?)
|
||||
s [ \t]
|
||||
m ([\-+]?)
|
||||
FRAMEID {ID}(\.{ID})*
|
||||
s [ \t]
|
||||
m [\-+]
|
||||
D [0-9]
|
||||
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}+)
|
||||
RANGE \.\.
|
||||
ELLIPSIS \.\.\.
|
||||
FRAMEID {ID}(\.{ID})*
|
||||
|
||||
%x GRAB_FRAME GRAB_OTHER COMMENT
|
||||
|
||||
|
@ -111,48 +113,33 @@ FRAMEID {ID}(\.{ID})*
|
|||
<COMMENT><<EOF>> { error (0, "EOF in comment"); return 0; }
|
||||
"//".* /* nothing to do */
|
||||
|
||||
^#{s}+{DIGIT}+{s}+\"(\.|[^"\n])*\".*$ { line_info (yytext + 1); }
|
||||
^#line{s}+{DIGIT}+{s}+\"(\.|[^"\n])*\".*$ { line_info (yytext + 5); }
|
||||
^#{s}+{D}+{s}+\"(\.|[^"\n])*\".*$ { line_info (yytext + 1); }
|
||||
^#line{s}+{D}+{s}+\"(\.|[^"\n])*\".*$ { line_info (yytext + 5); }
|
||||
|
||||
^{s}*#{s}*pragma.*$ /* skip */
|
||||
|
||||
{DIGIT}+[uU]? {
|
||||
{INT}+[uU]? {
|
||||
const char *c = yytext + yyleng - 1;
|
||||
int uint = 0;
|
||||
yylval.integer_val = atoi (yytext);
|
||||
int i = strtol (yytext, 0, 0);
|
||||
if (*c == 'u' || *c == 'U')
|
||||
uint = 1;
|
||||
return uint ? UINT_VAL : INT_VAL;
|
||||
yylval.expr = new_uinteger_expr (i);
|
||||
else
|
||||
yylval.expr = new_integer_expr (i);
|
||||
return CONST;
|
||||
}
|
||||
|
||||
0[xX]{XDIGIT}+[uU]? {
|
||||
const char *c = yytext + 2;
|
||||
int uint = 0;
|
||||
yylval.uinteger_val = 0;
|
||||
while (*c) {
|
||||
if (*c == 'u' || *c == 'U') {
|
||||
uint = 1;
|
||||
break;
|
||||
}
|
||||
yylval.uinteger_val *= 16;
|
||||
yylval.uinteger_val += *c - '0';
|
||||
if (*c > '9')
|
||||
yylval.uinteger_val -= 'A' - '9' - 1;
|
||||
if (*c > 'F')
|
||||
yylval.uinteger_val -= 'a' - 'A';
|
||||
c++;
|
||||
}
|
||||
return uint ? UINT_VAL : INT_VAL;
|
||||
{FLOAT} {
|
||||
float f = strtof (yytext, 0);
|
||||
yylval.expr = new_float_expr (f);
|
||||
return CONST;
|
||||
}
|
||||
|
||||
{FLOAT}* {
|
||||
yylval.float_val = atof (yytext);
|
||||
return FLOAT_VAL;
|
||||
{ID} {
|
||||
int tok = keyword_or_id(yytext);
|
||||
return tok;
|
||||
}
|
||||
|
||||
{ID} return type_or_name(yytext);
|
||||
@{ID} {
|
||||
int tok = type_or_name(yytext);
|
||||
int tok = keyword_or_id(yytext);
|
||||
if (tok == '@')
|
||||
REJECT;
|
||||
return tok;
|
||||
|
@ -160,24 +147,25 @@ FRAMEID {ID}(\.{ID})*
|
|||
@ return '@';
|
||||
|
||||
\"(\\.|[^"\\])*\" {
|
||||
yylval.string_val = make_string (yytext, 0);
|
||||
return STRING_VAL;
|
||||
const char *s = make_string (yytext, 0);
|
||||
yylval.expr = new_string_expr (s);
|
||||
return CONST;
|
||||
}
|
||||
|
||||
'{s}*{m}{NUM}{s}+{m}{NUM}{s}+{m}{NUM}{s}*' {
|
||||
'{s}*{m}?{FLOAT}{s}+{m}?{FLOAT}{s}+{m}?{FLOAT}{s}*' {
|
||||
vec3_t v;
|
||||
sscanf (yytext, "' %f %f %f '",
|
||||
&yylval.vector_val[0], &yylval.vector_val[1],
|
||||
&yylval.vector_val[2]);
|
||||
return VECTOR_VAL;
|
||||
&v[0], &v[1], &v[2]);
|
||||
yylval.expr = new_vector_expr (v);
|
||||
return CONST;
|
||||
}
|
||||
|
||||
'{s}*{m}{NUM}{s}+{m}{NUM}{s}+{m}{NUM}{s}+{m}{NUM}{s}*' {
|
||||
sscanf (yytext, "' %f %f %f %f '",
|
||||
&yylval.quaternion_val[0],
|
||||
&yylval.quaternion_val[1],
|
||||
&yylval.quaternion_val[2],
|
||||
&yylval.quaternion_val[3]);
|
||||
return QUATERNION_VAL;
|
||||
'{s}*{m}?{FLOAT}{s}+{m}?{FLOAT}{s}+{m}?{FLOAT}{s}+{m}?{FLOAT}{s}*' {
|
||||
quat_t q;
|
||||
sscanf (yytext, "' %f %f %f %f'",
|
||||
&q[0], &q[1], &q[2], &q[3]);
|
||||
yylval.expr = new_quaternion_expr (q);
|
||||
return CONST;
|
||||
}
|
||||
|
||||
'(\\[^xX0-7\r\n]|[^'\r\n]|\\[xX][0-9A-Fa-f]+|\\[0-7]+)*' {
|
||||
|
@ -185,8 +173,8 @@ FRAMEID {ID}(\.{ID})*
|
|||
|
||||
if (str[1])
|
||||
warning (0, "multibyte char constant");
|
||||
yylval.integer_val = *str;
|
||||
return INT_VAL;
|
||||
yylval.expr = new_integer_expr (*str);
|
||||
return CONST;
|
||||
}
|
||||
|
||||
[+\-*/&|^%]= {
|
||||
|
@ -205,22 +193,23 @@ FRAMEID {ID}(\.{ID})*
|
|||
}
|
||||
|
||||
[!(){}.*/&|^~+\-=\[\];,#%?:] {
|
||||
yylval.op = yytext[0];
|
||||
return yytext[0];
|
||||
}
|
||||
|
||||
"..." return ELLIPSIS;
|
||||
{ELLIPSIS} return ELLIPSIS;
|
||||
|
||||
"<<" return SHL;
|
||||
">>" return SHR;
|
||||
"<<" return SHL;
|
||||
">>" return SHR;
|
||||
|
||||
"&&" return AND;
|
||||
"||" return OR;
|
||||
"==" return EQ;
|
||||
"!=" return NE;
|
||||
"<=" return LE;
|
||||
">=" return GE;
|
||||
"<" return LT;
|
||||
">" return GT;
|
||||
"&&" return AND;
|
||||
"||" return OR;
|
||||
"==" return EQ;
|
||||
"!=" return NE;
|
||||
"<=" return LE;
|
||||
">=" return GE;
|
||||
"<" return LT;
|
||||
">" return GT;
|
||||
|
||||
"++" {
|
||||
yylval.op = '+';
|
||||
|
@ -235,8 +224,8 @@ FRAMEID {ID}(\.{ID})*
|
|||
"$"{s}*{FRAMEID} {
|
||||
int ret = do_grab (yytext);
|
||||
if (ret >= 0) {
|
||||
yylval.integer_val = ret;
|
||||
return INT_VAL;
|
||||
yylval.expr = new_integer_expr (ret);
|
||||
return CONST;
|
||||
} else {
|
||||
BEGIN (-ret);
|
||||
}
|
||||
|
@ -337,7 +326,7 @@ keyword_get_key (void *kw, void *unused)
|
|||
}
|
||||
|
||||
static int
|
||||
type_or_name (char *token)
|
||||
keyword_or_id (char *token)
|
||||
{
|
||||
static hashtab_t *keyword_tab;
|
||||
keyword_t *keyword;
|
||||
|
|
|
@ -148,11 +148,7 @@ static def_t *create_def (type_t *type, const char *name, scope_t *scope,
|
|||
%left '.' '(' '['
|
||||
|
||||
%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
|
||||
%token <expr> CONST
|
||||
|
||||
%token LOCAL RETURN WHILE DO IF ELSE FOR BREAK CONTINUE ELLIPSIS NIL
|
||||
%token IFBE IFB IFAE IFA
|
||||
|
@ -172,7 +168,7 @@ static def_t *create_def (type_t *type, const char *name, scope_t *scope,
|
|||
%type <param> param param_list
|
||||
%type <def> opt_initializer methoddef var_initializer
|
||||
%type <expr> const opt_expr fexpr expr element_list element_list1 element
|
||||
%type <expr> string_val opt_state_expr think opt_step array_decl texpr
|
||||
%type <expr> opt_state_expr think opt_step array_decl texpr
|
||||
%type <expr> statement statements statement_block
|
||||
%type <expr> label break_label continue_label enum_list enum
|
||||
%type <expr> unary_expr primary cast_expr opt_arg_list arg_list
|
||||
|
@ -532,14 +528,7 @@ func_init
|
|||
builtin_function
|
||||
: /* emtpy */
|
||||
{
|
||||
def_t *def = $<def>-1;
|
||||
if (!def->external) {
|
||||
$$ = build_builtin_function (def, $<expr>0);
|
||||
if ($$) {
|
||||
build_scope ($$, $$->def, current_params);
|
||||
flush_scope ($$->scope, 1);
|
||||
}
|
||||
}
|
||||
$$ = build_builtin_function ($<def>-1, $<expr>0, current_params);
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -1170,20 +1159,13 @@ arg_list
|
|||
;
|
||||
|
||||
const
|
||||
: FLOAT_VAL { $$ = new_float_expr ($1); }
|
||||
| string_val { $$ = $1; }
|
||||
| VECTOR_VAL { $$ = new_vector_expr ($1); }
|
||||
| QUATERNION_VAL { $$ = new_quaternion_expr ($1); }
|
||||
| INT_VAL { $$ = new_integer_expr ($1); }
|
||||
| UINT_VAL { $$ = new_uinteger_expr ($1); }
|
||||
: CONST
|
||||
| NIL { $$ = new_nil_expr (); }
|
||||
;
|
||||
|
||||
string_val
|
||||
: STRING_VAL { $$ = new_string_expr ($1); }
|
||||
| string_val STRING_VAL
|
||||
| const CONST
|
||||
{
|
||||
$$ = binary_expr ('+', $1, new_string_expr ($2));
|
||||
if ($1->type != ex_string || $2->type != ex_string)
|
||||
PARSE_ERROR;
|
||||
$$ = binary_expr ('+', $1, $2);
|
||||
}
|
||||
;
|
||||
|
||||
|
|
Loading…
Reference in a new issue