Parser.y 1.82 KB
Newer Older
pm3g19's avatar
pm3g19 committed
1
2
3
4
{
module Parser where
import Lexer
}
5

pm3g19's avatar
pm3g19 committed
6
7
8
%name parseCalc
%tokentype  {Token}
%error      {parseError}
pm3g19's avatar
pm3g19 committed
9

pm3g19's avatar
pm3g19 committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
%token
	filter          { TokenFilter }
	in              { TokenInSet    }
    out             { TokenOutSet   }
	Setname         { TokenSetName $$ }
	function        { TokenFunc }
	nat             { TokenNat $$ }
	var             { TokenVarName $$ }
	Record          { TokenRecord }
	true            { TokenTrue }
	false           { TokenFalse }
	string          { TokenString s }
	'['             { TokenLeftSqBracket }
	']'             { TokenRightSqBracket }
	"->"            { TokenArrow }
	"=="            { TokenisEqual }
	"/="            { TokenisNotEqual }
	'('             { TokenLeftBracket }
	')'             { TokenRightBracket }
	';'             { TokenSemiCo }
	'\\'            { TokenLambda }
	','             { TokenComma  }
	'.'             { TokenFullstop }
pm3g19's avatar
pm3g19 committed
33

pm3g19's avatar
pm3g19 committed
34
35
36
37
38
39
40
41
42
43
44
45
46
%right "->"
%left "/=" "==" ';'
%%


Prog : '.' in SetNames '.' out SetFuncCall {($3,$6)}

SetNames : Setname                 {[$1]}
         | SetNames ',' setName    { }


VarNames : var                   {Var $1}
         | var ',' VarNames      {Var $1 $3}
47
48

SetSetFuncCalls : SetFuncCall    {[SetFuncCall]}
pm3g19's avatar
pm3g19 committed
49
                | SetFuncCall; SetFuncCalls   {SetFuncCall:SetFuncCalls}
50

pm3g19's avatar
pm3g19 committed
51
SetFuncCall : filter '['SetName']' '('Func')' {FuncCall (PredefFunc Filter) [$3] [$6]}
pm3g19's avatar
pm3g19 committed
52

pm3g19's avatar
pm3g19 committed
53
Func : \'('VarNames')' -> Expr {FuncDef [] $3 $6}
54
55


pm3g19's avatar
pm3g19 committed
56
57
58
59
Exp : '.' in var '.' out Exp   {Prog $3 $6}
    | filter '[' Setname ']' Exp {Filter $3 $5}
    | '(' '\\'

pm3g19's avatar
pm3g19 committed
60
Expr : Expr == Expr {FuncCall (PredefFunc IsEqual) [] [$1, $3]}
pm3g19's avatar
pm3g19 committed
61
62
63
64
65
66
     | Expr'['Nat']' {FuncCall (PredefFunc RecordIndex) [] [$3]}
     | String {String $1}
     | VarName {Var $1}
     | Record {$1}
     | true  {Boolean True}
     | false {Boolean False}
mnay1u19's avatar
mnay1u19 committed
67

pm3g19's avatar
pm3g19 committed
68
69
Record : '['Exprs']' {Record $2}
Exprs : Expr    {[$1]}
pm3g19's avatar
pm3g19 committed
70
71
72
73
74
      | Expr','Exprs  {$1:$2}

{

}