X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=src%2Flib_4_comments.4th;fp=src%2Flib_4_comments.4th;h=1c0be393830095e8382b3f5111867eb6a3437f13;hb=30a093845e2d1097242e948bb577fb71f73bc860;hp=0000000000000000000000000000000000000000;hpb=c52194127d604bd365f7222936b46f34f62a4814;p=forth.jl.git diff --git a/src/lib_4_comments.4th b/src/lib_4_comments.4th new file mode 100644 index 0000000..1c0be39 --- /dev/null +++ b/src/lib_4_comments.4th @@ -0,0 +1,22 @@ +\ Parenthetic comments + +: ( IMMEDIATE + 1 \ allowed nested parens by keeping track of depth + BEGIN + >IN @ #IB @ >= IF \ End of TIB? + QUERY-INPUT \ Get next line + THEN + + IB >IN @ + @ 1 >IN +! + DUP [CHAR] ( = IF \ open paren? + DROP \ drop the open paren + 1+ \ depth increases + ELSE + [CHAR] ) = IF \ close paren? + 1- \ depth decreases + THEN + THEN + DUP 0= UNTIL \ continue until we reach matching close paren, depth 0 + DROP \ drop the depth counter +; +