paper/src/bison_config1.txt
author Eugen Sawin <sawine@me73.com>
Mon, 28 Mar 2011 23:38:01 +0200
changeset 11 a72716252271
permissions -rw-r--r--
Minor.
     1 %token
     2 CONSTRNT PATTERN FLOWP COM
     3 QUOTE THAN FROM UNTIL ON
     4 
     5 %union
     6 {
     7 	int integer;
     8 	double real;
     9 	const char* string;
    10 }
    11 
    12 %token <integer> INTEGER
    13 %token <integer> TIME
    14 %token <real> 	REAL
    15 %token <string> STRING
    16 
    17 
    18 %token <integer> IS 
    19 %token <integer> IN 
    20 %token <integer> GREATER 
    21 %token <integer> LESS 
    22 %token <integer> NOT 
    23 %token <integer> AND 
    24 %token <integer> OR 
    25 %token <integer> AT
    26 %token <integer> COPX
    27 %token <integer> ADEP
    28 %token <integer> ADES
    29 %token <integer> RWY
    30 %token <integer> ROUTE
    31 %token <integer> ATYP
    32 %token <integer> FLVL
    33 %token <integer> TAS
    34 %token <integer> FRUL
    35 %token <integer> FTYP
    36 %token <integer> EQUIP
    37 %token <integer> RFL
    38 %token <integer> TRAVEL_TYPE
    39 %token <integer> TIMESEP 
    40 %token <integer> FL
    41 
    42 %type <string> string
    43 %type <string> pttrn
    44 %type <string> flowp
    45 %type <string> constrnt
    46 %type <integer> int
    47 %type <integer> string_array
    48 %type <integer> int_array
    49 %type <integer> int_pt
    50 %type <integer> char_pt
    51 %type <integer> string_pt
    52 %type <integer> string_array_pt
    53 %type <integer> char_array_pt
    54 %type <integer> int_op
    55 %type <integer> string_op
    56 %type <integer> string_array_op
    57 %type <integer> string_string_array_op
    58 %type <integer> si_unit
    59 
    60 %left OR
    61 %left AND
    62 %right NOT
    63 
    64 %%
    65 prog:			| prog rule {  }
    66 				| error ')' { yyerrok; yyclearin;}				
    67 ;
    68 
    69 rule:			pttrn 		{ if (!pattern($1)) printf("Error: %s\n", last_error()); }
    70 				| constrnt 	{ if (!constraint($1)) printf("Error: %s\n", last_error()); }
    71 				| flowp 	{ if (!flowpoint($1)) printf("Error: %s\n", last_error()); }
    72 				| COM		{ comment(); }
    73 ;
    74 
    75 flowp:			FLOWP STRING '(' flowp_entry ')'	{ $$ = $2; }
    76 ;
    77 
    78 flowp_entry:	pttrn_lbl ':' constrnt_lbl					
    79 ;
    80 
    81 pttrn_lbl:		STRING						{ if (!pattern_id($1)) printf("Error: %s\n", last_error()); }						
    82 ;
    83 
    84 constrnt_lbl:	STRING	{ if (!constraint_id($1)) printf("Error: %s\n", last_error()); }
    85 ;
    86 
    87 constrnt:		CONSTRNT STRING '(' cterm ')' 	{ $$ = $2; }
    88 ;
    89 
    90 cterm:			TIMESEP AT string IS INTEGER si_unit		
    91 				{ intpt_string_int_cterm(PT_TIMESEP, $3, $5 * $6, 0, 0, 0); }				
    92 				| TIMESEP AT string_array IS INTEGER si_unit
    93 				{ intpt_stringarray_int_cterm(PT_TIMESEP, $3, $5 * $6, 0, 0, 0); }		
    94 				| TIMESEP AT string IS INTEGER si_unit FROM INTEGER UNTIL INTEGER	
    95 				{ intpt_string_int_cterm(PT_TIMESEP, $3, $5 * $6, $8, $10, 0); }				
    96 				| TIMESEP AT string_array IS INTEGER si_unit FROM INTEGER UNTIL INTEGER
    97 				{ intpt_stringarray_int_cterm(PT_TIMESEP, $3, $5 * $6, $8, $10, 0); }		
    98 				
    99 				| TIMESEP AT string IS INTEGER si_unit AT FL int_array
   100 				{ intpt_string_int_cterm(PT_TIMESEP, $3, $5 * $6, 0, 0, $9); }				
   101 				| TIMESEP AT string_array IS INTEGER si_unit AT FL int_array
   102 				{ intpt_stringarray_int_cterm(PT_TIMESEP, $3, $5 * $6, 0, 0, $9); }		
   103 				| TIMESEP AT string IS INTEGER si_unit FROM INTEGER UNTIL INTEGER AT FL int_array	
   104 				{ intpt_string_int_cterm(PT_TIMESEP, $3, $5 * $6, $8, $10, $13); }				
   105 				| TIMESEP AT string_array IS INTEGER si_unit FROM INTEGER UNTIL INTEGER AT FL int_array
   106 				{ intpt_stringarray_int_cterm(PT_TIMESEP, $3, $5 * $6, $8, $10, $13); }	
   107 									
   108 				| cterm AND cterm							
   109 				{ and_term(); }
   110 ;
   111 
   112 si_unit:		STRING	
   113 				{ 
   114 					if (!strcmp($1, "s")) { $$ = 1; }
   115 					else if (!strcmp($1, "min")) { $$ = 60; }
   116 				}
   117 ;
   118 
   119 pttrn: 			PATTERN STRING '(' term ')'	{ $$ = $2; }
   120 				| PATTERN '(' term ')'		{ $$ = get_pattern_id(); }
   121 ;
   122 
   123 term:			int_pt int_op INTEGER	
   124 				{ intpt_int_term($2, $1, $3); }	
   125 					
   126 				| char_pt string_op string
   127 				{ charpt_char_term($2, $1, $3); }
   128 						
   129 				| string_pt string_op string
   130 				{ stringpt_string_term($2, $1, $3); }
   131 				
   132 				| string_array_pt string_array_op string_array
   133 				{ stringarraypt_stringarray_term($2, $1, $3); }	
   134 							
   135 				| string_array string_array_op string_array_pt
   136 				{ 
   137 					if ($2 == OT_IN_C)
   138 					{
   139 						$2 = OT_IN_P;
   140 					}
   141 					else if ($2 == OT_NOTIN_C)
   142 					{
   143 						$2 = OT_NOTIN_P;
   144 					}
   145 					stringarraypt_stringarray_term($2, $3, $1); 
   146 				}			
   147 					
   148 				| string string_string_array_op string_array_pt
   149 				{ 
   150 					if ($2 == OT_IN_C)
   151 					{
   152 						$2 = OT_IN_P;
   153 					}
   154 					else if ($2 == OT_NOTIN_C)
   155 					{
   156 						$2 = OT_NOTIN_P;
   157 					} 
   158 					stringarraypt_string_term($2, $3, $1); 
   159 				}		
   160 				
   161 				| string string_string_array_op char_array_pt
   162 				{ 
   163 					if ($2 == OT_IN_C)
   164 					{
   165 						$2 = OT_IN_P;
   166 					}
   167 					else if ($2 == OT_NOTIN_C)
   168 					{
   169 						$2 = OT_NOTIN_P;
   170 					} 
   171 					chararraypt_char_term($2, $3, $1); 
   172 				}	
   173 							
   174 				| term OR term 		
   175 				{ or_term(); }
   176 				
   177 				| term AND term
   178 				{ and_term(); } 	
   179 				
   180 				| NOT term						
   181 				| '(' term ')'				
   182 ;
   183 
   184 int_op:			IS 				{ $$ = OT_IS; }	
   185 				| IS NOT		{ $$ = OT_ISNOT; } 
   186 				| GREATER THAN	{ $$ = OT_GREATER; }
   187 				| LESS THAN		{ $$ = OT_LESS; }
   188 ;
   189 
   190 string_op:		IS			{ $$ = OT_IS; }	
   191 				| IS NOT	{ $$ = OT_ISNOT; } 
   192 ;
   193 
   194 string_array_op:IS			{ $$ = OT_IS; }
   195 				| IS NOT 	{ $$ = OT_ISNOT; } 
   196 				| IN 		{ $$ = OT_IN_P; }
   197 				| NOT IN	{ $$ = OT_NOTIN_P; }
   198 ;
   199 
   200 string_string_array_op: IN 			{ $$ = OT_IN_P; }
   201 						| NOT IN	{ $$ = OT_NOTIN_P; }
   202 ;
   203 
   204 int_array:		'[' ints ']' { $$ = integer_array(); }
   205 ;
   206 
   207 ints:			| ints ',' int
   208 				| ints int
   209 ;
   210 
   211 int:		INTEGER { integer($1); $$ = $1; }
   212 ; 
   213 
   214 string_array:	'[' strings ']'	{ $$ = string_array(); }
   215 ;
   216 
   217 strings:		| strings ',' string
   218 				| strings string
   219 ;
   220 
   221 int_pt:			TAS		{ $$ = PT_TAS; }			
   222 ;
   223 
   224 char_pt:		FTYP		{ $$ = PT_FTYP; }
   225 
   226 string_pt:		ADEP	{ $$ = PT_ADEP; }
   227 				| ADES	{ $$ = PT_ADES; }
   228 				| RWY 	{ $$ = PT_RWY; }
   229 				| ATYP 	{ $$ = PT_ATYP; }
   230 				| COPX	{ $$ = PT_COPX; }				
   231 				| FRUL 	{ $$ = PT_FRUL; }				
   232 				| RFL	{ $$ = PT_RFL; }
   233 				| TRAVEL_TYPE { $$ = PT_TRAVEL_TYPE; }
   234 ;
   235 
   236 string_array_pt:ROUTE	{ $$ = PT_ROUTE; }				
   237 ;
   238 
   239 char_array_pt:	EQUIP	{ $$ = PT_EQUIP; }
   240 ;
   241 
   242 string:			QUOTE STRING QUOTE	{ string($2); $$ = $2; }
   243 ;