tvl-depot/users/wpcarro/scratch/facebook/evaluator.hs
Vincent Ambo 019f8fd211 subtree(users/wpcarro): docking briefcase at '24f5a642'
git-subtree-dir: users/wpcarro
git-subtree-mainline: 464bbcb15c
git-subtree-split: 24f5a642af
Change-Id: I6105b3762b79126b3488359c95978cadb3efa789
2021-12-14 02:15:47 +03:00

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