@@ -4,6 +4,7 @@ pub mod ast;
44mod constants;
55pub mod context;
66pub mod executer;
7+ pub mod lexer;
78pub mod parser;
89pub mod value;
910
@@ -95,22 +96,22 @@ mod tests {
9596 order_of_operations_negative_prefix: "-10 + 5" => -5. ,
9697 order_of_operations_add_multiply: "5+1*1+5" => 11. ,
9798 order_of_operations_add_negative_multiply: "5+(-1)*1+5" => 9. ,
98- order_of_operations_sqrt: "sqrt25 + 11" => 16. ,
99- order_of_operations_sqrt_expression: "sqrt(25+11)" => 6. ,
99+ order_of_operations_sqrt: "@sqrt(25) + 11" => 16. ,
100+ order_of_operations_sqrt_expression: "@ sqrt(25+11)" => 6. ,
100101
101102 // Parentheses and nested expressions
102103 parentheses_nested_multiply: "(5 + 3) * (2 + 6)" => 64. ,
103104 parentheses_mixed_operations: "2 * (3 + 5 * (2 + 1))" => 36. ,
104105 parentheses_divide_add_multiply: "10 / (2 + 3) + (7 * 2)" => 16. ,
105106
106107 // Square root and nested square root
107- sqrt_chain_operations: "sqrt(16) + sqrt(9) * sqrt(4)" => 10. ,
108- sqrt_nested: "sqrt(sqrt(81))" => 3. ,
109- sqrt_divide_expression: "sqrt((25 + 11) / 9)" => 2. ,
108+ sqrt_chain_operations: "@ sqrt(16) + @ sqrt(9) * @ sqrt(4)" => 10. ,
109+ sqrt_nested: "@ sqrt(@ sqrt(81))" => 3. ,
110+ sqrt_divide_expression: "@ sqrt((25 + 11) / 9)" => 2. ,
110111
111112 // Mixed square root and units
112- sqrt_add_multiply: "sqrt(49) - 1 + 2 * 3" => 12. ,
113- sqrt_addition_multiply: "(sqrt(36) + 2) * 2" => 16. ,
113+ sqrt_add_multiply: "@ sqrt(49) - 1 + 2 * 3" => 12. ,
114+ sqrt_addition_multiply: "(@ sqrt(36) + 2) * 2" => 16. ,
114115
115116 // Exponentiation
116117 exponent_single: "2^3" => 8. ,
@@ -119,10 +120,10 @@ mod tests {
119120
120121 // Operations with negative values
121122 negative_nested_parentheses: "-(5 + 3 * (2 - 1))" => -8. ,
122- negative_sqrt_addition: "-(sqrt(16) + sqrt(9))" => -7. ,
123- multiply_sqrt_subtract: "5 * 2 + sqrt(16) / 2 - 3" => 9. ,
124- add_multiply_subtract_sqrt: "4 + 3 * (2 + 1) - sqrt(25)" => 8. ,
125- add_sqrt_subtract_nested_multiply: "10 + sqrt(64) - (5 * (2 + 1))" => 3. ,
123+ negative_sqrt_addition: "-(@ sqrt(16) + @ sqrt(9))" => -7. ,
124+ multiply_sqrt_subtract: "5 * 2 + @ sqrt(16) / 2 - 3" => 9. ,
125+ add_multiply_subtract_sqrt: "4 + 3 * (2 + 1) - @ sqrt(25)" => 8. ,
126+ add_sqrt_subtract_nested_multiply: "10 + @ sqrt(64) - (5 * (2 + 1))" => 3. ,
126127
127128 // Mathematical constants
128129 constant_pi: "pi" => std:: f64 :: consts:: PI ,
@@ -138,47 +139,44 @@ mod tests {
138139 infinity_subtract_large_number: "inf - 1000" => f64 :: INFINITY ,
139140
140141 // Trigonometric functions
141- trig_sin_pi: "sin(pi)" => 0.0 ,
142- trig_cos_zero: "cos(0)" => 1.0 ,
143- trig_tan_pi_div_four: "tan(pi/4)" => 1.0 ,
144- trig_sin_tau: "sin(tau)" => 0.0 ,
145- trig_cos_tau_div_two: "cos(tau/2)" => -1.0 ,
142+ trig_sin_pi: "@ sin(pi)" => 0.0 ,
143+ trig_cos_zero: "@ cos(0)" => 1.0 ,
144+ trig_tan_pi_div_four: "@ tan(pi/4)" => 1.0 ,
145+ trig_sin_tau: "@ sin(tau)" => 0.0 ,
146+ trig_cos_tau_div_two: "@ cos(tau/2)" => -1.0 ,
146147
147148 // Basic if statements
148- if_true_condition: "if(1){5} else {3} " => 5. ,
149- if_false_condition: "if(0){5} else {3} " => 3. ,
149+ if_true_condition: "if(1,5,3) " => 5. ,
150+ if_false_condition: "if(0, 5, 3) " => 3. ,
150151
151152 // Arithmetic conditions
152- if_arithmetic_true: "if(2+2-4){1} else {0} " => 0. ,
153- if_arithmetic_false: "if(3*2-5){1} else {0} " => 1. ,
153+ if_arithmetic_true: "if(2+2-4, 1 , 0) " => 0. ,
154+ if_arithmetic_false: "if(3*2-5, 1, 0) " => 1. ,
154155
155156 // Nested arithmetic
156- if_complex_arithmetic: "if((5+3)*(2-1)){10} else {20} " => 10. ,
157- if_with_division: "if(8/4-2 == 0){15} else {25} " => 15. ,
157+ if_complex_arithmetic: "if((5+3)*(2-1), 10, 20) " => 10. ,
158+ if_with_division: "if(8/4-2 == 0,15, 25) " => 15. ,
158159
159160 // Constants in conditions
160- if_with_pi: "if(pi > 3){1} else {0} " => 1. ,
161- if_with_e: "if(e < 3){1} else {0} " => 1. ,
161+ if_with_pi: "if(pi > 3, 1, 0) " => 1. ,
162+ if_with_e: "if(e < 3, 1, 0) " => 1. ,
162163
163164 // Functions in conditions
164- if_with_sqrt: "if(sqrt(16) == 4){1} else {0} " => 1. ,
165- if_with_sin: "if(sin(pi) == 0.0){1} else {0} " => 0. ,
165+ if_with_sqrt: "if(@ sqrt(16) == 4, 1, 0) " => 1. ,
166+ if_with_sin: "if(@ sin(pi) == 0.0, 1, 0) " => 0. ,
166167
167168 // Nested if statements
168- nested_if: "if(1){ if(0){1} else {2}} else {3} " => 2. ,
169- nested_if_complex: "if(2-2 == 0){ if(1){5} else {6}} else { if(1){7} else {8}} " => 5. ,
169+ nested_if: "if(1, if(0, 1, 2), 3) " => 2. ,
170+ nested_if_complex: "if(2-2 == 0, if(1, 5, 6), if(1, 7, 8)) " => 5. ,
170171
171172 // Mixed operations in conditions and blocks
172- if_complex_condition: "if(sqrt(16) + sin(pi) < 5){ 2*pi} else { 3*e} " => 2. * std:: f64 :: consts:: PI ,
173- if_complex_blocks: "if(1){2* sqrt(16) + sin(pi/2)} else {3* cos(0) + 4} " => 9. ,
173+ if_complex_condition: "if(@ sqrt(16) + @ sin(pi) < 5, 2*pi, 3*e) " => 2. * std:: f64 :: consts:: PI ,
174+ if_complex_blocks: "if(1, 2*@ sqrt(16) + @ sin(pi/2), 3*@ cos(0) + 4) " => 9. ,
174175
175176 // Edge cases
176- if_zero: "if(0.0){1} else {2}" => 2. ,
177- if_negative: "if(-1){1} else {2}" => 1. ,
178- if_infinity: "if(inf){1} else {2}" => 1. ,
179-
177+ if_zero: "if(0.0, 1, 2)" => 2. ,
180178
181179 // Complex nested expressions
182- if_nested_expr: "if((sqrt(16) + 2) * (sin(pi) + 1)){ 3 + 4 * 2} else { 5 - 2 / 1} " => 11. ,
180+ if_nested_expr: "if((@ sqrt(16) + 2) * (@ sin(pi) + 1), 3 + 4 * 2, 5 - 2 / 1) " => 11. ,
183181 }
184182}
0 commit comments