about summary refs log tree commit diff
path: root/users/wpcarro/scratch/facebook/evaluator.hs
blob: 1ba46a75489290cdf153dc7c4fa5e74a342d7b8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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