-
Notifications
You must be signed in to change notification settings - Fork 0
/
CCasm.lua
46 lines (42 loc) · 933 Bytes
/
CCasm.lua
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
local lex = require "CCasm.Lexer.lex"
local Token = require "CCasm.Lexer.Token"
local parse = require "CCasm.Parser.parse"
register = {
--[[ General Purpose Registers ]]--
['a'] = Token('NULL'),
['b'] = Token('NULL'),
['c'] = Token('NULL'),
['d'] = Token('NULL'),
['e'] = Token('NULL'),
--[[ Instruction Pointer ]]--
['ip'] = 1,
}
stack = {}
labels = {}
macros = {}
local args = {...}
if #args > 1 then
error("Usage: CCasm [path]", 0)
end
_G.report = function(line, message)
error('[Line: ' .. line .. '] Error: ' .. message .. '\n', 0)
end
local function repl()
while true do
write(">: ")
local input = read()
register['ip'] = 1
parse( lex(input) )
end
end
local function run_file()
local asm = fs.open(args[1], 'r')
local code = asm.readAll()
asm.close()
parse( lex(code) )
end
if #args == 0 then
repl()
else
run_file()
end