aboutsummaryrefslogtreecommitdiff
path: root/src/parser/Statement.hs
blob: 889f24f1a9ca1531da214c31b4d4ebc4a1e94922 (plain)
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
module Parser.Statement where

import           Control.Applicative

import           Expr
import           Parser.Core
import           Parser.Expr


data Statement
    = Evaluation Expr
    | PolynomEvaluation Expr Expr
    | VariableDeclaration String Expr
    | FunctionDeclaration String String Expr

statementP :: Parser Statement
statementP = functionDeclarationP <|> variableDeclarationP <|> polynomEvaluationP <|> evaluationP
    where
        functionDeclarationP = FunctionDeclaration
                                    <$> labelP
                                    <*> parenthesis labelP
                                    <*> (char '=' *> exprP)

        variableDeclarationP = VariableDeclaration
                                    <$> labelP
                                    <*> (char '=' *> exprP)

        polynomEvaluationP   = PolynomEvaluation <$>  exprP <*> (char '=' *> exprP <* char '?')

        evaluationP          = Evaluation <$> exprP <* char '=' <* char '?'