blob: 63fcd08ad32b35fd103ffa78b62a041202fc70d9 (
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
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
|
(**
This module describe the type an analyzer must implement in order to be
used with the parser.
The module is divided in three modules :
- Expression : the finest part of the QSP syntax.
- Instruction : if/act block,
- Location
All the elements of the syntax are represented with a dedicated function
(instead of a big sum type). The module [Tree] provide an implementation
which build the AST.
*)
type pos = Lexing.position * Lexing.position
type ('a, 'b) variable = { pos : 'a; name : string; index : 'b option }
(** Represent the evaluation over an expression *)
module type Expression = sig
type 'a obs
type repr
type variable = { pos : pos; name : string; index : repr option }
(**
Describe a variable, using the name in capitalized text, and an optionnal
index.
If missing, the index should be considered as [0].
*)
val ident : variable -> repr
(*
Basic values, text, number…
*)
val integer : pos -> string -> repr
val literal : pos -> string -> repr
val function_ : pos -> T.function_ -> repr list -> repr
(** Call a function. The functions list is hardcoded in lib/lexer.mll *)
val uoperator : pos -> T.uoperator -> repr -> repr
(** Unary operator like [-123] or [+'Text']*)
val boperator : pos -> T.boperator -> repr -> repr -> repr
(** Binary operator, for a comparaison, or an operation *)
end
module type Instruction = sig
type repr
type expression
type variable
val call : pos -> T.keywords -> expression list -> repr
(** Call for an instruction like [GT] or [*CLR] *)
val location : pos -> string -> repr
(** Label for a loop *)
val comment : pos -> repr
(** Comment *)
val expression : expression -> repr
(** Raw expression *)
type clause = pos * expression * repr list
val if_ : pos -> clause -> elifs:clause list -> else_:repr list -> repr
val act : pos -> label:expression -> repr list -> repr
val assign : pos -> variable -> T.assignation_operator -> expression -> repr
end
module type Location = sig
type repr
type instruction
val location : pos -> instruction list -> repr
end
module type Analyzer = sig
module Expression : Expression
module Instruction :
Instruction
with type expression = Expression.repr
and type variable = Expression.variable
module Location : Location with type instruction = Instruction.repr
end
|