penny-lib-0.4.0.0: Extensible double-entry accounting system - library

Safe HaskellSafe-Infered

Penny.Liberty.Expressions.Infix

Description

Creates RPN expressions from infix inputs.

Penny accepts only infix expressions, but RPN expressions are easier to process. This module converts infix expressions to RPN expressions for further processing.

Uses the shunting-yard algorithm, best described at http:www.chris-j.co.uk/parsing.php (be sure to use the "click to display" links).

Synopsis

Documentation

newtype Precedence Source

Precedence can be any integer; the greater the number, the higher the precedence.

Constructors

Precedence Int 

data Associativity Source

Constructors

ALeft 
ARight 

Instances

data Token a Source

Instances

Show a => Show (Token a) 

infixToRPNSource

Arguments

:: Foldable l 
=> l (Token a)

Input tokens. These should be in the sequence from left to right in ordinary infix order. The easiest choice is a list, though you might want to use Data.Sequence if many appends will be needed to build the sequence.

-> Maybe (Seq (Token a))

The resulting RPN expression. The token type here is a token from Penny.Liberty.Expressions.RPN, which is a different type than the Token in this module. Fails only if there is a close parenthesis without a matching open parenthesis, or if there is an open parenthesis without a matching close parenthesis. Other nonsensical expressions will still parse to an RPN expression successfully, so the RPN parser has to catch these errors.

Converts an infix expression to an RPN expression.