-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsemantic_analysis.nit
More file actions
41 lines (33 loc) · 825 Bytes
/
Copy pathsemantic_analysis.nit
File metadata and controls
41 lines (33 loc) · 825 Bytes
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
module semantic_analysis
import minilang_test_parser
class SemanticAnalysis
super Visitor
var methods = new ArrayMap[String, Int]
redef fun visit(n) do n.accept_semantic(self)
end
redef class Node
fun accept_semantic(v: SemanticAnalysis) do visit_children(v)
end
redef class Ndef
redef fun accept_semantic(v) do
if v.methods.has_key(n_id.text) then
print "Cannot redeclared method"
exit(1)
end
v.methods[n_id.text] = n_params.number_of_children
end
end
redef class Ncall
redef fun accept_semantic(v) do
super
if not v.methods.has_key(n_id.text) then
print "Method {n_id.text} was not declared"
exit(1)
end
var nb_arguments = n_arguments.number_of_children
if nb_arguments != v.methods[n_id.text] then
print "Method {n_id.text} signature does not match"
exit(1)
end
end
end