Navigation Menu

Skip to content

Commit

Permalink
Don't pass the TokenData back out of the lemon code.
Browse files Browse the repository at this point in the history
--HG--
branch : calculator-experiment
  • Loading branch information
icculus committed Feb 9, 2010
1 parent a858c52 commit 31af9ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions calculator.c
Expand Up @@ -225,11 +225,11 @@ static Expression *new_ternary_expr(Context *ctx, const Operator op,
return (Expression *) retval;
} // new_ternary_expr

static Expression *new_identifier_expr(Context *ctx, const TokenData *data)
static Expression *new_identifier_expr(Context *ctx, const char *string)
{
NEW_EXPR(ExpressionIdentifier);
retval->op = OP_IDENTIFIER;
retval->identifier = data->string; // cached; don't copy string.
retval->identifier = string; // cached; don't copy string!
return (Expression *) retval;
} // new_identifier_expr

Expand Down Expand Up @@ -270,11 +270,11 @@ static inline int64 strtoi64(const char *str, unsigned int len)
return retval;
} // strtoi64

static Expression *new_literal_int_expr(Context *ctx, const TokenData *data)
static Expression *new_literal_int_expr(Context *ctx, const int64 value)
{
NEW_EXPR(ExpressionIntLiteral);
retval->op = OP_INT_LITERAL;
retval->value = data->i64;
retval->value = value;
return (Expression *) retval;
} // new_literal_int_expr

Expand All @@ -287,19 +287,19 @@ static inline double strtodouble(const char *_str, unsigned int len)
return strtod(str, NULL);
} // strtodouble

static Expression *new_literal_float_expr(Context *ctx, const TokenData *data)
static Expression *new_literal_float_expr(Context *ctx, const double value)
{
NEW_EXPR(ExpressionFloatLiteral);
retval->op = OP_FLOAT_LITERAL;
retval->value = data->dbl;
retval->value = value;
return (Expression *) retval;
} // new_literal_float_expr

static Expression *new_literal_string_expr(Context *ctx, const TokenData *data)
static Expression *new_literal_string_expr(Context *ctx, const char *string)
{
NEW_EXPR(ExpressionStringLiteral);
retval->op = OP_STRING_LITERAL;
retval->string = data->string; // cached; don't copy string.
retval->string = string; // cached; don't copy string!
return (Expression *) retval;
} // new_string_literal_expr

Expand Down
10 changes: 5 additions & 5 deletions calculator.lemon
Expand Up @@ -78,10 +78,10 @@ calculator ::= expression(B). { parse_complete(ctx, B); }

// the expression stuff is based on Jeff Lee's ANSI C grammar.
%type primary_expr { Expression * }
primary_expr(A) ::= IDENTIFIER(B). { A = new_identifier_expr(ctx, &B); }
primary_expr(A) ::= INT_CONSTANT(B). { A = new_literal_int_expr(ctx, &B); }
primary_expr(A) ::= FLOAT_CONSTANT(B). { A = new_literal_float_expr(ctx, &B); }
primary_expr(A) ::= STRING_LITERAL(B). { A = new_literal_string_expr(ctx, &B); }
primary_expr(A) ::= IDENTIFIER(B). { A = new_identifier_expr(ctx, B.string); }
primary_expr(A) ::= INT_CONSTANT(B). { A = new_literal_int_expr(ctx, B.i64); }
primary_expr(A) ::= FLOAT_CONSTANT(B). { A = new_literal_float_expr(ctx, B.dbl); }
primary_expr(A) ::= STRING_LITERAL(B). { A = new_literal_string_expr(ctx, B.string); }
primary_expr(A) ::= LPAREN expression(B) RPAREN. { A = B; }

%type postfix_expr { Expression * }
Expand All @@ -90,7 +90,7 @@ postfix_expr(A) ::= postfix_expr(B) LBRACKET expression(C) RBRACKET. { A = new_b
postfix_expr(A) ::= postfix_expr(B) LPAREN RPAREN. { A = new_binary_expr(ctx, OP_CALLFUNC, B, NULL); }
postfix_expr(A) ::= postfix_expr(B) LPAREN argument_expr_list(C) RPAREN. { A = new_binary_expr(ctx, OP_CALLFUNC, B, C); }
//postfix_expr(A) ::= datatype(B) LPAREN argument_expr_list(C) RPAREN. { A = new_constructor_expr(ctx, B, C); } // HLSL constructor
postfix_expr(A) ::= postfix_expr(B) DOT IDENTIFIER(C). { A = new_binary_expr(ctx, OP_DEREF_STRUCT, B, new_identifier_expr(ctx, &C)); }
postfix_expr(A) ::= postfix_expr(B) DOT IDENTIFIER(C). { A = new_binary_expr(ctx, OP_DEREF_STRUCT, B, new_identifier_expr(ctx, C.string)); }
postfix_expr(A) ::= postfix_expr(B) PLUSPLUS. { A = new_unary_expr(ctx, OP_POSTINCREMENT, B); }
postfix_expr(A) ::= postfix_expr(B) MINUSMINUS. { A = new_unary_expr(ctx, OP_POSTDECREMENT, B); }

Expand Down

0 comments on commit 31af9ce

Please sign in to comment.