[Next] [Previous] [Up] [Top] [Contents] [Index]
Appendix A Annotated Cecil Syntax
a program is a sequence of declaration blocks and statements
program ::= file_body file_body ::= { top_decl_block | stmt }
a declaration block is an unbroken sequence of declarations where names are available throughout;
declaration blocks at the top level can be interspersed with pragmas
top_decl_block ::= { decl | pragma } decl_block ::= decl { decl }
a declaration is a variable, a field, or a method declaration
decl ::= module_decl | import_decl | let_decl | tp_decl | type_ext_decl | object_decl | obj_ext_decl
| predicate_decl | disjoint_decl | cover_decl | divide_decl | signature_decl| method_decl | field_sig_decl | field_decl | precedence_decl | include_decl | prim_decl
privacy of a declaration defaults to public
privacy ::= "public" | "protected" | "private"
modules package up independent subsystems
module_decl ::= [privacy] "module" module_name [extension] "{" {friendship | decl} "}" [";"] extension ::= "extends" module_names friendship ::= "friend" module_names ";" module_names ::= module_name {"," module_name} module_name ::= name
import declarations specify used modules
import_decl ::= [privacy] "import" ["friend"] module_names ";"
variable declarations bind names to objects; if "var" is present then variable is assignable
let_decl ::= [privacy] "let" ["var"] name [type_decl] {pragma} ":=" expr ";"
type, representation, and object declarations create new implementations and/or types
tp_decl ::= [type_cxt] [privacy] "type" name [formal_params] {type_relation} [type_cons] ";" declares an object type object_decl ::= [type_cxt] [privacy] rep_role rep_kind name [formal_params] {relation} [type_cons] [field_inits] ";" rep_role ::= "abstract" only inherited from by named objects; allowed to be incomplete | "template" only inherited from or instantiated; uninitialized fields allowed | "concrete" completely usable; must be complete and initialized | ["dynamic"] completely usable; accesses checked dynamically rep_kind ::= "representation" declares an object implementation | "object" declares an object type and implementation type_relation ::= "subtypes" type_patterns relation ::= type_relation type subtypes from type, or impl conforms to type | "inherits" parents impl inherits from impl | "isa" parents impl inherits from impl, type subtypes from type parents ::= named_object_p { "," named_object_p } field_inits ::= "{" field_init { "," field_init } "}" field_init ::= msg_name [location] ":=" expr location ::= "@" named_object
predicate object declaration
predicate_decl ::= [type_cxt] [privacy] "predicate" name [formal_params] {relation} [type_cons] [field_inits] ["when" expr] ";"
declarations of the relationships among predicate objects
disjoint_decl ::= [privacy] "disjoint" named_objects ";" cover_decl ::= [privacy] "cover" named_object "by" named_objects ";" divide_decl ::= [privacy] "divide" named_object "into" named_objects ";" named_objects ::= named_object { "," named_object }
extensions adjust the declaration of an existing object and/or type
type_ext_decl ::= [type_cxt] [privacy] "extend" "type" named_type_p [type_cons] {type_relation} ";" obj_ext_decl ::= [type_cxt] [privacy] "extend" extend_kind named_object_p {relation} [type_cons] [field_inits] ";" extend_kind ::= "representation" extend representation | ["object"] extend both type and representation
signature declarations declare method signatures
signature_decl ::= [type_cxt] [privacy] "signature" method_name "(" [arg_type_ps] ")" [type_decl_p] [type_cons] ";" arg_type_ps ::= arg_type_p { "," arg_type_p } arg_type_p ::= [[name] ":"] type_pattern method_name ::= msg_name [formal_params] | op_name msg_name ::= name
implementation declarations define new method implementations; method decls define signatures, too
method_decl ::= [type_cxt] [privacy] impl_kind method_name
"(" [formals] ")" [type_decl_p] [type_cons] {pragma}
"{" (body | prim_body) "}" [";"]
impl_kind ::= ["method"] "implementation" declares a method implementation
| "method" declares a method signature and implementation
formals ::= formal { "," formal }
formal ::= [name] specializer formal names are optional, if never referenced
specializer ::= location [type_decl_p] specialized formal
| [type_decl_p] unspecialized formal
| "@" ":" named_object_p sugar for @named_obj_p :named_obj_p
field declarations declare accessor method signatures and/or implementations
field_sig_decl ::= [type_cxt] [field_privacy] ["var"] "field" "signature" msg_name [formal_params] "(" arg_type_p ")" [type_decl_p] [type_cons] ";" field_decl ::= [type_cxt] [field_privacy] ["shared"] ["var"] "field" field_kind msg_name [formal_params] "(" formal ")" [type_decl_p] [type_cons] {pragma} [":=" expr] ";" field_kind ::= empty declare accessor method impl(s) and sig(s) | "implementation" declare just accessor method implementation(s) field_privacy ::= privacy [ ("get" [ privacy "set" ] | "set") ]
precedence declarations control the precedence and associativity of binary operators
prec_decl ::= [privacy] "precedence" op_list [associativity] {precedence} ";" associativity ::= "left_associative" | "right_associative" | "non_associative" precedence ::= "below" op_list | "above" op_list | "with" op_list op_list ::= op_name { "," op_name }
include declarations control textual file inclusions (implementation specific)
include_decl ::= "include" file_name ";" file_name ::= string
primitive body declarations include an arbitrary piece of code in the compiled file (implementation specific)
prim_decl ::= prim_body ";"
primitive method bodies support access to code written in other languages (implementation specific)
prim_body ::= "prim" { language_binding }
language_binding ::= language ":" code_string
| language "{" code_chars "}"
language ::= name currently recognize rtl and c_++
code_string ::= string
code_chars ::= brace_balanced_chars any characters, with balanced use of "{" and "}"
body of a method or closure
body ::= {stmt} result| empty return
void
stmt ::= decl_block | assignment ";" | expr ";" result ::= normal_return return an expression | non_local_rtn return from the lexically-enclosing method normal_return ::= decl_block returnvoid
| assignment [";"] returnvoid
| expr [";"] return result of expression non_local_rtn ::= "^" [";"] do a non-local return, returningvoid
| "^" expr [";"] do a non-local return, returning a result
assignment only allowed if name is assignable; returns void
assignment ::= qualified_name ":=" expr | assign_msg assignment-like syntax for messagesassign_msg ::= lvalue_msg ":=" expr sugar for
set_msg(exprs...,expr)
lvalue_msg ::= message| dot_msg
| unop_msg
| binop_msg
expressions
expr ::= binop_expr
binary msgs have lowest precedence
binop_expr ::= binop_msg | unop_expr binop_msg ::= binop_expr op_name binop_expr predecence and associativity as declared
unary msgs have second-lowest precedence
unop_expr ::= unop_msg | dot_expr
unop_msg ::= op_name unop_expr & and ^ are not allowed as unary operators
dotted messages have second-highest precedence
dot_expr ::= dot_msg | simple_expr
dot_msg ::= dot_expr "." msg_name [params] ["(" [exprs] ")"]
sugar for msg_name[params](dot_expr,exprs...)
simple messages have highest precedence
simple_expr ::= literal | ref_expr | vector_expr | closure_expr | object_expr | message | resend | paren_expr
literal constants
literal ::= integer | float | character | string
reference a variable or a named object implementation
ref_expr ::= qualified_name reference a local or global variable | named_object reference a named object
build a vector
vector_expr ::= "[" [exprs] "]" exprs ::= expr { "," expr }
build a closure
closure_expr ::= [ "&" "(" [closure_formals] ")" [type_decl] ] "{" body "}" closure_formals ::= closure_formal { "," closure_formal } closure_formal ::= [name] [type_decl] formal names are optional, if never referenced
build a new object
object_expr ::= rep_role rep_kind {relation} [field_inits]
send a message
message ::= msg_name [params] "(" [exprs] ")"
resend the message
resend ::= "resend" [ "(" resend_args ")" ] resend_args ::= resend_arg { "," resend_arg } resend_arg ::= expr corresponding formal of sender must be unspecialized | name undirected resend (name is a specialized formal)
| name location directed resend (name is a specialized formal)
introduce a new nested scope
paren_expr ::= "(" body ")"
name something perhaps in another module
qualified_name ::= [module_name "$"] name
name an object
named_object ::= qualified_name [params] named_object_p ::= qualified_name [param_patterns]
type contexts and constraints
type_cxt ::= "forall" formal_param { "," formal_param } [type_cons] ":" type_cons ::= "where" type_constraint { "," type_constraint } type_constraint ::= sub_constraint | sig_constraint sub_constraint ::= type_pattern ("<=" | ">=") type_pattern sig_constraint ::= "signature" (msg_name [param_patterns] | op_name) "(" [arg_type_ps] ")" type_decl_p
syntax of types
types ::= type { "," type } type ::= named_type | closure_type | lub_type | glb_type | paren_type named_type ::= qualified_name [params] closure_type ::= "&" "(" [arg_types] ")" [type_decl] arg_types ::= arg_type { "," arg_type } arg_type ::= [[name] ":"] type lub_type ::= type "|" type glb_type ::= type "&" type paren_type ::= "(" type ")"
type patterns are types that can contain binding occurrences of implicit type parameters
type_patterns ::= type_pattern { "," type_pattern } type_pattern ::= binding_type_p | named_type_p | closure_type_p | lub_type_p | glb_type_p | paren_type_p binding_type_p ::= "'" name_binding named_type_p ::= qualified_name [param_patterns] closure_type_p ::= "&" "(" [arg_type_ps] ")" [type_decl_p] lub_type_p ::= type_p "|" type_p glb_type_p ::= type_p "&" type_p paren_type_p ::= "(" type_p ")" name_binding introduces a type variable called name name_binding ::= name [">=" type_pattern] ["<=" type_pattern] type_decl ::= ":" type type_decl_p ::= ":" type_pattern
formal type parameters for objects and methods
formal_params ::= "[" formal_param { "," formal_param } "]" formal_param ::= ["'"] name_binding
actual type parameters for objects and methods
params ::= "[" types "]"
actual type parameters for types that may contain binding occurrences of implicit type variables
param_patterns ::= "[" type_patterns "]"
pragmas can be added at various points in a program to provide implementation-specific hints/commands
pragma ::= "(**" exprs "**)"
[Next] [Previous] [Up] [Top] [Contents] [Index]
Generated with Harlequin WebMaker