mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 15:01:41 +00:00
expr.h:
add prototype for print_expr expr.c: add print_expr correct string accessors currect the result type for unary operators qc-lex.l: correct string, vector and quaternion parsing qc-parse.y: precedence corrections and more function scope work CustomTF gets through the parsing again.
This commit is contained in:
parent
3dbc913903
commit
ab051248e8
4 changed files with 91 additions and 18 deletions
|
@ -34,6 +34,7 @@ typedef struct expr_s {
|
|||
} expr_t;
|
||||
|
||||
expr_t *new_expr (void);
|
||||
void print_expr (expr_t *e);
|
||||
expr_t *binary_expr (int op, expr_t *e1, expr_t *e2);
|
||||
expr_t *unary_expr (int op, expr_t *e);
|
||||
expr_t *function_expr (expr_t *e1, expr_t *e2);
|
||||
|
|
|
@ -63,6 +63,68 @@ new_expr ()
|
|||
return calloc (1, sizeof (expr_t));
|
||||
}
|
||||
|
||||
void
|
||||
print_expr (expr_t *e)
|
||||
{
|
||||
printf (" ");
|
||||
switch (e->type) {
|
||||
case ex_statement:
|
||||
break;
|
||||
case ex_expr:
|
||||
print_expr (e->e.expr.e1);
|
||||
if (e->e.expr.op == 'c') {
|
||||
expr_t *p = e->e.expr.e2;
|
||||
printf ("(");
|
||||
while (p) {
|
||||
print_expr (p);
|
||||
if (p->next)
|
||||
printf (",");
|
||||
p = p->next;
|
||||
}
|
||||
printf (")");
|
||||
} else {
|
||||
print_expr (e->e.expr.e2);
|
||||
if (isprint (e->e.expr.op)) {
|
||||
printf (" %c", e->e.expr.op);
|
||||
} else {
|
||||
printf (" %d", e->e.expr.op);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ex_uexpr:
|
||||
print_expr (e->e.expr.e1);
|
||||
if (isprint (e->e.expr.op)) {
|
||||
printf (" u%c", e->e.expr.op);
|
||||
} else {
|
||||
printf (" u%d", e->e.expr.op);
|
||||
}
|
||||
break;
|
||||
case ex_def:
|
||||
printf ("%s", e->e.def->name);
|
||||
break;
|
||||
case ex_int:
|
||||
printf ("%d", e->e.int_val);
|
||||
break;
|
||||
case ex_float:
|
||||
printf ("%g", e->e.float_val);
|
||||
break;
|
||||
case ex_string:
|
||||
printf ("\"%s\"", strings + e->e.string_val);
|
||||
break;
|
||||
case ex_vector:
|
||||
printf ("'%g", e->e.vector_val[0]);
|
||||
printf ( " %g", e->e.vector_val[1]);
|
||||
printf ( " %g'", e->e.vector_val[2]);
|
||||
break;
|
||||
case ex_quaternion:
|
||||
printf ("'%g", e->e.quaternion_val[0]);
|
||||
printf (" %g", e->e.quaternion_val[1]);
|
||||
printf (" %g", e->e.quaternion_val[2]);
|
||||
printf (" %g'", e->e.quaternion_val[3]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static expr_t *
|
||||
do_op_string (int op, expr_t *e1, expr_t *e2)
|
||||
{
|
||||
|
@ -70,8 +132,8 @@ do_op_string (int op, expr_t *e1, expr_t *e2)
|
|||
char *buf;
|
||||
char *s1, *s2;
|
||||
|
||||
s1 = G_STRING(e1->e.string_val);
|
||||
s2 = G_STRING(e2->e.string_val);
|
||||
s1 = strings + e1->e.string_val;
|
||||
s2 = strings + e2->e.string_val;
|
||||
|
||||
switch (op) {
|
||||
case '+':
|
||||
|
@ -367,7 +429,7 @@ unary_expr (int op, expr_t *e)
|
|||
case ex_def:
|
||||
{
|
||||
expr_t *n = new_expr ();
|
||||
n->type = ex_expr;
|
||||
n->type = ex_uexpr;
|
||||
n->e.expr.op = op;
|
||||
n->e.expr.type = (e->type == ex_def)
|
||||
? e->e.def->type
|
||||
|
@ -405,7 +467,7 @@ unary_expr (int op, expr_t *e)
|
|||
case ex_def:
|
||||
{
|
||||
expr_t *n = new_expr ();
|
||||
n->type = ex_expr;
|
||||
n->type = ex_uexpr;
|
||||
n->e.expr.op = op;
|
||||
n->e.expr.type = &type_float;
|
||||
n->e.expr.e1 = e;
|
||||
|
|
|
@ -62,22 +62,24 @@ m ([\-+]?)
|
|||
{ID} return type_or_name(yytext);
|
||||
|
||||
\"(\\.|[^"])*\" {
|
||||
yylval.string_val = strdup (yytext);
|
||||
int len = strlen (yytext) - 2;
|
||||
yylval.string_val = malloc (len + 1);
|
||||
strncpy (yylval.string_val, yytext + 1, len);
|
||||
yylval.string_val[len] = 0;
|
||||
return STRING_VAL;
|
||||
}
|
||||
|
||||
'{s}*{m}{NUM}{s}+{m}{NUM}{s}+{m}{NUM}{s}*' {
|
||||
sscanf (yytext, "%f %f %f", &yylval.vector_val[0],
|
||||
&yylval.vector_val[1],
|
||||
&yylval.vector_val[2]);
|
||||
sscanf (yytext, "' %f %f %f '",
|
||||
&yylval.vector_val[0], &yylval.vector_val[1],
|
||||
&yylval.vector_val[2]);
|
||||
return VECTOR_VAL;
|
||||
}
|
||||
|
||||
'{s}*{m}{NUM}{s}+{m}{NUM}{s}+{m}{NUM}{s}+{m}{NUM}{s}*' {
|
||||
sscanf (yytext, "%f %f %f %f", &yylval.vector_val[0],
|
||||
&yylval.vector_val[1],
|
||||
&yylval.vector_val[2],
|
||||
&yylval.vector_val[3]);
|
||||
sscanf (yytext, "' %f %f %f %f '",
|
||||
&yylval.vector_val[0], &yylval.vector_val[1],
|
||||
&yylval.vector_val[2], &yylval.vector_val[3]);
|
||||
return VECTOR_VAL;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ void PR_PrintType(type_t*);
|
|||
|
||||
type_t *parse_params (def_t *parms);
|
||||
function_t *new_function (void);
|
||||
void build_scope (def_t *func, def_t *parms);
|
||||
void build_scope (def_t *func);
|
||||
|
||||
typedef struct {
|
||||
type_t *type;
|
||||
|
@ -48,8 +48,9 @@ typedef struct {
|
|||
%left EQ NE LE GE LT GT
|
||||
%left '+' '-'
|
||||
%left '*' '/' '&' '|'
|
||||
%left '!' '.'
|
||||
%left '!'
|
||||
%right '('
|
||||
%left '.'
|
||||
|
||||
%token <string_val> NAME STRING_VAL
|
||||
%token <int_val> INT_VAL
|
||||
|
@ -130,7 +131,6 @@ maybe_func
|
|||
}
|
||||
param_list
|
||||
{
|
||||
$<def>$ = param_scope.scope_next;
|
||||
PR_FlushScope (¶m_scope);
|
||||
current_type = $<scope>2.type;
|
||||
param_scope.scope_next = $<scope>2.pscope;
|
||||
|
@ -138,7 +138,7 @@ maybe_func
|
|||
}
|
||||
')'
|
||||
{
|
||||
$$ = parse_params ($<def>4);
|
||||
$$ = parse_params ($3);
|
||||
}
|
||||
| '(' ')'
|
||||
{
|
||||
|
@ -230,6 +230,7 @@ begin_function
|
|||
: /*empty*/
|
||||
{
|
||||
pr_scope = current_def;
|
||||
build_scope (current_def);
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -300,9 +301,9 @@ expr
|
|||
| expr '/' expr { $$ = binary_expr ('/', $1, $3); }
|
||||
| expr '&' expr { $$ = binary_expr ('&', $1, $3); }
|
||||
| expr '|' expr { $$ = binary_expr ('|', $1, $3); }
|
||||
| expr '.' expr { $$ = binary_expr ('.', $1, $3); }
|
||||
| expr '(' arg_list ')' { $$ = function_expr ($1, $3); }
|
||||
| expr '(' ')' { $$ = function_expr ($1, 0); }
|
||||
| expr '.' expr { $$ = binary_expr ('.', $1, $3); }
|
||||
| '-' expr { $$ = unary_expr ('-', $2); }
|
||||
| '!' expr { $$ = unary_expr ('!', $2); }
|
||||
| NAME
|
||||
|
@ -394,8 +395,15 @@ parse_params (def_t *parms)
|
|||
}
|
||||
|
||||
void
|
||||
build_scope (def_t *func, def_t *parms)
|
||||
build_scope (def_t *func)
|
||||
{
|
||||
int i;
|
||||
def_t *def;
|
||||
type_t *ftype = func->type;
|
||||
|
||||
for (i = 0; i < ftype->num_parms; i++) {
|
||||
def = PR_GetDef (ftype->parm_types[i], pr_parm_names[i], func, &func->num_locals);
|
||||
}
|
||||
}
|
||||
|
||||
function_t *
|
||||
|
|
Loading…
Reference in a new issue