Final version.
5 #include "semantic_helper.hh"
7 #define MAX_ID_TABLE_NO 1024
8 char* id_table[MAX_ID_TABLE_NO];
15 int yyerror(const char *str);
16 void yyrestart(FILE* file);
19 CONSTRNT PATTERN FLOWP COM
20 QUOTE THAN FROM UNTIL ON
29 %token <integer> INTEGER
32 %token <string> STRING
35 %token <integer> GREATER
43 %token <integer> INTERNAL
44 %token <integer> GLOBAL
48 %token <integer> ROUTE
54 %token <integer> EQUIP
56 %token <integer> TRAVEL_TYPE
57 %token <integer> TIMESEP
58 %token <integer> DEPTIME
59 %token <integer> ARRTIME
60 %token <integer> GATETIME
65 %type <string> constrnt
67 %type <integer> string_array
68 %type <integer> int_array
69 %type <integer> int_pt
70 %type <integer> time_pt
71 %type <integer> char_pt
72 %type <integer> string_pt
73 %type <integer> string_array_pt
74 %type <integer> char_array_pt
75 %type <integer> int_op
76 %type <integer> string_op
77 %type <integer> string_array_op
78 %type <integer> string_string_array_op
79 %type <integer> si_unit
86 | error ')' { yyerrok; yyclearin;}
88 rule: pttrn { if (!pattern($1))
89 printf("Error: %s\n", last_error()); }
90 | constrnt { if (!constraint($1))
91 printf("Error: %s\n", last_error()); }
92 | flowp { if (!flowpoint($1))
93 printf("Error: %s\n", last_error()); }
96 flowp: FLOWP STRING '(' flowp_entry ')' { $$ = $2; }
98 flowp_entry: pttrn_lbl ':' constrnt_lbl
100 pttrn_lbl: STRING { if (!pattern_id($1))
101 printf("Error: %s\n", last_error()); }
103 constrnt_lbl: STRING { if (!constraint_id($1))
104 printf("Error: %s\n", last_error()); }
106 constrnt: CONSTRNT STRING '(' cterm ')' { $$ = $2; }
108 cterm: TIMESEP AT string IS INTEGER si_unit
109 { intpt_string_int_cterm(PT_TIMESEP, $3, $5 * $6,
111 | TIMESEP AT string_array IS INTEGER si_unit
112 { intpt_stringarray_int_cterm(PT_TIMESEP, $3, $5 * $6,
114 | TIMESEP AT string IS INTEGER si_unit
115 FROM INTEGER UNTIL INTEGER
116 { intpt_string_int_cterm(PT_TIMESEP, $3, $5 * $6, $8,
118 | TIMESEP AT string_array IS INTEGER si_unit
119 FROM INTEGER UNTIL INTEGER
120 { intpt_stringarray_int_cterm(PT_TIMESEP, $3, $5 * $6,
122 | TIMESEP AT string IS INTEGER si_unit AT FL int_array
123 { intpt_string_int_cterm(PT_TIMESEP, $3, $5 * $6,
125 | TIMESEP AT string_array IS INTEGER si_unit
127 { intpt_stringarray_int_cterm(PT_TIMESEP, $3, $5 * $6,
129 | TIMESEP AT string IS INTEGER si_unit
130 FROM INTEGER UNTIL INTEGER AT FL int_array
131 { intpt_string_int_cterm(PT_TIMESEP, $3, $5 * $6, $8,
133 | TIMESEP AT string_array IS INTEGER si_unit
134 FROM INTEGER UNTIL INTEGER AT FL int_array
135 { intpt_stringarray_int_cterm(PT_TIMESEP, $3, $5 * $6,
137 | cterm AND cterm { and_term(); }
139 si_unit: STRING { if (!strcmp($1, "s")) { $$ = 1; }
140 else if (!strcmp($1, "min")) { $$ = 60; } }
142 pttrn: PATTERN STRING '(' term ')' { $$ = $2; }
143 | PATTERN '(' term ')' { $$ = get_pattern_id(); }
145 term: int_pt int_op INTEGER
146 { intpt_int_term($2, $1, $3); }
147 | time_pt int_op INTEGER
148 { time_pt_int_term($2, $1, $3); }
149 | char_pt string_op string
150 { charpt_char_term($2, $1, $3); }
151 | string_pt string_op string
152 { stringpt_string_term($2, $1, $3); }
153 | string_array_pt string_array_op string_array
154 { stringarraypt_stringarray_term($2, $1, $3); }
155 | string_array string_array_op string_array_pt
156 { if ($2 == OT_IN_C) { $2 = OT_IN_P; }
157 else if ($2 == OT_NOTIN_C) { $2 = OT_NOTIN_P; }
158 stringarraypt_stringarray_term($2, $3, $1); }
159 | string string_string_array_op string_array_pt
160 { if ($2 == OT_IN_C) { $2 = OT_IN_P; }
161 else if ($2 == OT_NOTIN_C) { $2 = OT_NOTIN_P; }
162 stringarraypt_string_term($2, $3, $1); }
163 | string string_string_array_op char_array_pt
164 { if ($2 == OT_IN_C) { $2 = OT_IN_P; }
165 else if ($2 == OT_NOTIN_C) { $2 = OT_NOTIN_P; }
166 chararraypt_char_term($2, $3, $1); }
167 | term OR term { or_term(); }
168 | term AND term { and_term(); }
172 int_op: IS { $$ = OT_IS; }
173 | IS NOT { $$ = OT_ISNOT; }
174 | GREATER THAN { $$ = OT_GREATER; }
175 | LESS THAN { $$ = OT_LESS; }
177 string_op: IS { $$ = OT_IS; }
178 | IS NOT { $$ = OT_ISNOT; }
180 string_array_op: IS { $$ = OT_IS; }
181 | IS NOT { $$ = OT_ISNOT; }
182 | IN { $$ = OT_IN_P; }
183 | NOT IN { $$ = OT_NOTIN_P; }
185 string_string_array_op: IN { $$ = OT_IN_P; }
186 | NOT IN { $$ = OT_NOTIN_P; }
188 int_array: '[' ints ']' { $$ = integer_array(); }
193 int: INTEGER { integer($1); $$ = $1; }
195 string_array: '[' strings ']' { $$ = string_array(); }
197 strings: | strings ',' string
200 int_pt: TAS { $$ = PT_TAS; }
201 | INTERNAL { $$ = PT_INTERNAL; }
202 | GLOBAL { $$ = PT_GLOBAL; }
204 time_pt: DEPTIME { $$ = PT_DEPTIME; }
205 | ARRTIME { $$ = PT_ARRTIME; }
206 | GATETIME { $$ = PT_GATETIME; }
208 char_pt: FTYP { $$ = PT_FTYP; }
210 string_pt: ADEP { $$ = PT_ADEP; }
211 | ADES { $$ = PT_ADES; }
212 | RWY { $$ = PT_RWY; }
213 | ATYP { $$ = PT_ATYP; }
214 | COPX { $$ = PT_COPX; }
215 | GATE { $$ = PT_GATE; }
216 | FRUL { $$ = PT_FRUL; }
217 | RFL { $$ = PT_RFL; }
218 | TRAVEL_TYPE { $$ = PT_TRAVEL_TYPE; }
220 string_array_pt: ROUTE { $$ = PT_ROUTE; }
222 char_array_pt: EQUIP { $$ = PT_EQUIP; }
224 string: QUOTE STRING QUOTE { string($2); $$ = $2; }
227 #include "atccl_parser.c"
228 void clear_id_table()
231 for (i = 0; i < id_table_no; ++i)
243 int semantic_error(const char* str)
245 if (errorNo < maxErrorNo)
247 errors[errorNo].line = -1;
248 strcpy(errors[errorNo].text, "");
249 strcpy(errors[errorNo].error, str);
254 int yyerror(const char *str)
256 if (errorNo < maxErrorNo)
258 errors[errorNo].line = line_no;
259 strcpy(errors[errorNo].text, yytext);
260 strcpy(errors[errorNo].error, str);
265 int parse_syntax(FILE* file, ErrorType* errors_,
266 int maxErrorNo_, int passes)
270 maxErrorNo = maxErrorNo_;
279 if (!complete_semantics())
281 semantic_error(last_error());