lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 2/17/2023 7:18 PM, Luiz Henrique de Figueiredo wrote:
Can we please go back to discussing Lua? Thanks.

I have done project 1-1, more or less, in the book /Assemblers and
Loaders/ [1] in Lua.  It was a bit unusual for me to create data
structures out of Lua tables, but once the initial hurdles were over
and I had figured out binary output, it turned out to be rather easy.

It turns the example input of

	STO 50
	STO 51
	ADD 50
X	LOD 50
	ADD 50
Y	STO 52


00000000: 7000 2032 7000 2033 400d 3032 8000 6011  p. 2p. 3@.02..`.
00000010: 1032 3032 2034 0000                      .202 4..

with the 2pass assembler.  As per the book, I changed the binary
format slightly between the 1pass and 2pass assemblers. [2]

Parsing is something I did with a line by line reader, and
string.match(), which works fine for a very rigid syntax.  Later
on, I'm pretty sure I'll have to resort to something more flexible
like recursive descent or something.


[2] I may have misunderstood the project a bit, and done binary
output when I strictly didn't have to, but I found it a bit more
fun that way.