Filed on: [Indigo]<CedarDocs>Language>Grammar.doc, press
Last written: May 30, 1982 9:36 pm
By: JJH - Butler Lampson's February 17, 1982 Cedar Grammar
DRATF XXX DARFT XXX DRFAT XXX DRAFTT XXX DRAFT!
Cedar Language Grammar Version 3
I simply don't see any of repairing this with a reasonable amount of work. Unfortunately, the sources are all in Bravo X and intricately intertwined with other information. - JJH
The intention of this grammar and associated restrictions is to document the Cedar syntax (as accepted by the compiler). A considerable amount of semantic detail has been suppressed, so as to simplify the grammar.
Notation:
Parentheses are for grouping.
Item | item means choose one.
?item means zero or one occurrences of item.
{item}sep means one or more occurrences of item separated by sep. The sep is optional. ?{item}sep means zero or more.
Terminals are punctuation other than (){}?| or quoted or in small caps.
The order is: module, type, expression, and top-down within these.
*module ::= ? directory {id} : ?resident transferTC ?(LOCKS primary ?(using id : type))
?(IMPORTS { ?(id :) id },) ?(EXPORTS ids) ?(SHARES ids) = block .
directory ::= DIRECTORY {id ?(: (FROM stringLiteral | type ?id)) ?(USING [ ?ids ])}, ;
*block ::= attributes BEGIN body END
*body ::= ?(open ;) ?(enable ;) ?({decl}; ;) ?{stat}; ?; ?(exits ?;)
open ::= OPEN {?(id :) exp},
decl ::= ?({id ?position}, :) type
exits ::= (exits | repeat) {choice};
position ::= "(" exp ?(: exp .. exp) ")"
stat ::= exp | control | block | loop
control ::= CONTINUE | EXIT | (GOTO | GO TO) id | LOOP | NULL | RETRY | STOP | REJECT |
(RETURN | RESUME) ?group | var ← state
loop ::= iterator ?((WHILE | UNTIL) exp) DO body ENDLOOP
*iterator ::= THROUGH exp |
FOR (id | newId type) (?DECREASING IN exp | ← exp , exp)
type ::= attributes (typeId | builtInType | typeCons) ?initialization
typeId ::= ?{id} id ?(. id)
attributes ::= ?{PUBLIC | PRIVATE | READONLY | ENTRY | INTERNAL | MONITORED |
MACHINE DEPENDENT | typeId RELATIVE | LONG | ORDERED | BASE | PACKED | UNCOUNTED |
CHECKED | UNCHECKED | TRUSTED | SAFE |
INLINE | RESIDENT | MACHINE CODE}
builtInType ::= INTEGER | CARDINAL | REAL | UNSPECIFIED | TYPE | ZONE
*initialization ::= (← | =) (exp ?("|" NULL) | block | type | CODE | [ exp ]) |
MACHINE CODE BEGIN { {exp}, }; END
typeCons ::= enumerationTC | subrange | typeId { [exp] } |
recordTC | unionTC | arrayTC | refTC | pointerTC | transferTC
enumerationTC ::= "{" {id ?position | position}, "}"
recordTC ::= RECORD fields
*fields ::= [ ?{decl ?position}, ] | NULL
*unionTC ::= SELECT tag FROM {ids => fields}, ?, ENDCASE | SEQUENCE tag OF type
tag ::= (newId | COMPUTED | OVERLAID ) (type | *)
newId ::= id ?position :
arrayTC ::= ARRAY ?type OF type
refTC ::= REF ?(readOnly (type | ANY))
listTC ::= LIST OF readOnly type
pointerTC ::= (POINTER ?subrange TO | DESCRIPTOR FOR) type
transferTC ::= (PROCEDURE | PROC | PORT | PROCESS | SIGNAL | ERROR | PROGRAM)
?fields ?(RETURNS fields)
exp ::= primary | prefixOp exp | exp infixOp exp | subrange | var ← exp |
funnyAppl var ?group | if | select | NULL
primary ::= var | literal | builtIn group | typeBuiltIn [ type ] |
DESCRIPTOR [ exp ?(, exp ?(, type)) ]
SIZE [type ?(, exp) ] | ISTYPE [exp, type ?enable ]
var ::= id | "(" exp ")" | var ^ | var . id | group | var group |
( NARROW | LOOPHOLE) [ exp ?(, type) ?enable ]
group ::= [ ?{?(id :) exp}, ?enable ]
enable ::= ! {choice}; | enable choice | enable BEGIN {choice}; ?: END
builtIn ::= MIN | MAX | ABS | LENGTH | BASE | PRED | SUCC | ALL | LONG
typeBuiltIn ::= FIRST | LAST | CODE | NIL
prefixOp ::= @ | - | ~ | NOT
infixOp ::= * | / | MOD | + | - | relOp | AND | OR
relOp ::= ?(~ | NOT) (# | = | < | <= | > | >= | IN )
subrange ::= ?typeId ( "[" | "(" ) exp .. exp ( "]" | ")" )
funnyAppl ::= FORK | JOIN | SIGNAL | ERROR | NEW |
START | RESTART | WAIT | NOTIFY | BROADCAST | RETURN WITH ERROR |
TRANSFER WITH | RETURN WITH
if ::= IF exp THEN exp ?(ELSE exp)
select ::= (SELECT expselector | WITH ?(id :) expunion SELECT ?exp) FROM {choice}, ?, ENDCASE ?(=> exp)
choice ::= ({condition}, | newId type)=> exp
condition ::= exp | relOp exp | relOp exp | FINISHED | ANY