6 February 2011

UltraEdit and Gforth

Forth
Forth is a computer programming language. Among other things Forth is stack-based, which makes it unique. (Well it's not entirely unique, just quite different from the usual languages like Java or C#.) It's not as popular as other programming systems and most likely you don't know it. I didn't know it either, but the interview with Charles H. Moore, its creator, sparked my interest. So I chose Forth as my new programming language for the last year.

UltraEdit Forth code completionSyntax Highlighting
I use UltraEdit and love it. I created a wordfile for ANS compliant Forth. Adding a wordfile for syntax highlighting is simple. UltraEdit versions 14.20 and earlier use a different approach, but the wordfile is still compatible. As soon as UltraEdit knows about the structure of a Forth program, it's able to provide code completion (shown on the screenshot on the right) and function lists showing all defined functions (see another screenshot).

Limitations
  • The wordfile contains only core words. (Adding words is easy, just add them to the proper section of words in the wordfile.)
  • // is only a comment, if there is a blank or a newline before it, but the later is not possible to define in wordfiles. So line comments starting in the first column are not highlighted properly.
  • UltraEdit supports only symmetric strings, e.g. character sequences between " and ". Forth sequences between S" or C" and " are somehow like strings, but in fact S" and C" are parsing words. These words are highlighted, but not recognised as the beginning of a string. So known words inside strings will be highlighted as well.
  • There is no way to define the pattern for matching numbers and UltraEdit uses its internal magic. This causes some minor glitches in number formatting, e.g. with negative numbers.
Tool Integration
Last year I attended the lecture Stackbased Languages and played around with Gforth that was recommended there. There is a good Gforth integration in Emacs, but I want to stick with UltraEdit. Using its tool configuration I defined a menu item together with a keyboard shortcut for invoking Gforth:

UltraEdit tool configuration for Gforth
Create a new menu item with name gforth, set the command line to gforth "%n%e" -e bye in the working directory %p and make sure the output is captured. Another tool worth defining is the Gforth ANS Report with command line
C:\gforth\gforth.exe C:\gforth\ans-report.fs "%n%e" -e "print-ans-report bye"
Acknowledgement
Experimenting with Forth was part of several System One Research Days. Thank you System One for your support :-)

(Download the UltraEdit wordfile here.)

No comments: