INCLUDE now reads lib.4th up to first nested INCLUDE.
[forth.jl.git] / src / lib_3_comments.4th
1 \ Parenthetic comments
2
3 : ( IMMEDIATE
4         1               \ allowed nested parens by keeping track of depth
5         BEGIN
6                 >IN @ #TIB @ >= IF      \ End of TIB?
7                         QUERY       \ Get next line
8                 THEN
9
10                 TIB >IN @ + @ 1 >IN +!
11                 DUP [CHAR] ( = IF    \ open paren?
12                         DROP            \ drop the open paren
13                         1+              \ depth increases
14                 ELSE
15                         [CHAR] ) = IF        \ close paren?
16                                 1-              \ depth decreases
17                         THEN
18                 THEN
19         DUP 0= UNTIL            \ continue until we reach matching close paren, depth 0
20         DROP            \ drop the depth counter
21 ;
22