CoCoA:Grammar: Difference between revisions

From ApCoCoAWiki
Fran (talk | contribs)
Fran (talk | contribs)
Line 6: Line 6:
  [[PROGRAM]] ::= <[[COMMAND]]> | <math>\Lambda</math>
  [[PROGRAM]] ::= <[[COMMAND]]> | <math>\Lambda</math>


  [[COMMAND]] ::= [[HELP_QUERY]] \newline
  [[COMMAND]] ::= [[HELP_QUERY]] (newline)
  | [[PACKAGE_DECL]]
  | [[PACKAGE_DECL]]
  | [[FUNCTION_DECL]]
  | [[FUNCTION_DECL]]
Line 26: Line 26:
  | [[EXPRESSION]]
  | [[EXPRESSION]]
  | [[FUNCTION_CALL]
  | [[FUNCTION_CALL]
  | Return [[[EXPRESSION]]]
  | Return [ [[EXPRESSION]] ]
  | Print [[EXPRESSIONS]]
  | Print [[EXPRESSIONS]]
  | PrintLn [[[EXPRESSIONS]]
  | PrintLn [ [[EXPRESSIONS]] ]
  | If [[EXPRESSION]] Then [[STATEMENTS]] [[[ELSE_LIST]]] End[If]
  | If [[EXPRESSION]] Then [[STATEMENTS]] [ [[ELSE_LIST]] ] End[If]
  | While [[EXPRESSION]] Do [[STATEMENTS]] End[While]
  | While [[EXPRESSION]] Do [[STATEMENTS]] End[While]
  | Repeat [[STATEMENTS]] Until [[EXPRESSION]]
  | Repeat [[STATEMENTS]] Until [[EXPRESSION]]
  | For [[IDENTIFIER]] := [[EXPRESSION]] To [[EXPRESSION]] Step [[EXPRESSION]] Do [[STATEMENTS]] End[For]
  | For [[IDENTIFIER]] := [[EXPRESSION]] To [[EXPRESSION]] [ Step [[EXPRESSION]] ]
Do [[STATEMENTS]] End[For]
  | ForEach [[IDENTIFIER]] In [[EXPRESSION]] Do [[STATEMENTS]] End[ForEach]
  | ForEach [[IDENTIFIER]] In [[EXPRESSION]] Do [[STATEMENTS]] End[ForEach]
  | Break
  | Break
  | Block [[STATEMENTS]] End[Block]
  | Block [[STATEMENTS]] End[Block]
  | Declare [[[TYPE]]] <IDENTIFIER ,>
  | Declare [ [[TYPE]] ] <[[IDENTIFIER]] ,>
  | Delete <IDENTIFIER ,>
  | Delete <[[IDENTIFIER]] ,>
  | Quit
  | Quit
Line 44: Line 45:
  [[LEFT_EXPR]] ::= [[IDENTIFIER]]
  [[LEFT_EXPR]] ::= [[IDENTIFIER]]
  | [[LEFT_EXPR]].[[IDENTIFIER]]
  | [[LEFT_EXPR]].[[IDENTIFIER]]
  | [[LEFT_EXPR]].[<EXPRESSION ,>]
  | [[LEFT_EXPR]].'''['''<[[EXPRESSION]] ,>''']'''


  [[FUNCTION_CALL]] ::= [[FUNCTION_ID]](<EXPRESSION ,>)
  [[FUNCTION_CALL]] ::= [[FUNCTION_ID]](<[[EXPRESSION]] ,>)


  [[FUNCTION_ID]] ::= [[IDENTIFIER]] | [[EXPRESSION]].[[IDENTIFIER]] | [[PACKAGE_ID.IDENTIFIER]]
  [[FUNCTION_ID]] ::= [[IDENTIFIER]] | [[EXPRESSION]].[[IDENTIFIER]] | [[PACKAGE_ID.IDENTIFIER]]

Revision as of 09:27, 20 May 2006

Base grammar

A few rules to start the formal language definition. (They will slowly get more readable as soon as I get confidence with the wiki)

PROGRAM ::= <COMMAND> | Λ
COMMAND ::= HELP_QUERY (newline)
	| PACKAGE_DECL
	| FUNCTION_DECL
	| STATEMENT;
HELP_QUERY ::= ? <*>
PACKAGE_DECL ::= Package PACKAGE_ID <FUNCTION_DECL> End[Package]
FUNCTION_DECL ::= Define IDENTIFIER(PARAMS) STATEMENTS End[Define]
	| Define [Internal/External] IDENTIFIER(PARAMS)
PARAMS ::= <PARAM ,>
PARAM ::= [TYPE] IDENTIFIER
STATEMENT ::= Λ
	| ASSIGNMENT
	| EXPRESSION
	| [[FUNCTION_CALL]
	| Return [ EXPRESSION ]
	| Print EXPRESSIONS
	| PrintLn [ EXPRESSIONS ]
	| If EXPRESSION Then STATEMENTS [ ELSE_LIST ] End[If]
	| While EXPRESSION Do STATEMENTS End[While]
	| Repeat STATEMENTS Until EXPRESSION
	| For IDENTIFIER := EXPRESSION To EXPRESSION [ Step EXPRESSION ]
		Do STATEMENTS End[For]
	| ForEach IDENTIFIER In EXPRESSION Do STATEMENTS End[ForEach]
	| Break
	| Block STATEMENTS End[Block]
	| 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