-
Notifications
You must be signed in to change notification settings - Fork 3
/
BNF.h4
32 lines (30 loc) · 1.08 KB
/
BNF.h4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| BNF parser for HelFORTH
| -----------------------------------------------------------
| Author: Helmar Wodtke
| Year: 2005
|
context bnf~
enter bnf~
variable tp
variable success
doer @token make @token tp @ c@ ;
doer +token make +token 1 tp +! ;
: success? success @ ;
: {{ ['] success? compile x: if ; immediate
: }} x: then ; immediate
: back rdrop r> tp ! ;
: <bnf {{ tp @ >rr ;; }} rdrop ;
: bnf> {{ rdrop ;; }} back [ $c3 1,
: || {{ rdrop rdrop ;; }} rr tp ! success on ;
: ?? {{ rr> drop <bnf ;; }} success on back ;
: && {{ rr> drop <bnf ;; }} back ;
: <nest {{ r> dup @ >r tp @ >r cell+ >r ;; }} back ;
: (( ['] <nest compile here 0 , ; immediate
: ;bnf ['] bnf> compile x: ; ; immediate
: )) x: ;bnf ] here swap ! ; immediate
: token constant
does> {{ @token =if +token ;;
then success off ;; }} drop back ;
: bnf: : ['] <bnf compile ;
;enter
| -------------------------------------------------------------