Forth language spec
Posted: Sun Apr 24, 2005 7:37 pm
Dear Jussij,
here is a possible spec for ANS Forth. It covers loops, conditionals and colon definitions (the Forth equivalent of functions, where : starts a definition and ; completes it) as well as block comments. I hope this helps.
Tony
Extension: .f .fth
Line Comment: \ (backslash followed by whitespace)
Block Comment: ( ) (opening parenth followed by whitespace)
Block Comment: { } (opening brace followed by whitespace)
Begin: :
End: ;
Begin: BEGIN
End: REPEAT
Begin: IF
End: THEN
Begin: DO
End: LOOP
Begin: ?DO
End: LOOP
Begin: DO
End: +LOOP
Begin: ?DO
End: +LOOP
Begin: BEGIN
End: UNTIL
Begin: BEGIN
End: AGAIN
Sample Code:
here is a possible spec for ANS Forth. It covers loops, conditionals and colon definitions (the Forth equivalent of functions, where : starts a definition and ; completes it) as well as block comments. I hope this helps.
Tony
Extension: .f .fth
Line Comment: \ (backslash followed by whitespace)
Block Comment: ( ) (opening parenth followed by whitespace)
Block Comment: { } (opening brace followed by whitespace)
Begin: :
End: ;
Begin: BEGIN
End: REPEAT
Begin: IF
End: THEN
Begin: DO
End: LOOP
Begin: ?DO
End: LOOP
Begin: DO
End: +LOOP
Begin: ?DO
End: +LOOP
Begin: BEGIN
End: UNTIL
Begin: BEGIN
End: AGAIN
Sample Code:
Code: Select all
: sample ( -- )
xxx xxx xxx
yyy yyy
zzz zzz ;
: sample2 ( -- )
0 > if
xxx xxx xxx
else
yyy yyy yyy
then ;
: sample3 ( -- )
begin
0 < while
xxx xx xxx
yyy yyy yyy
repeat ;
: sample4 ( -- )
100 0 ?do
xxx xxx xxx
loop ;
: sample5 ( -- )
begin
xxx xxx xxx
0= until ;
: sample6 ( -- )
begin
xxx xxx xxx
yyy yyy yyy
again
zz zzz zzz ;