1 | /* $Id: lfc.grammar 3798 2008-06-02 11:23:39Z orlov $ |
---|
2 | * |
---|
3 | * This is LL(1) grammar for LFC based on the "Introduction to LFC Programming |
---|
4 | * Language" (January 25, 2008) by Zhen Lixiao |
---|
5 | */ |
---|
6 | |
---|
7 | %token SC COLON COMMA |
---|
8 | %token DEC VAR DEF |
---|
9 | %token ASTERISK TO EQ |
---|
10 | %token LPAR RPAR |
---|
11 | %token IDENTIFIER STRING UNDEFINED |
---|
12 | %token CONCAT |
---|
13 | %token IF THEN ELSE WHERE |
---|
14 | |
---|
15 | %% |
---|
16 | |
---|
17 | program : function_dec var_dec_and_func_def program_rest ; |
---|
18 | |
---|
19 | program_rest : /*empty*/ |
---|
20 | | program |
---|
21 | ; |
---|
22 | |
---|
23 | function_dec : DEC funname COLON function_type SC ; |
---|
24 | |
---|
25 | var_dec_and_func_def : variable_dec definition |
---|
26 | | definition |
---|
27 | ; |
---|
28 | |
---|
29 | variable_dec : VAR vars_decl variable_dec_rest ; |
---|
30 | |
---|
31 | vars_decl : variable_list COLON concept_name SC ; |
---|
32 | |
---|
33 | variable_dec_rest : /*empty*/ |
---|
34 | | vars_decl variable_dec_rest |
---|
35 | ; |
---|
36 | |
---|
37 | variable_list : variable variable_list_rest ; |
---|
38 | |
---|
39 | variable_list_rest : /*empty*/ |
---|
40 | | COMMA variable variable_list_rest |
---|
41 | ; |
---|
42 | |
---|
43 | definition : DEF equation equation_rest ; |
---|
44 | |
---|
45 | equation : funname LPAR pattern_list RPAR EQ exp_with_where SC ; |
---|
46 | |
---|
47 | equation_rest : /*empty*/ |
---|
48 | | equation equation_rest |
---|
49 | ; |
---|
50 | |
---|
51 | pattern_list : pattern pattern_list_rest ; |
---|
52 | |
---|
53 | pattern : STRING pat_concat |
---|
54 | | variable pat_concat |
---|
55 | ; |
---|
56 | |
---|
57 | pat_concat : /*empty*/ |
---|
58 | | CONCAT pattern |
---|
59 | ; |
---|
60 | |
---|
61 | pattern_list_rest : /*empty*/ |
---|
62 | | COMMA pattern pattern_list_rest |
---|
63 | ; |
---|
64 | |
---|
65 | function_type : concept_name concept_list_rest TO concept_name ; |
---|
66 | |
---|
67 | concept_list_rest : /*empty*/ |
---|
68 | | ASTERISK concept_name concept_list_rest |
---|
69 | ; |
---|
70 | |
---|
71 | concept_name : IDENTIFIER ; |
---|
72 | funname : IDENTIFIER ; |
---|
73 | variable : IDENTIFIER ; |
---|
74 | |
---|
75 | exp : STRING exp_concat |
---|
76 | | UNDEFINED exp_concat |
---|
77 | | IDENTIFIER exp_var_or_func exp_concat |
---|
78 | | LPAR exp_with_where RPAR exp_concat |
---|
79 | | IF exp THEN exp ELSE exp |
---|
80 | ; |
---|
81 | |
---|
82 | exp_with_where : STRING exp_concat_or_where |
---|
83 | | UNDEFINED exp_concat_or_where |
---|
84 | | IDENTIFIER exp_var_or_func exp_concat_or_where |
---|
85 | | LPAR exp_with_where RPAR exp_concat_or_where |
---|
86 | | IF exp_with_where THEN exp_with_where ELSE exp_with_where |
---|
87 | ; |
---|
88 | |
---|
89 | exp_var_or_func : /*empty*/ |
---|
90 | | LPAR arg_list RPAR |
---|
91 | ; |
---|
92 | |
---|
93 | arg_list : /*empty*/ |
---|
94 | | exp arg_list_rest |
---|
95 | ; |
---|
96 | |
---|
97 | arg_list_rest : /*empty*/ |
---|
98 | | COMMA exp arg_list_rest |
---|
99 | ; |
---|
100 | |
---|
101 | exp_concat : /*empty*/ |
---|
102 | | CONCAT exp |
---|
103 | ; |
---|
104 | |
---|
105 | exp_concat_or_where : /*empty*/ |
---|
106 | | CONCAT exp_with_where |
---|
107 | | WHERE varassign_list |
---|
108 | ; |
---|
109 | |
---|
110 | varassign_list : variable EQ exp varassign_rest ; |
---|
111 | |
---|
112 | varassign_rest : /*empty*/ |
---|
113 | | COMMA varassign_list |
---|
114 | ; |
---|