Second Draft of CHAIMS Grammar and Language Structure Proposal
Pankaj Jain
February 3, 1997



1.
Primary objective of CHAIMSis to facilitate composition. Thus OO paradigm
is a good candidate. But we are going to only use chaims for composition
and not development of objects. So inheritance is not required. We just
need to take advantage of the encapsulation in the OO paradigm.

2.
Another issue is of type checking. We can have strong compile time
checking like Pascal or procastinate it to run time like smalltalk and
lisp. There is also a possibilty of a middle path - partially run time and
partially compile time. The trade-off depends on whether we want safety or
flexibilty. Static type checking makes coding less error prone and well
documented (and may also help compiler with with some optimizations) but
at the same time the programmer is constrained somewhat. Another issue is
that chaims is only going to be a composition mechanism and not coding
mechanism and the programs are going to be small so we can avoid type info
explicitly in the language structure. THIS ISSUE NEEDS SOME DISCUSSION.

3.
Closely related to 2 is the issue of type. We can have basically no type
associated with variables (that is compile time type) and treed them as
messages to and from the megamodules (la smalltalk) and let the type
business be handled at run time.

4.
As far as the parameter passing (and values returned) to methods of
megamodules is concerned we better have named arguments scheme. We could
have methods with no parameters and the parameter passing is done thru
properties. For example, if a megamodule adds two numbers then the
psedocode of the megamodule may appear as follows :

megamodule Adder{
public properties:
int x;
int y;
int z;
public methods:
add = { z = x + y }
}

and the client uses
Adder.x = 1;
Adder.y = 2;
Adder.add;
Having send the message add to the Adder the the megaprogram does not wait
for the result of add. It can conviniently refer to the result anytime
later in the program using Adder.z. This facilitates asynchronous
concurrent execution of the megamodules. To enforce synchrony the
megaprogram can wait for the add to finish by using estimate(or done
statement) which can be used to find out how much of the execution
remains.

5. 4 assumes that by default we assume asynchronous execution. We need to
decide what our default is.

6. The syntax described in 4 is not necessarily the final. We can have a
convinient mechanism for setting properties of a megamodule like
Adder{x,y}={1,2} or whatever. Notice it also associates a semantics
depending upon where the property appears in an assignment. Lvalue
corresponds to set property and Rvalue to get property. Hope it makes
sense.

7. We could in defining the interface attach attributes to the
members. Like the Adder interface can be defined as

Adder{

SETPROPERTY int x;
SETPROPERTY int y;
GETPROPERTY int z;
METHOD      add { z = x + y};

}

This enforces a restriction on how each member can be used and thus can
prove handy if we were to have some mechanism of verification of the
megaprograms. We can take megamodules and the megaprogram as concurrent
agents and the megaprogram communicates with other agents thru messages
(GETPROP, SETPROP or INVOKEMETHOD)


Below is the first draft of BNF. This is not necessarily complete or
correct. It is the first draft.
I think that the BNF below is not too big. also notice that a correct
program follows the BNF but so could many of incorrect programs. How much
correctness checking the BNF achieves is dependent on how you design the
BNF of a language. But if you insist that it does do a lot of correctness
checking then the BNF blows up.

Comments within C styled /**/ 
------------------------------------------------------------------------------

Program			->   	T_Prog identifier '(' MegamoduleList ')'
                                '{' Program ')'
/* identifier = program name
   MegaModuleList = List of megamodules used. This may be used to import
   or include(la #include) megamodule interfaces so that megaprogrammer
   need not define interfaces himself. The production for MegamoduleList
   is omitted as we haven't defined how to give pathnames for MModules. 
   They are spread over the net so we may like URL kind of a strategy.
*/   


VariableDeclaration	->	Variable ';'
	
Variable		->	Type Identifier

/* This is what was there in SOOP
Type			-> 	int
			->	void
			-> 	bool
			->	double 
			->	class Identifier

And this is what we get if we assume no type checking

*/

Type                   ->       blob
                       ->       T_megamodule Identifier

ParameterListOrVoid	->	Void  
			->	ParameterList

ParameterList 		->	( ParameterList ',' )* Parameter 

Parameter		->	Variable

Program          	->	CompoundStatement 

CompoundStatement	->	'{' ( VariableDeclaration )* 
				    ( Statement )* '}' 
/* TO BE DECIDED: do we need to allow variable declarations inside
compound statements. This would oblige us to have a scoping mechanism */

Statement		->	SimpleStatement  ';'
			->	IfStatement      
			->	WhileStatement
			->      EstimateStatement
			->	CompoundStatement
/* No for loop required. In my opinion for loop doesn't buy you much */
/* Separate estimate statement! I would have prefered to have it at par
with other methods in the megamodule */

SimpleStatement		->	Designator '=' Expression
			->	Identifier '=' Expression
			->	Expression      

Designator		->      Expression '.' Identifier 

