theandrew168 / derzforth

Bare-metal Forth implementation for RISC-V
MIT License
42 stars 5 forks source link

Skip bounded comments (parens) #16

Closed aw closed 2 years ago

aw commented 2 years ago

Hi,

This PR adds the ability to skip bounded comments, ex:

: dup ( x -- x x ) sp@ @ ;
 ok

This will define the word dup and skip everything between ( and ). It's a bit naive and doesn't handle cases of nested parens.. so:

: dup ( x -- (x) x ) sp@ @ ; 

... would fail, not that anybody does that...

On the plus side, this makes it possible to easily copy/paste Forth code from existing implementations and libraries without having to manually remove the (comments).

This adds 20 bytes to the binary, but can probably be optimized a bit.

aw commented 2 years ago

hmm.. I tried but it fails:

line 285
  li t0, '('                           # bounded comments start with ( char
AssemblerError: invalid char literal in expr: "' ( '"
theandrew168 commented 2 years ago

Interesting... That might be an assembler bug for me to look into. Either way, this PR is good to go!