lua-users home
lua-l archive

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

> I'm writing an LPEG grammar for moderately simple assembly language.
> Unfortunately the very last instruction results in an LPEG
> error: my pattern is too big!  Apparently Roberto is using
> 16-bit signed integers to count offsets in the abstract machine,
> so my pattern is limited to 32K elements.   I'm probably doing
> lots of stupid things, but it sure is annoying because my
> grammar (appended) is not that big.
> Any hints on how to reduce the number of elements in an LPEG pattern?
> I'm not even sure what 'elements' are at the source level...
> and I doubt anybody wants to read my 800-line assembler!
> The grammar is below; all hints are welcome!

Usually the easiest way to reduce the size of a grammar is to change some
pattern that is used in many places to a rule. For instance, we may
have defined spaces like this:

Sp = lpeg.Set" \t\n" + '--' * (1 - lpeg.P"\n")^0

Then, each use of 'Sp' will repeat the opcode for that pattern (some dozens
of opcodes). Instead, we may change it to this:

Sp = lpeg.V"Sp"

And include the definition for rule "Sp" in the final grammar. This will
add just one copy of the space pattern into the final pattern.

(But I will try to remove this limit in some future version. Several
people have problems with it...)

-- Roberto