GRASS (programming language): Difference between revisions

Content deleted Content added
m Zgrass capitalization consistency
m Description: rm easter egg link
Line 26:
Zgrass was based on a standard set of BASIC commands and used most of its syntax. Where Zgrass differed from BASIC was that all commands were in fact [[function (programming)|function]]s and returned values, similar to the [[C (programming language)|C programming language]]. If there was no obvious return value it was expected that a function would return 1 if it succeeded, and 0 if it failed. For instance, the command <code>PRINT PRINT 10</code> would be illegal in BASIC, but in Zgrass this would print <code>10 1</code>, the 1 being the value returned by second <code>PRINT</code>, meaning "I successfully output the string '10'".
 
Programs in Zgrass were referred to as "macros", and stored as strings. Both of these oddities were deliberate, as Zgrass allowed any string to become a program. For instance, <code>MYBOX="BOX 0,0,100,100,2"</code> defines a string (no need for a $ on the variable as in [[Microsoft BASIC]]s) containing a snippet of Zgrass code. Simply typing {{code|MYBOX}} from that point on would run the command(s) inside. This feature can be used in place of the more traditional <code>[[GOSUB]]</code> command from BASIC, but has the added advantage of having a well-defined name as opposed to an opaque line number. In addition, the command remains in the form of a string in memory and can be manipulated at runtime with standard string operations.
 
Most BASIC [[interpreter (computer software)|interpreters]] of the era converted the input text into a ''[[Lexical analysis|tokenized]]'' version in which each of the commands was replaced by a single number (typically one [[byte]] long). This made the program run faster because it didn't have to continually decode the commands from the strings every time. Zgrass's use of string-based macros made this difficult, so they didn't bother with tokenization. Instead, they included a [[compiler]] which could be used on any particular macro, speeding it up many times. Programs would often consist of a mix of compiled and uncompiled macros.