lua-users home
lua-l archive

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




On 2019-03-27 9:03 p.m., Sean Conner wrote:
It was thus said that the Great Soni They/Them L. once stated:
I'm rolling with this weird idea. is it possible to make a simple parser
out of tables?
   Yes.  There's an entire book dedicated to this topic---_Compilers:
Principles, Techniques, and Tools_, [1] also known as The Dragon Book
(because of the cover).  It doesn't use Lua tables per se, but the lexing
portion is driven completely by a 2D array that represents a state machine.

   The other book I'm familiar with is _Compiler Design in C_ [2].  It too,
uses a table to drive the lexing.

I tried some stuff but ran into a few issues. I don't
wanna use LPeg or anything more complicated than string.find(foo, bar,
1, true).
   You might be better off learning LPEG.

It's not that I don't know LPEG (I could make an LPEG re for it in uh, maybe an hour at most. no need to write something to parse the table structures and stuff).

I just can't use it.

(besides, this is a lot cuter than an LPEG re IMO)


   -spc (But that's just my opinion)

[1]	https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools

[2]	https://holub.com/compiler/