expr.bnf 2.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
\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
       | "fun" type-v-param+ "->" triple          ; lambda abstraction
       | "let" "rec" recfun ("with" recfun)*      ; recursive functions
       | "if" expr "then" expr ("else" expr)?     ; conditional
       | expr ";" expr                            ; sequence
       | "loop" loop-annot "end"                  ; infinite loop
16 17
       | "while" expr                             ; while loop
         "do" loop-annot expr "done"              ;
18 19 20 21 22 23 24
       | "for" lident "=" expr to-downto expr     ; for loop
         "do" loop-inv expr "done"                ;
       | assert annotation                        ; assertion
       | "absurd"                                 ;
       | "raise" uqualid                          ; exception raising
       | "raise" "(" uqualid expr ")"             ;
       | "try" expr "with" ("|" handler)+ "end"   ; exception catching
25
       | "any" type-c                             ;
26 27 28 29
       | "let" pattern "=" expr "in" expr         ; local binding
       | "match" expr ("," expr)* "with"          ; pattern matching
         ("|" expr-case)+ "end"                   ;
       | "(" expr ("," expr)+ ")"                 ; tuple
30
       | "{" field-value+ "}"                     ; record
31
       | expr "." lqualid                         ; field access
32
       | expr "." lqualid "<-" expr               ; field assignment
33
       | "{" expr "with" field-value+ "}"         ; field update
34
       | expr ":" type 	                          ; cast
35 36
       | label expr 	                          ; label
       | "'" uident ":" expr                      ; code mark
37 38 39 40
       | "(" expr ")" 	      	                  ; parentheses
  \
  expr-case ::= pattern "->" expr                 ;
  \
41
  field-value ::= lqualid "=" expr ";"            ;
42 43 44
  \
  triple ::= expr                                 ;
    | pre expr post                               ; Hoare triple
45
\end{syntax}