Call			->	Expression '.' Identifier 
				  '(' ArgumentList ')'
/* I have retained ArgumentList just to indicate where the arguments of
the method would go if we were to have functions with more than Zero
parameters */

 

Expression		->	Designator
			->	Call
			->	Identifier
			->	Constant
			->	'(' Expression ')'
			->	Setup '(' Identifier ')'
			->      Terminate '(' Identifier ')'

/* All these get commented as addition etc is to be performed by
airithmetic megamodule etc. 
			->	Expression '+' Expression
			->	Expression '-' Expression
			->	Expression '/' Expression
			->	Expression '*' Expression
			->	Expression '%' Expression
			->	Expression '==' Expression
			->	Expression '!=' Expression
			->	Expression '<' Expression
			->	Expression '>' Expression
			->	Expression '<=' Expression
			->	Expression '>=' Expression
			->	Expression '&&' Expression
			->	Expression '||' Expression
			->	'-' Expression 
			->	'!' Expression 
			->	ReadInteger '(' ')'

    TILL HERE WE COMMENT */

	
/* Constant List may be superfluous or inadequate. To be discussed */

Constant		->	IntConstant
			->	BoolConstant
			->	DoubleConstant
			->	StringConstant
			->	Null
				
ArgumentList		->	(Expression ',' )* Expression
			->


WhileStatement		->	while '(' Expression ')' Statement

IfStatement		->	if '(' Expression ')' Statement 
				  ( else Statement )?

EstimateStatement	->	Estimate '(' Call ')' 

---------------------------------------------------------------------------

         E  N  D    O  F    B  N  F
---------------------------------------------------------------------------


         B  N  F    O  F    SOOP
         -----------------------

Just for reference here is the bnf of SOOP that "inspired" the one
suggested above




Program			->   	( Declaration )* 

Declaration		-> 	ClassDefinition  
			->	ClassDeclaration  
			->	FunctionDefinition
			->	FunctionDeclaration  
			->	VariableDeclaration   

VariableDeclaration	->	Variable ';'
	
Variable		->	Type Identifier ArrayModifiers

ArrayModifiers		->	( '[' IntConstant ']' )*
	
Type			-> 	int
			->	void
			-> 	bool
			->	double 
			->	class Identifier


ClassDeclaration	->	class Identifier ';' 	

ClassDefinition		->	class Identifier (':' Identifier)? 
				'{'  ClassDefinitionList '}' 

ClassDefinitionList	->	( ClassDefinitionList 
				  (public|private)?
				  ClassField )*

ClassField		->	InstanceVariableDeclaration
			->	FunctionDefinition
			->	FunctionDeclaration

InstanceVariableDeclaration ->	Variable ';'

FunctionDeclaration	->  	Type Identifier 
				  '(' ParameterListOrVoid ')' ';'

ParameterListOrVoid	->	Void  
			->	ParameterList

ParameterList 		->	( ParameterList ',' )* Parameter 

Parameter		->	Variable

FunctionDefinition	->	Type Identifier '(' ParameterListOrVoid ')' 
				  CompoundStatement 

CompoundStatement	->	'{' ( VariableDeclaration )* 
				    ( Statement )* '}' 

Statement		->	SimpleStatement  ';'
			->	IfStatement      
			->	WhileStatement
			->	ReturnStatement  ';'
			->	CompoundStatement
			->	PrintStatement ';'

SimpleStatement		->	Designator '=' Expression
			->	Identifier '=' Expression
			->	Expression      

Designator		->      Expression ( '.' Identifier |
				             '[' Expression ']' )

Call			->	( Expression '.' )? Identifier 
				  '(' ArgumentList ')' 

Expression		->	Designator
			->	Call
			->	Identifier
			->	Constant
			->	Expression '+' Expression
			->	Expression '-' Expression
			->	Expression '/' Expression
			->	Expression '*' Expression
			->	Expression '%' Expression
			->	Expression '==' Expression
			->	Expression '!=' Expression
			->	Expression '<' Expression
			->	Expression '>' Expression
			->	Expression '<=' Expression
			->	Expression '>=' Expression
			->	Expression '&&' Expression
			->	Expression '||' Expression
			->	'(' Expression ')'
			->	'-' Expression 
			->	'!' Expression 
			->	ReadInteger '(' ')'
			->	New '(' Identifier ')'
			->	NewArray '(' Expression ')' 
	
Constant		->	IntConstant
			->	BoolConstant
			->	DoubleConstant
			->	StringConstant
			->	Null
				
ArgumentList		->	(Expression ',' )* Expression
			->

BooleanExpression	->	Expression

WhileStatement		->	while '(' BooleanExpression ')' Statement

IfStatement		->	if '(' BooleanExpression ')' Statement 
				  ( else Statement )?

ReturnStatement		->	Return ( Expression )? 

PrintStatement		->   	Print '(' (Expression ',' )* Expression ')'




02/03/97ct