Thursday, March 21, 2013

Syntax Outline

The basic unit of a Toyl program will be an expression, which may be a constant value, lambda expression, or else involve function calls and operators.  The full description of expression syntax covers almost everything else I currently envision in Toyl:
expression ::= { reference | constant | evaluable | lambda }

  reference ::= identifier
  evaluable ::= { function-call | operator-expression } [where-phrase]
    function-call ::= function-name "(" parameters ")"
      function-name ::= identifier
      parameters ::= expression ["," parameters]
    operator-expression ::= { unary-operation | binary-operation | trinary-operation }
      unary-operation ::= operator expression
      binary-operation ::= expression operator expression
      ternary-operation ::= expression operator expression operator expression
    where-phrase ::= "where" "{" declarations "}"
      declarations ::= declaration [";" declarations]
        declaration ::= identifier "=" expression
  lambda ::= return-type function-type "(" parameter-declarations ")" "{" expression "}"
    function-type ::= "function" | "process"
    parameter-declarations ::= parameter-declaration ["," parameter-declarations]
      parameter-declaration ::= type identifier

Fig. 9.1: Expression syntax
Identifiers may be organized in namespaces, which (like the where-phrase above) are just collections of identifiers:
namespace ::= "namespace" "{" declarations "}"
Fig. 9.2: Namespace syntax

This looks like a good start.  In the next post, I'll try to walk through the process of translating Toyl expressions into the underlying object structures and see where my ideas break.

No comments:

Post a Comment