Difference between revisions of "CoCoA:Grammar"

From ApCoCoAWiki
(tidying up the wiki...)
 
(12 intermediate revisions by 2 users not shown)
Line 2: Line 2:
  
 
A few rules to start the formal language definition.
 
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]]> | <math>\Lambda</math>
+
  [[CoCoA:Grammar/Program|PROGRAM]] ::= {{flist|[[CoCoA:Grammar/Command|COMMAND]]}} | <math>\Lambda</math>
  
  [[COMMAND]] ::= [[HELP_QUERY]] (newline)
+
  [[CoCoA:Grammar/Command|COMMAND]] ::= [[HELP_QUERY]] ''newline''
| [[PACKAGE_DECL]]
+
    | [[COMMENT]]
| [[FUNCTION_DECL]]
+
    | [[CoCoA:Grammar/Package|PACKAGE_DECL]]
| [[STATEMENT]];
+
    | [[FUNCTION_DECL]]
 +
    | [[STATEMENT]];
 
 
  [[HELP_QUERY]] ::= ? <*>
+
  [[HELP_QUERY]] ::= '''?''' {{flist|*}}
  
  [[PACKAGE_DECL]] ::= Package [[PACKAGE_ID]] <[[FUNCTION_DECL]]> End[Package]
+
  [[COMMENT]] ::= '''--''' {{flist|*}} ''newline''
 +
    | '''//''' {{flist|*}} ''newline''
 +
    | '''/*''' {{flist|*}} '''*/'''
  
  [[FUNCTION_DECL]] ::= Define [[IDENTIFIER]]([[PARAMS]]) STATEMENTS End[Define]
+
  [[CoCoA:Grammar/Package|PACKAGE_DECL]] ::=
| Define [Internal/External] [[IDENTIFIER]]([[PARAMS]])
+
      Package [[PACKAGE_ID]]
 +
        {{fopt|{{flist|[[EXPORT_DECL]] ;}}}}
 +
        {{fopt|{{flist|[[VARIABLE_DECL]] ;}}}}
 +
        {{fopt|{{flist|[[FUNCTION_DECL]]}}}}
 +
      EndPackage
  
  [[PARAMS]] ::= <[[PARAM]] ,>
+
  [[EXPORT_DECL]] ::= Export {{flist|[[IDENTIFIER]] ,}};
  
  [[PARAM]] ::= [TYPE] IDENTIFIER
+
[[VARIABLE_DECL]] ::= Declare {{flist|{{fopt|[[TYPE]]}} [[IDENTIFIER]] ,}};
 +
 
 +
[[FUNCTION_DECL]] ::=
 +
      Define [[IDENTIFIER]]'''(''' [[PARAMS]] ''')''' [[STATEMENTS]] EndDefine
 +
    | Define [[IDENTIFIER]]'''(''' [[PARAMS]] ''')''' BuiltIn
 +
    | Define [[IDENTIFIER]]'''(''' [[PARAMS]] ''')''' PlugIn
 +
 
 +
[[PARAMS]] ::= {{flist|[[PARAM]] ,}}
 +
 
 +
  [[PARAM]] ::= {{fopt|[[TYPE]]}} [[IDENTIFIER]]
 +
 
 +
[[STATEMENTS]] ::= {{flist|[[STATEMENT]] ;}}
  
 
  [[STATEMENT]] ::= <math>\Lambda</math>
 
  [[STATEMENT]] ::= <math>\Lambda</math>
| [[ASSIGNMENT]]
+
    | [[ASSIGNMENT]]
| [[EXPRESSION]]
+
    | [[EXPRESSION]]
