Safe Haskell | Safe-Infered |
---|
Penny.Liberty.Expressions.RPN
Description
Parses reverse polish notation expressions. This module needs much better error messages (right now it has none).
An RPN expression consists of operands and operators; a token is
either an operand or an operator. For example, in the expression 5
4 +
, the 5
and the 4
are operands; the +
is an operator;
each of these three is a token.
Documentation
An operand; for example, in the expression 5 4 +
, 5
and 4
are operands.
Constructors
Operand a |
Operators; for example, in the expression 5 4 +
, +
is an
operator. Because this is RPN, there is no operator precedence.
A token is either an operator or an operand.
Constructors
TokOperand (Operand a) | |
TokOperator (Operator a) |
Arguments
:: Foldable l | |
=> l (Token a) | The tokens must be in the sequence from left to right in
postfix order; for example, |
-> Maybe a | Fails if there is not exactly one operand remaining on the stack at the end of the parse, or if at any time there are insufficient operands on the stack to parse an operator. Otherwise, succeeds and returns the result. |
Processes an entire input sequence of RPN tokens.