Arithmetic evaluation: Difference between revisions

Content added Content deleted
(→‎{{header|TXR}}: New implementation with AST construction and evaluation.)
(Add links.)
Line 2: Line 2:
Create a program which parses and evaluates arithmetic expressions.
Create a program which parses and evaluates arithmetic expressions.


'''Requirements:'''
;Requirements:
* An [[wp:Abstract_syntax_tree|abstract-syntax tree]] (AST) for the expression must be created from parsing the input.
* An [[wp:Abstract_syntax_tree|abstract-syntax tree]] (AST) for the expression must be created from parsing the input.
* The AST must be used in evaluation, also, so the input may not be directly evaluated (e.g. by calling eval or a similar language feature.)
* The AST must be used in evaluation, also, so the input may not be directly evaluated (e.g. by calling eval or a similar language feature.)
Line 9: Line 9:
* Precedence-control parentheses must also be supported.
* Precedence-control parentheses must also be supported.


;Note:
Note: For those who don't remember, mathematical precedence is as follows:
For those who don't remember, mathematical precedence is as follows:
* Parentheses
* Parentheses
* Multiplication/Division (left to right)
* Multiplication/Division (left to right)
* Addition/Subtraction (left to right)
* Addition/Subtraction (left to right)



C.f: [[24 game Player]]
;C.f:
* [[24 game Player]].
* [[Parsing/RPN calculator algorithm]].
* [[Parsing/RPN to infix conversion]].


=={{header|Ada}}==
=={{header|Ada}}==