Source Language Reference Grammar for 488/2107

Spring 1998

Notation:

Grammar:

program:	
        scope

statement:	
        ,  /* empty */
	variable  '<'  '-'  expression ,
	'if'  expression  'then'  statement  [  'else'  statement  ]  'end' ,
	'while'  expression  'do' statement 'end' ,
	'loop'  statement 'end' ,
	'exit' ,
	'return'  [  '(' expression ')'  ]
	'put'  output ,
	'get'  input ,
	scope ,
	procedurename  [  '('  arguments  ')'  ]  ,
	statement statement

scope:	'begin'   [declaration]  statement    'end'

expression:	
        integer ,
	'-'   expression ,
	expression  '+'  expression ,
	expression  '-'  expression ,
	expression  '*'  expression ,
	expression  '/'  expression ,
        expression  '^'  expression ,
	'true'  ,
	'false'  ,
	'not'  expression ,
	expression  'and'  expression ,
	expression  'or'  expression ,
	expression  '='   expression ,
	expression  'not'  '='  expression ,
	expression  '<'  expression ,
	expression  '<'  '='  expression ,
	expression  '>'  expression ,
	expression  '>'  '='  expression ,
	'('  expression  ')'  ,
	'{'   [ declaration ]   statement   'yields'  expression   '}'
	variable ,
	functionname  [  '('  arguments  ')'  ]  ,
	parametername

declaration:	
        type  ':'  identifier  ,
	type  ':'  identifier   '['  expression  ']'  ,
	type  'function'  identifier  [   '('  parameters  ')'   ]  scope ,
	'procedure'  identifier   [   '('  parameters  ')'   ]   scope ,
	declaration declaration

output:	expression ,
	text ,
	'skip'  ,
	output   ','   output

input:	variable ,
	input   ','   input

type:	'integer'  ,
	'boolean' 

arguments:	
        expression ,
	expression   ','   arguments

parameters:	
        type  ':'  identifier  ,
	parameters  ','  type  ':'  identifier

variable:	
        variablename ,
	arrayname   '['   expression   ']'

variablename:	identifier
arrayname:	identifier
functionname:	identifier
procedurename:	identifier
parametername:	identifier

Examples:

identifier examples:	am   al   a_B
integer examples:	0    32767
text examples:		"aB  )'$"   "He said ""hello""."
comment example:	/* comments are bracketed by * and /   */

Tokens may be separated by blanks, comments, or line boundaries. An identifier or keyword must be separated from a following identifier, keyword, integer, or newline token; in all other cases, tokens need not be separated. No token or comment can be continued across a line boundary.

Each identifier must be declared before it is used. There are no type conversions. The precedence and associativity of operators is:

       0.  unary-
       1.  ^                        Right-associative
       2.  * /                      Left-associative
       3.  + binary-                Left-associative
       4.  =  not=  <  <=  >  >=
       5.  not
       6.  and         
       7.  or          

Unless otherwise specified, operators do not associate. So, a=b=c is illegal. Array indexes start at 1.


Marsha Chechik
Back to csc488 homepage
Last modified on January 7, 1998