Page 1 of 1

Forth language spec

Posted: Sun Apr 24, 2005 7:37 pm
by TonyMc
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:

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 ;

Posted: Tue Apr 26, 2005 8:26 am
by jussij
Hi Tony,

The code folding for Forth has been implemented and the new xFolder.dll can be found here:

http://www.zeusedit.com/z300/xfolder.zip

The Forth specification you provided could only be partially implemented in that the above DLL has the following limitations:
(1) Whitespace
The xFolder ignores all whitespace, thus all the comments specifications where implemented but the "followed by whitespace" clause was not. Basicaly this means all (, ), {, } and \ characters are identified as a comment character.

If this is going to cause a problem just post a bug report to this thread and I will see if this limitation is easily fixed.

(2) Lines Containing Multiple End of Fold Markers
Your specification also highlighted a folding bug specific to all languages. :(

For any situation where two end of folds occur on the same line the second end of fold is lost, resulting in a folding error. For example this will code will fold incorrectly:

Code: Select all

: sample1  ( -- )
  begin
  repeat ;

: sample2  ( -- )
  begin
  repeat ;
but this code will fold correctly:

Code: Select all

: sample1  ( -- )
  begin
  repeat
  ;

: sample2  ( -- )
  begin
  repeat
  ;
This bug requires further investigation and will most likely require a change to the folding model. This means the editor itself will need to be changed so if this is the case the fixed will only be available in the next Zeus release.

Jussi

Posted: Wed Apr 27, 2005 9:50 pm
by TonyMc
The code folding for Forth has been implemented and the new xFolder.dll can be found here:
Hi Jussi,

thanks for implementing this so quickly. I am really impressed by the quality of your support for Zeus. And thanks for the warning about two fold closings on the same line. That shouldn't be hard for me to work around, but it's great that you are also looking into this.

Best wishes,
Tony