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!


Norman


============= UM Macro Assembler input grammar ============
  <comment> ::= from # or // to end-of-line
 <reserved> ::= if | a | goto | new | array | nand | xor
             |  inactivate | input | output | in | program | using
             |  off | here | halt | words | push | pop | on | off | stack
    <ident> ::= identifier as in C, except <reserved> or <reg>
    <label> ::= <ident>
      <reg> ::= rNN, where NN is any decimal number
        <k> ::= <hex-literal> | <decimal-literal> | <character-literal>
   <lvalue> ::= <reg> | a[<reg>][<rvalue>]
   <rvalue> ::= <reg> | a[<reg>][<rvalue>]
             |  <k> | <label> | <label> + <k> | <label> - <k>
    <relop> ::= != | == | <s | >s | <=s | >=s
    <binop> ::= + | - | * | / | nand | & | '|' | xor | mod
     <unop> ::= - | ~
    <instr> ::= <lvalue> := <rvalue>
             |  <lvalue> := <rvalue> <binop> <rvalue>
             |  <lvalue> := <unop> <rvalue>
             |  <lvalue> := new array (<rvalue> words)
             |  inactivate a[<reg>]
             |  <lvalue> := input()
             |  output <rvalue>
             |  output <string-literal>
             |  goto *<reg> in program a[<reg>]
             |  halt
             |  goto <rvalue> [linking <reg>]
             |  if (<rvalue> <relop> <rvalue>) <lvalue> := <rvalue>
             |  if (<rvalue> <relop> <rvalue>) goto <rvalue>
             |  push <rvalue> on  stack <reg>
             |  pop  <lvalue> off stack <reg>
<directive> ::= .section <ident>
             |  .data <label> [(+|-) <k>]
             |  .data <k>
             |  .space <k>
             |  .string <string-literal>
             |  .zero <reg> | .zero off               // identify zero register
             |  .temps <reg> {, <reg>} | .temps off   // temporary regs
     <line> ::= {<label>:} [<instr> [using <reg> {, <reg>}] | <directive>]
  <program> ::= {<line> (<comment> | newline | ;)}