public
Description: Simple fuzzy logic inference for control
Homepage:
Clone URL: git://github.com/khigia/ocaml-fuzlog.git
ocaml-fuzlog / fuzlog / parser.mly
100644 116 lines (92 sloc) 1.348 kb
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
%{
open Ast
 
%}
 
%token IF THEN
%token IS
%token AND
%token SEP
%token DEF
%token OPENB CLOSEB
%token OPENSB CLOSESB
%token EOF
%token <string> SYMB
%token <string> NUMBER
 
%start rules vocabulary
%type <Ast.rule_t list> rules
%type <Ast.def_t list> vocabulary
 
%%
 
/* TODO parse a vocabulary section */
 
rules:
    rules_ { List.rev $1 }
 
rules_:
    rule
        { [ $1 ] }
    | rules_ rule
        { $2 :: $1 }
 
rule:
    IF is_branch THEN is_branch
        { Imply($2, $4) }
;
 
is_branch:
    is
        { $1 }
    | is_branch AND is
        { And($1, $3) }
;
 
is:
    symb IS symb
        { Is($1, $3) }
;
 
vocabulary:
    vocabulary_
        { List.rev $1 }
;
 
vocabulary_:
    def
        { [ $1 ] }
    | vocabulary_ def
        { $2 :: $1 }
;
 
def:
    DEF symb vocfun numbers
        { DefByFun($2, $3, $4) }
    | DEF symb OPENSB points CLOSESB
        { DefByPoints($2, $4) }
;
 
vocfun:
    symb
        { $1 }
;
 
points:
    points_
        { List.rev $1 }
;
 
points_:
    point
        { [ $1 ] }
    | points_ point
        { $2 :: $1 }
;
 
point:
    OPENB number number CLOSEB
        { ($2, $3) }
;
 
numbers:
    numbers_
        { List.rev $1 }
;
 
numbers_:
    number
        { [ $1 ] }
    | numbers_ number
        { $2 :: $1 }
;
 
number:
    NUMBER
        { float_of_string $1 }
;
 
symb:
    SYMB
        { Symb $1 }
;
 
%%