Семантический анализатор. Нетестченный

 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
/* SemanticAnalysis(errorList 'tree to analyse' 'tree to compare') */
SemanticAnalysis {
myErorList ((functionName mode pos: eFunctionBody) : eOtherFunctions) tree =
< SemanticAnalysis
<AnalyseFunction myErorList eFunctionBody tree>
eOtherFunctions
tree
>;
myErorList (otherElem : eOtherFunctions) tree =
<SemanticAnalysis myErorList eOtherFunctions tree>;
myErrorList () tree =
myErrorList
}
AnalyseFunction {
myErorList ((pattern result) :eOtherSentences) tree =
<AnalyseFunction
<CheckVariable myErorList pattern result tree>
eOtherSentences
tree
>;
myErorList () tree = myErorList;
}
/* CheckVariables(errorList pattern result tree) */
CheckVariable {
myErorList pattern ((Variable pos :eName) :eTali) tree =
<CheckVariable
<CheckPattern myErorList pattern (Variable pos :eName) tree>
pattern
eTali
tree
>;
myErorList pattern ((BRACKETS :eBody) :eTali) tree =
<CheckVariable
<CheckVariable myErorList pattern (BRACKETS :eBody) tree>
pattern
eTali
tree
>;
myErorList pattern ((CALL :eBody) :eTali) tree =
<CheckVariable
<CheckVariable myErorList pattern (CALL :eBody) tree>
pattern
eTali
tree
>;
myErorList pattern (otherToken :eTali) tree =
<CheckVariable myErorList pattern eTali tree>;
}
/* CheckPattern(errorList pattern variable tree) */
CheckPattern {
myErorList ((Variable pos :eName) :eTali) (Variable pos :eName) tree
= myErorList;
myErorList (CALL functionName :eTali) (Variable pos :eName) tree =
<CheckPattern
<CheckFunction myErorList functionName tree>
eTali
(Variable pos :eName)
tree
>;
myErorList ((BRACKETS :eBody) :eTali) (Variable pos :eName) tree =
<CheckPattern
<CheckPattern myErorList (BRACKETS :eBody) (Variable pos :eName) tree>
eTali
(Variable pos :eName)
tree
>;
myErorList (otherToken :eTali) (Variable pos :eName) tree =
<CheckPattern
myErorList
eTali
(Variable pos :eName)
tree
>;
myErorList () (Variable pos :eName) tree =
<AddUnexpectedToken myErorList (Variable pos :eName) 'undeclared variable in result on pos'>;
}
/* FunctionName (errorList (functionName) tree) */
CheckFunction {
myErorList functionName (( functionName : eFunctionBody ) : eFunctions) =
myErorList;
myErorList functionName (( otherName : eFunctionBody ) : eFunctions) =
<CheckFunction myErorList functionName eFunctions>;
myErorList functionName (term : eFunctions) =
<CheckFunction myErorList functionName eFunctions>;
myErorList functionName () =
<AddUnexpectedToken myErorList functionName 'undeclared function on pos'>;
}