v80 icon indicating copy to clipboard operation
v80 copied to clipboard

Parser v2?

Open Kroc opened this issue 1 year ago • 5 comments

It has occurred to me that another method of parsing would be to use a straight jump table from ASCII code to routine. Since the order of tokens would no longer be enforced by code order (i.e. a value must follow a unary operator), there would instead be a "mode" variable that would describe the context for each routine arrived at. For example, if an operator is encountered but the mode says we're not in an expression, then we throw an error.

There are a number of cons:

  • The parsing flow is much harder to follow
  • One token is not connected to another by code flow meaning that register pressure may increase
  • A mode value needs to be persisted and this may be difficult to pin to a register (as above)
  • the ASCII jump table will take ~192-256 bytes

However there are some pros:

  • Less code is required to express parsing; may actually save bytes
  • Less code also means less code to port for other architectures, such as porting v80 to 6502 (v65?)
  • Less coupling of routines, easier to make improvements without knock-on effects

Kroc avatar Feb 22 '24 13:02 Kroc