CoCoA:Grammar

From ApCoCoAWiki
Revision as of 13:47, 6 June 2007 by Fran (talk | contribs)

Base grammar

A few rules to start the formal language definition.

PROGRAM ::= COMMAND | 
COMMAND ::= HELP_QUERY newline
	| PACKAGE_DECL
	| FUNCTION_DECL
	| STATEMENT;
HELP_QUERY ::= ? *
PACKAGE_DECL ::=
   Package PACKAGE_ID
     Template:Opt
     Template:Opt
     Template:Opt
   EndPackage
FUNCTION_DECL ::=
   Define IDENTIFIER( PARAMS ) STATEMENTS EndDefine
 | Define IDENTIFIER( PARAMS ) BuiltIn
 | Define IDENTIFIER( PARAMS ) PlugIn
PARAMS ::= PARAM ,
PARAM ::= TYPE IDENTIFIER
STATEMENTS ::= STATEMENT ;
STATEMENT ::= 
	| ASSIGNMENT
	| EXPRESSION
	| FUNCTION_CALL
	| Return EXPRESSION
	| Print EXPRESSIONS
	| PrintLn EXPRESSIONS
	| If EXPRESSION Then STATEMENTS ELSE_LIST EndIf
	| While EXPRESSION Do STATEMENTS EndWhile
	| Repeat STATEMENTS Until EXPRESSION
	| For IDENTIFIER := EXPRESSION To EXPRESSION Step EXPRESSION
		Do STATEMENTS EndFor
	| ForEach IDENTIFIER In EXPRESSION Do STATEMENTS EndForEach
	| Break
	| Block STATEMENTS EndBlock
	| Declare TYPE IDENTIFIER ,
	| Delete IDENTIFIER ,
	| Quit
ASSIGNMENT ::= LEFT_EXPRESSION := EXPRESSION
LEFT_EXPR ::= IDENTIFIER
	| LEFT_EXPR.IDENTIFIER
	| LEFT_EXPR.[EXPRESSION ,]
FUNCTION_CALL ::= FUNCTION_ID( EXPRESSION , )
FUNCTION_ID ::= IDENTIFIER | EXPRESSION.IDENTIFIER | PACKAGE_ID.IDENTIFIER