| [[FUNCTION_CALL]
+
    | [[FUNCTION_CALL]]
| Return [ [[EXPRESSION]] ]
+
    | Return {{fopt|[[EXPRESSION]]}}
| Print [[EXPRESSIONS]]
+
    | Print [[EXPRESSIONS]]
| PrintLn [ [[EXPRESSIONS]] ]
+
    | PrintLn {{fopt|[[EXPRESSIONS]]}}
| If [[EXPRESSION]] Then [[STATEMENTS]] [ [[ELSE_LIST]] ] End[If]
+
    | If [[EXPRESSION]] Then [[STATEMENTS]] {{fopt|[[ELSE_LIST]]}} EndIf
| While [[EXPRESSION]] Do [[STATEMENTS]] End[While]
+
    | While [[EXPRESSION]] Do [[STATEMENTS]] EndWhile
| Repeat [[STATEMENTS]] Until [[EXPRESSION]]
+
    | Repeat [[STATEMENTS]] Until [[EXPRESSION]]
| For [[IDENTIFIER]] := [[EXPRESSION]] To [[EXPRESSION]] [ Step [[EXPRESSION]] ]
+
    | For [[IDENTIFIER]] := [[EXPRESSION]] To [[EXPRESSION]] {{fopt|Step [[EXPRESSION]]}}
Do [[STATEMENTS]] End[For]
+
    Do [[STATEMENTS]] EndFor
| ForEach [[IDENTIFIER]] In [[EXPRESSION]] Do [[STATEMENTS]] End[ForEach]
+
    | ForEach [[IDENTIFIER]] In [[EXPRESSION]] Do [[STATEMENTS]] EndForEach
| Break
+
    | Break
| Block [[STATEMENTS]] End[Block]
+
    | Block [[STATEMENTS]] EndBlock
| Declare [ [[TYPE]] ] <[[IDENTIFIER]] ,>
+
    | [[VARIABLE_DECL]]
| Delete <[[IDENTIFIER]] ,>
+
    | Delete {{flist|[[IDENTIFIER]] ,}}
| Quit
+
    | Quit
 
 
  [[ASSIGNMENT]] ::= [[LEFT_EXPRESSION]] := [[EXPRESSION]]
+
  [[ASSIGNMENT]] ::= [[LEFT_EXPRESSION]] ''':=''' [[EXPRESSION]]
  
 
  [[LEFT_EXPR]] ::= [[IDENTIFIER]]
 
  [[LEFT_EXPR]] ::= [[IDENTIFIER]]
 
  | [[LEFT_EXPR]].[[IDENTIFIER]]
 
  | [[LEFT_EXPR]].[[IDENTIFIER]]
  | [[LEFT_EXPR]].'''['''<[[EXPRESSION]] ,>''']'''
+
  | [[LEFT_EXPR]].'''['''{{flist|[[EXPRESSION]] ,}}''']'''
 +
 
 +
[[FUNCTION_CALL]] ::= [[FUNCTION_ID]]'''(''' {{flist|[[EXPRESSION]] ,}} ''')'''
  
  [[FUNCTION_CALL]] ::= [[FUNCTION_ID]](<[[EXPRESSION]] ,>)
+
  [[FUNCTION_ID]] ::= [[IDENTIFIER]] | [[EXPRESSION]]'''.'''[[IDENTIFIER]] | [[PACKAGE_ID]]'''.'''[[IDENTIFIER]]
  
[[FUNCTION_ID]] ::= [[IDENTIFIER]] | [[EXPRESSION]].[[IDENTIFIER]] | [[PACKAGE_ID.IDENTIFIER]]
+
[[Category:CoCoA5Client]]

Latest revision as of 17:34, 20 October 2007

Base grammar

A few rules to start the formal language definition.

PROGRAM ::= COMMAND | 
COMMAND ::= HELP_QUERY newline
   | COMMENT
   | PACKAGE_DECL
   | FUNCTION_DECL
   | STATEMENT;
HELP_QUERY ::= ? *
COMMENT ::= -- * newline
   | // * newline
   | /* * */
PACKAGE_DECL ::=
     Package PACKAGE_ID
       EXPORT_DECL ;
       VARIABLE_DECL ;
       FUNCTION_DECL
     EndPackage
EXPORT_DECL ::= Export IDENTIFIER ,;
VARIABLE_DECL ::= Declare TYPE IDENTIFIER ,;
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
   | VARIABLE_DECL
   | 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