expr.bnf 2.44 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
\begin{syntax}
  expr ::= integer                                ; integer constant
       | real 			                  ; real constant
       | lqualid 		                  ; symbol
       | prefix-op expr 	                  ;
       | expr infix-op expr 	                  ;
       | expr "[" expr "]"                        ; brackets
       | expr "[" expr "]" "<-" expr              ; brackets assignment
       | expr "[" expr infix-op-1 expr "]" 	  ; ternary brackets
       | expr expr+ 		                  ; function application
11 12 13
       | "fun" binder+ spec* "->" spec* expr ; lambda abstraction
       | "let" "rec" rec-defn "in" expr ; recursive functions
       | "let" fun-defn "in" expr                 ; local function
14 15
       | "if" expr "then" expr ("else" expr)?     ; conditional
       | expr ";" expr                            ; sequence
16
       | "loop" invariant* variant? expr "end"    ; infinite loop
17
       | "while" expr                             ; while loop
18
         "do" invariant* variant? expr "done"     ;
19
       | "for" lident "=" expr to-downto expr     ; for loop
20 21
         "do" invariant* expr "done"                ;
       | assertion                                ; assertion
22 23 24
       | "raise" uqualid                          ; exception raising
       | "raise" "(" uqualid expr ")"             ;
       | "try" expr "with" ("|" handler)+ "end"   ; exception catching
25 26
       | "any" type spec*                         ;
       | "abstract" expr spec*                    ; blackbox
27 28
       | "let" pattern "=" expr "in" expr         ; local binding
       | "match" expr ("," expr)* "with"          ; pattern matching
29
         "|"? expr-case ("|" expr-case)* "end"    ;
30
       | "(" expr ("," expr)+ ")"                 ; tuple
31
       | "{" expr-field+ "}"                     ; record
32
       | expr "." lqualid                         ; field access
33
       | expr "." lqualid "<-" expr               ; field assignment
34
       | "{" expr "with" expr-field+ "}"         ; field update
35
       | expr ":" type 	                          ; cast
36
       | "ghost" expr 	                          ; ghost expression
37 38
       | label expr 	                          ; label
       | "'" uident ":" expr                      ; code mark
39 40 41 42
       | "(" expr ")" 	      	                  ; parentheses
  \
  expr-case ::= pattern "->" expr                 ;
  \
43 44 45
  expr-field ::= lqualid "=" expr ";"            ;
  \
  handler ::= uqualid pattern? "->" expr
46
  \
47
\end{syntax}