This repository has been archived by the owner on Sep 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
nfs.fs
151 lines (104 loc) · 3.8 KB
/
nfs.fs
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
\ ==============================================================================
\
\ nfs - the non-deterministic finite automata state
\
\ Copyright (C) 2007 Dick van Oudheusden
\
\ This library is free software; you can redistribute it and/or
\ modify it under the terms of the GNU Lesser General Public
\ License as published by the Free Software Foundation; either
\ version 3 of the License, or (at your option) any later version.
\
\ This library is distributed in the hope that it will be useful,
\ but WITHOUT ANY WARRANTY; without even the implied warranty of
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\ Lesser General Public License for more details.
\
\ You should have received a copy of the GNU Lesser General Public
\ License along with this library; if not, write to the Free
\ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
\
\ ==============================================================================
\
\ $Date: 2007-12-09 07:23:16 $ $Revision: 1.6 $
\
\ ==============================================================================
include ffl/config.fs
[UNDEFINED] nfs.version [IF]
include ffl/stc.fs
( nfs = Non-deterministic finite automata state )
( The nfs module implements a state in a non-deterministic finite automata. )
1 constant nfs.version
( State structure )
begin-structure nfs% ( -- n = Get the required space for a nfs state )
field: nfs>id \ the state id
field: nfs>type \ the state type
field: nfs>data \ the state optional data
field: nfs>out1 \ the next state (during building also used as next pointer )
field: nfs>out2 \ the split state (during building also used as next pointer )
field: nfs>visit \ the visit number
end-structure
( State types )
1 constant nfs.char ( -- n = State type char, data = char )
2 constant nfs.any ( -- n = State type any, no data )
3 constant nfs.class ( -- n = State type class, data = chs )
4 constant nfs.lparen ( -- n = State type left paren, data = paren level )
5 constant nfs.rparen ( -- n = State type right paren, data = paren level )
6 constant nfs.split ( -- n = State type split, no data )
7 constant nfs.match ( -- n = State type match, no data )
( State creation, initialisation and destruction )
: nfs-init ( x n1 n2 nfs -- = Initialise the nfs state with data x, type n1 and id n2 )
>r
r@ nfs>id !
r@ nfs>type !
r@ nfs>data !
r@ nfs>out1 nil!
r@ nfs>out2 nil!
r> nfs>visit 0!
;
: nfs-new ( x n1 n2 -- nfs = Create a new nfs state on the heap with data x, type n1 and id n2 )
nfs% allocate throw >r r@ nfs-init r>
;
: nfs-free ( nfs -- = Free the state from the heap )
free throw
;
( Member words )
: nfs-id@ ( nfs -- n = Get the id of the state )
nfs>id @
;
: nfs-type@ ( nfs -- n = Get the type of the state )
nfs>type @
;
: nfs-data@ ( nfs -- x = Get the optional data of the state )
nfs>data @
;
: nfs-out1! ( nfs1 nfs2 -- = Set out1 in the nfs2 state to the nfs1 state )
nfs>out1 !
;
: nfs-out1@ ( nfs1 -- nfs2 = Get the out1 state of the nfs1 state )
nfs>out1 @
;
: nfs-out2! ( nfs1 nfs2 -- = Set out2 in the nfs2 state to the nfs1 state )
nfs>out2 !
;
: nfs-out2@ ( nfs1 -- nfs2 = Get the out2 nfs state of nfs1 state )
nfs>out2 @
;
: nfs-visit! ( n nfs -- = Set the visit number [0>=] )
nfs>visit !
;
: nfs-visit@ ( nfs -- n = Get the visit number )
nfs>visit @
;
( Inspection )
: nfs-dump ( nfs -- = Dump the nfs state )
." nfs:" dup . cr
." id :" dup nfs>id ? cr
." type :" dup nfs>type ? cr
." data :" dup nfs>data ? cr
." out1 :" dup nfs>out1 ? cr
." out2 :" dup nfs>out2 ? cr
." visit:" nfs>visit ? cr
;
[THEN]
\ ==============================================================================