Let us begin with defining a language, a simple assembly language (invent
by Tawan). We show a sample of the code.
CLRA
MOV R1,100
MOV R2,200
ADD R1
ADD R2
MOVA R1
asm = op oprnd asm | EOF
op = CLRA | MOV | ADD | MOVA
oprnd = reg , num | reg | empty
reg = R[0..31]
return 0 - error, 1 - OK
reg()
match('R')
ret num()
op()
switch tokentype()
mov: match('MOV')
...
default: ret 0
oprnd()
if reg() != 0
if token == ',' //
lookahead
match(',')
ret num()
else
ret 1
ret 1
asm()
if token == EOF ret 1
if op() != 0
oprnd()
asm()
ret 0
I modify my rz33-1 compiler. I use its scanner which can accept lexemes of ASM easily. Then, I put ASM parser into work. Here is the whole package. Please try to compile and run it.
asm-parser-2.zip (bug fixed and clean up code, update 5 Sept 2017)Enjoy!
last update 5 Sept 2017