附录A Erlang 语法参考

这部分语法参考是 LALR 语法的改编版本。

此语法和严格的 LALR 语法对 match_expr 有不同理解。 match_expr 中等号左边可以是一个模式或者表达式, Erlang 编译器会在语义分析时确定其含义。

类型优先级运算符
Nonassoc0'catch'.
Right200'='.
Right200'!'.
Left300addop.
Left400multop.
Nonassoc500prefixop.

编号非终结符表达式
1addop:="+"|"-"|"bor"|"bxor"|"bsl"|"bsr"
2comp_op:="=="|"/="|"=<"|"<"|">="|">"|"=:="|"=/="
3mult_op:="*"|"/"|"div"|"rem"|"band"
4prefix_op:="+"|"-"|"bnot"
5basic_type:="atom"|"number"|"string"|"var"|"true"
6pattern:=basic_type|pattern_list|pattern_tuple
7pattern_list:="[""]"|"["patternpatterntail"]"
8pattern_tail:="|"pattern|","patternpattern_tail|ε
9pattern_tuple:="{""}"|"{"patterns"}"
10patterns:=pattern|pattern","patterns
11expr:=basic_type|list|tuple|function_call|expraddopexpr|exprmult_opexpr|prefix_opexpr|"("expr")"|"begin"exprs"end"|"catch"expr|case_expr|if_expr|receive_expr|match_expr|sendexpr
12list:="[""]"|"["exprexpr_tail"]"
13expr_tail:="|"expr|","exprexpr_tail|ε
14tuple:="{""}"|"{"exprs"}"
15function_call:="atom""("parameter_list")"|"atom"":""atom""("parameter_list")"
16parameter_list:=exprs|ε
17case_expr:="case"expr"of"cr_clauses"end"
18cr_clause:=patternclause_guardclause_body
19cr_clauses:=cr_clause|cr_clause";"cr_clauses
20if_expr:="if"if_clauses"end"
21if_clause:=guardclause_body
22if_clauses:=if_clause|if_clause";"if_clauses
23receive_expr:="receive""after"exprclause_body"end"|"receive"cr_clauses"end"|"receive"cr_clauses"after"exprclause_body"end"
24match_expr:=expr"="expr
25sendexpr:=expr"!"expr
26exprs:=expr|expr","exprs
27guard_expr:=basic_type|guard_expr_list|guard_expr_tuple|guard_call|"("guard_expr")"|guard_expraddopguard_expr|guard_exprmult_opguard_expr|prefix_opguard_expr
28guard_expr_list:="[""]"|"["guard_exprguard_expr_tail"]"
29guard_expr_tail:="|"guard_expr|","guard_exprguard_expr_tail|ε
30guard_expr_tuple:="{""}"|"{"guard_exprs"}"
31guard_exprs:=guard_expr|guard_expr","guard_exprs
32guard_call:="atom""("guard_parameter_list")"
33guard_parameter_list:=guard_exprs|ε
34bif_test:="atom""("guard_parameter_list")"
35guard_test:=bif_test|guard_exprcomp_opguard_expr
36guard_tests:=guard_test|guard_test","guard_tests
37guard:="true"|guard_tests
38function_clause:=clause_headclause_guardclause_body
39clause_head:="atom""("formalparameter_list")"
40formalparameter_list:=patterns|ε
41clause_guard:="when"guard|ε
42clause_body:="->"exprs
43function:=function_clause|function_clause";"function
44attribute:=pattern|"["farity_list"]"|"atom"",""["farity_list"]"
45farity_list:=farity|farity","farity_list
46farity:="atom""/""number"
47form:="-""atom""("attribute")"|function

非终结符编号
add_op1 11 27
attribute44 47
basic_type5 6 11 27
bif_test34 35
case_expr11 17
clause_body18 21 23 38 42
clause_guard18 38 41
clause_head38 39
comp_op2 35
cr_clause18 19
cr_clauses17 19 19 23
expr11 11 12 13 17 23 24 25 26
expr_tail12 13 13
exprs11 14 16 26 26 42
farity45 46
farity_list44 45 45
form47
formal_parameter_list39 40
function43 43 47
function_call11 15
function_clause38 43
guard21 37 41
guard_call27 32
guard_expr27 27 28 29 31 35
guard_expr_list27 28
guard_expr_tail28 29 29
guard_expr_tuple27 30
guard_exprs30 31 31 33
guard_parameter_list32 33 34
guard_test35 36
guard_tests36 36 37
if_clause21 22
if_clauses20 22 22
if_expr11 20
list11 12
match_expr11 24
mult_op3 11 27
parameter_list15 16
pattern6 7 8 10 18 44
pattern_list6 7
pattern_tail7 8 8
pattern_tuple6 9
patterns9 10 10 40
prefix_op4 11 27
receive_expr11 23
send_expr11 25
tuple11 *14