Arithmetic evaluation: Difference between revisions

Content added Content deleted
(Linkified terminology I'm unfamiliar with. Would someone care to fill them in?)
(Reverted terminology to binary relations, with Wikipedia link ("dyadic infix operators" is accurate, but less standard))
Line 1: Line 1:
{{task}}
{{task}}
Create a program which parses and evaluates arithmetic expressions. Requirements: an [[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 expression will be a string or list of symbols like "(1+3)*7". The four symbols + - * / must be supported as [[dyadic infix]] operators with conventional precedence rules. Precedence-control parentheses must also be supported.
Create a program which parses and evaluates arithmetic expressions. Requirements: an [[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 expression will be a string or list of symbols like "(1+3)*7". The four symbols + - * / must be supported as [http://en.wikipedia.org/wiki/Binary_relation binary relations] with conventional precedence rules. Precedence-control parentheses must also be supported.


For those who don't remember, mathematical precedence is as follows:
For those who don't remember, mathematical precedence is as follows: