summaryrefslogtreecommitdiff
path: root/src/services/quick-answers/math-parser.c
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2024-07-03 19:07:45 +0200
committerHannes Schulze <haschu0103@outlook.de>2024-07-03 19:07:45 +0200
commit6967d26dd1841965a6e979897e282dd66e45ef5f (patch)
tree15dcee051e77866f174091478cd061b18e05546b /src/services/quick-answers/math-parser.c
parent40939b3ebe359b19cc4ee1d9a7b831fada71ce75 (diff)
implement expression evaluation
Diffstat (limited to 'src/services/quick-answers/math-parser.c')
-rw-r--r--src/services/quick-answers/math-parser.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/services/quick-answers/math-parser.c b/src/services/quick-answers/math-parser.c
index bb94a66..7f93552 100644
--- a/src/services/quick-answers/math-parser.c
+++ b/src/services/quick-answers/math-parser.c
@@ -104,7 +104,7 @@ FoobarMathExpression* parser_process(
next_op = parser_peek( ctx );
}
- lhs = foobar_math_expression_operation( parser_operator( op ), lhs, rhs );
+ lhs = foobar_math_expression_new_operation( parser_operator( op ), lhs, rhs );
op = parser_peek( ctx );
op_precedence = parser_operator_precedence( op );
@@ -148,11 +148,11 @@ FoobarMathExpression* parser_process_identifier( Parser* ctx )
FoobarMathToken const* token = parser_pop( ctx );
if ( parser_match_identifier( token, "pi" ) )
{
- return foobar_math_expression_constant( FOOBAR_MATH_CONSTANT_PI );
+ return foobar_math_expression_new_constant( FOOBAR_MATH_CONSTANT_PI );
}
else if ( parser_match_identifier( token, "e" ) )
{
- return foobar_math_expression_constant( FOOBAR_MATH_CONSTANT_E );
+ return foobar_math_expression_new_constant( FOOBAR_MATH_CONSTANT_E );
}
else if ( parser_match_identifier( token, "exp" ) )
{
@@ -219,13 +219,13 @@ FoobarMathExpression* parser_process_identifier( Parser* ctx )
FoobarMathExpression* parser_process_number( Parser* ctx )
{
FoobarMathToken const* token = parser_pop( ctx );
- FoobarMathValue value;
+ FoobarMathValue value = { 0 };
if ( !foobar_math_value_from_string( token->data, token->length, &value ) )
{
return NULL;
}
- return foobar_math_expression_value( value );
+ return foobar_math_expression_new_value( value );
}
FoobarMathExpression* parser_process_function(
@@ -241,7 +241,7 @@ FoobarMathExpression* parser_process_function(
FoobarMathExpression* arg = parser_process_parens( ctx );
if ( !arg ) { return NULL; }
- return foobar_math_expression_function( function, arg );
+ return foobar_math_expression_new_function( function, arg );
}
FoobarMathExpression* parser_process_parens( Parser* ctx )
@@ -268,7 +268,7 @@ FoobarMathExpression* parser_process_sign( Parser* ctx )
if ( token->type == FOOBAR_MATH_TOKEN_MINUS )
{
- return foobar_math_expression_function( FOOBAR_MATH_FUNCTION_NEGATE, result );
+ return foobar_math_expression_new_function( FOOBAR_MATH_FUNCTION_NEGATE, result );
}
else
{