aboutsummaryrefslogtreecommitdiff
path: root/src/parser/Statement.hs
blob: cfeabe16038b40f5d64c2b4545e60fcbc9622c0f (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 <|> evaluationP <|> polynomEvaluationP
    where
        functionDeclarationP = FunctionDeclaration
                                    <$> funLabelP
                                    <*> parenthesis varLabelP
                                    <*> (char '=' *> exprP)

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

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

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