about summary refs log blame commit diff
path: root/users/wpcarro/scratch/facebook/evaluator.hs
blob: 1ba46a75489290cdf153dc7c4fa5e74a342d7b8f (plain) (tree)






































                                                             
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