Tiny Imperative Language

Software Transformation Systems
This is a proposal for a Tiny Imperative Language for setting tiny benchmarks of source transformation systems such as the TIL Chairmarks.

-- EelcoVisser & JamesCordy

Added "primary -> string", to allow for transformations involving addition of meaningful output statements.

-- JamesCordy - 29 Apr 2005

In the draft Stratego manual Eelco has proposed that the commenting convention of TIL be the C++ // to end of line comments. This seems a good idea and I suggest we adopt it.

Eelco has also proposed that the "write" statement does not output a full line, rather outputs only what is given. Newlines must then be explicitly output using an escaped newline "\n". This is a good idea also but not yet agreed. It also opens the larger question of "what's in a string?" We need some lexical specs here.

The draft Stratego manual also adds "begin-end" statements, which TIL so far does not have, and seems to assume that begin-end implies scopes, which at present it appears TIL also does not have. Both of these are the subject of TIL Chairmarks. Possibly the core language should have begin-end, but if so we are committed to nested scope rules I think. Not clear this keeps us "tiny".

Finally, I infer from the desugaring example in the draft Stratego manual that it is proposed that "for" statements be changed to require their control variable to be declared. This is the subject of one of the TIL Chairmarks transformations. Possibly we should make this change to the core language.

-- JamesCordy - 30 Aug 2005

% Grammar for Tiny Imperative Language (TIL)

program -> statement*

statement ->  declaration
           |  assignment_statement
           |  if_statement
           |  while_statement
           |  for_statement
           |  read_statement
           |  write_statement

% Untyped variables
declaration -> "var" identifier ";"

assignment_statement -> identifier ":=" expression ";"

if_statement -> "if" expression "then" 
             |  "if" expression "then" 

% While loop 
while_statement -> "while" expression "do"

% Declaring for
for_statement -> "for"  identifier ":=" expression "to" expression do

read_statement -> "read" identifier ";"

write_statement -> "write" expression ";"

% Simple 
expression -> primary
           |  expression op expression

primary -> identifier
        |  integer
        |  string
        |  "(" expression ")"

op -> "=" | "!="        % lowest priority       
   |  "+" | "-"
   |  "*" | "/"         % highest priority