haskellator-0.1.0.0: SI-Units supporting calculator
Safe HaskellSafe-Inferred
LanguageHaskell2010

Math.Haskellator.Internal.Parser

Description

Parse a token stream to an expression tree

Examples:

>>> parse [Number 1.0,Operator "+",Number 2.0]
Right (1.0 + 2.0)
>>> parse [OpenParen,Number 3.0,Operator "/",Number 2.0,Operator "+",OpenParen,Number 1.5,Operator "*",Number 2.0,CloseParen,CloseParen,Operator "+",Number 4.95]
Right (((3.0 / 2.0) + (1.5 * 2.0)) + 4.95)
>>> parse [Number 9001.0,Operator "*",Number 29.12]
Right (9001.0 * 29.12)
>>> parse [Number 2.0,Identifier "km",OpenBracket,Identifier "m",CloseBracket]
Right 2.0 km[m]
>>> parse [Identifier "a",Equal,Number 3.0,Comma,Identifier "b",Equal,Number 2.0,Arrow,Identifier "a",Operator "+",Identifier "b"]
Right (a = 3.0, b = 2.0 -> (a + b))
>>> parse [Number 2.0,Operator "*",OpenParen,Number 3,Operator "+",Number 4,CloseParen,Operator "/", Number 7.0]
Right ((2.0 * (3.0 + 4.0)) / 7.0)
>>> parse [Number 2.0,OpenParen,Number 3,Operator "+",Number 4,CloseParen,Operator "/", Number 7.0]
Right ((2.0 * (3.0 + 4.0)) / 7.0)
Synopsis

Documentation

parse Source #

Arguments

:: Tokens

input token stream

-> Either Error Expr

the parsed expression tree or an error

Parse a token stream to an expression tree