019f8fd211
git-subtree-dir: users/wpcarro git-subtree-mainline:464bbcb15c
git-subtree-split:24f5a642af
Change-Id: I6105b3762b79126b3488359c95978cadb3efa789
39 lines
739 B
Haskell
39 lines
739 B
Haskell
module Evaluator where
|
|
|
|
data Token
|
|
= TokenInt Integer
|
|
| TokenAdd
|
|
| TokenMultiply
|
|
deriving (Eq, Show)
|
|
|
|
newtype AST = AST [Token]
|
|
deriving (Eq, Show)
|
|
|
|
tokens :: [Token]
|
|
tokens =
|
|
[ TokenInt 13
|
|
, TokenAdd
|
|
, TokenInt 2
|
|
, TokenMultiply
|
|
, TokenInt 4
|
|
, TokenAdd
|
|
, TokenInt 7
|
|
, TokenAdd
|
|
, TokenInt 3
|
|
, TokenMultiply
|
|
, TokenInt 8
|
|
]
|
|
|
|
-- expression -> addition ;
|
|
-- addition -> multiplication ( "+" multiplication )* ;
|
|
-- multiplication -> terminal ( "*" terminal )* ;
|
|
-- terminal -> NUMBER ;
|
|
|
|
parseExpression :: [Token] -> ([Token], AST)
|
|
parseExpression tokens = do
|
|
lhs, rest = parseMultiplication tokens
|
|
|
|
parseMulitplication :: [Token] -> ([Token], AST)
|
|
|
|
main :: IO ()
|
|
main = print $ parse tokens
|