-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompiler.rb
More file actions
50 lines (38 loc) · 911 Bytes
/
Copy pathcompiler.rb
File metadata and controls
50 lines (38 loc) · 911 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
42
43
44
45
46
47
48
49
50
require_relative 'lexer/lexer'
require_relative 'parser/parser'
require_relative 'parser/ast_printer'
require_relative 'parser/check_scope'
require_relative 'parser/check_types'
require_relative 'parser/check_structure'
require_relative 'generator/generator'
require_relative 'virtual_machine'
input_file = ARGV[0]
output_file = ARGV[1]
if input_file == nil
puts "No input file specified."
exit
end
if output_file == nil
puts "No output file specified."
exit
end
lx = Lexer.new(input_file, false)
tokens = lx.get_tokens
ps = Parser.new(tokens)
root = ps.parse_program
#tp = AstPrinter.new
#tp.print('root', root)
root.check_scope
$error_found = false
root.check_types
root.check_structure(input_file)
if $error_found == true
exit
end
gen = Generator.new
root.generate(gen)
gen.write_to_file(output_file)
#gen.dump
strings = gen.strings
vm = VirtualMachine.new
vm.run(output_file, strings)