Skip to content

Instantly share code, notes, and snippets.

@ruv

ruv/missing.fth Secret

Last active November 12, 2024 09:46
Show Gist options
  • Save ruv/84f8ff1a7c761dba030e11cecea9d283 to your computer and use it in GitHub Desktop.
Save ruv/84f8ff1a7c761dba030e11cecea9d283 to your computer and use it in GitHub Desktop.
A conceptual implementation for the word `missing(`
[undefined] parse-lexeme [if]
synonym parse-lexeme parse-name
[then]
[undefined] tt-xt [undefined] tt-sd [undefined] tt-x or or [if]
include https://github.com/ForthHub/fep-recognizer/blob/master/implementation/index.lib-compat.fth
include https://github.com/ForthHub/fep-recognizer/blob/master/implementation/variant.gamma/token-translator.fth
[then]
: extract-lexeme ( -- sd.lexeme | 0 0 )
begin parse-lexeme dup if exit then 2drop refill 0= until 0 0
;
: extract-lexeme-sure ( -- sd.lexeme )
extract-lexeme dup if exit then -39 throw \ "unexpected end of the input source"
;
-81 constant exception-word-missing
: missing ( sd.name -- -81 | 0 )
\ This implementation is for testing purposes only
forth-wordlist search-wordlist if drop 0 exit then exception-word-missing
;
: missing( ( compil: true ; "ccc <rparen> " -- | compil: false ; "ccc <rparen> " -- -81|0 )
0 tt-x
begin extract-lexeme-sure
2dup s" )" compare \ the lexeme is not equal to ")"
while ( sd.lexeme )
tt-sd [: missing or ;] tt-xt
repeat 2drop
; immediate
@ruv
Copy link
Author

ruv commented Nov 12, 2024

A link to the implementation for Recognizer API:
https://github.com/ForthHub/fep-recognizer/tree/master/implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment