-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmicrocom.rb
executable file
·47 lines (38 loc) · 1.19 KB
/
microcom.rb
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
# Chris Durtschi
# CS 4820
# David Hart
# MicroCom - Main Driver
require 'microcom/lexical_scanner'
require 'microcom/syntactical_parser'
require 'microcom/semantical_phase'
require 'microcom/precedence_table'
require 'microcom/code_generator'
puts "Enter .mic file, with or without extension:"
path = gets.chomp
mic_path = path
mic_path += '.mic' if !mic_path.match(/^\w+\.mic$/)
lis_path = mic_path.gsub('.mic', '.lis')
lex_path = mic_path.gsub('.mic', '.lex')
sem_path = mic_path.gsub('.mic', '.sem')
tas_path = mic_path.gsub('.mic', '.tas')
if (!File.exist?(mic_path))
puts "File does not exist: #{mic_path}"
exit
end
symbol_table = []
int_literal_table = []
lexemes = []
atoms = []
scanner = LexicalScanner.new(mic_path, lex_path, lis_path, lexemes,
symbol_table, int_literal_table)
if scanner.scan
parser = SyntacticalParser.new(lex_path, lis_path, lexemes)
if parser.parse
semantic = SemanticalPhase.new(sem_path, lis_path, lexemes, atoms,
symbol_table, int_literal_table)
semantic.run
generator = CodeGenerator.new(lis_path, tas_path, atoms, symbol_table,
int_literal_table)
generator.generate
end
end