SimpleTalk Grammar

Here is a formal grammar for SimpleTalk (so far) in EBNF.

(And here is a rationale for preferring EBNF over a CFG.)

Commands

So far, all commands start with a unique keyword. This makes top-down parsing easy to implement. Eventually handler names will also serve as commands.


Remarks

Note that newlines are mandatory after each command, and inside commands as formatted above. For example, the get command should be:

GetCommandget Expression newline

These are omitted in the foregoing for convenience. Indenting is not required; we are not Python.


Expressions

The expression hierarchy illustrates the precedence, or binding order, of operations. Note that there is (generally) no direct recursion in each production. For example, the rule for E1 does not have E1 on its right-hand side. (Exceptions include E10.) The hierarchy indirectly recurs in the last production, when an E12 can be a parenthesized Expression.



Remarks

In some cases we want to have words serve dual purpose, being keywords in some productions and var names in others. (Aka contextual keywords.)

For example, the Parser has some (inelegant) special-casing to allow the word ‘a’ to be used both as an indefinite article (as in ValuePropertya number) and as a variable name (as in E12). It would be simpler to just declare a to be a reserved word, but scripters will (reasonably) expect to be able to use it for a variable.

Similarly, it will reasonable to write

repeat with line in the lines of text
  ; Use "line" as var name. (And "lines" as a function.)
end repeat

get line 2 of text ; Use "line" as a keyword to introduce E10.

put line 2 of text into line ; Use as both keyword and var name.

and expect it to just work. (Although the third example is perhaps poor style.) The same situation arises with any of the Selector words “item”, “entry”, “line”, “word”, and “char”: we want to use them as keywords in E10, and var names in RepeatCommand blocks.