parser.y

Mon, 31 Dec 2001 02:33:50 +0000

author
eric
date
Mon, 31 Dec 2001 02:33:50 +0000
changeset 19
e9bf1ed4f331
parent 18
3de372e4b230
child 20
a1cd8cb9d09e
permissions
-rw-r--r--

*** empty log message ***

     1 %{
     2   #include <stdio.h>
     3   #include "type.h"
     4   #include "semantics.h"
     5 %}
     7 %union {
     8   int integer;
     9   double fp;
    10   char *string;
    11   page_size_t size;
    12   range_t range;
    13 }
    15 %token <integer> INTEGER
    16 %token <fp> FLOAT
    17 %token <string> STRING
    18 %token <size> PAGE_SIZE
    20 %token ELIPSIS
    22 %token CM
    23 %token INCH
    25 %token EVEN
    26 %token ODD
    27 %token ALL
    29 %token PORTRAIT
    30 %token LANDSCAPE
    32 %token FILE_KEYWORD
    33 %token IMAGE
    34 %token IMAGES
    35 %token ROTATE
    36 %token CROP
    37 %token SIZE
    38 %token RESOLUTION
    39 %token INPUT
    41 %token PAGE
    42 %token PAGES
    43 %token BOOKMARK
    44 %token OUTPUT
    46 %type <range> range
    47 %type <range> image_ranges
    48 %type <range> page_ranges
    50 %type <fp> unit
    54 %type <fp> length
    56 %%
    58 statements: 
    59 	statement
    60 	| statements statement ;
    62 statement:
    63 	input_statement
    64 	| output_statement ;
    67 range:
    68 	INTEGER ELIPSIS INTEGER { $$.first = $1; $$.last = $3; }
    69 	| INTEGER { $$.first = $1; $$.last = $1; } ;
    71 image_ranges:
    72 	range { input_images ($1.first, $1.last); }
    73 	| image_ranges ',' range { input_images ($3.first, $3.last); } ;
    76 input_file_clause:
    77 	FILE_KEYWORD STRING  ';'  { input_set_file ($2) } ;
    79 image_clause:
    80 	IMAGE INTEGER ';' { input_images ($2, $2); } ;
    82 images_clause:
    83 	IMAGES image_ranges ';' ;
    85 rotate_clause:
    86 	ROTATE INTEGER ';' { input_set_rotation ($2) };
    88 unit:
    89 	/* empty */  /* default to INCH */ { $$ = 25.4; }
    90 	| CM { $$ = 1.0; }
    91 	| INCH { $$ = 25.4; } ;
    93 length:
    94 	FLOAT unit { $$ = $1 * $2; } ;
    96 crop_clause:
    97 	CROP PAGE_SIZE ';'
    98 	| CROP PAGE_SIZE orientation ';'
    99 	| CROP length ',' length ';'
   100 	| CROP length ',' length ',' length ',' length ';' ;
   102 orientation:
   103 	PORTRAIT
   104 	| LANDSCAPE ;
   106 size_clause:
   107 	SIZE PAGE_SIZE ';'
   108 	| SIZE PAGE_SIZE orientation ';'
   109 	| SIZE length ',' length ';' ;
   111 resolution_clause:
   112 	RESOLUTION FLOAT unit ;
   114 modifier_clause:
   115 	rotate_clause | crop_clause | size_clause | resolution_clause;
   117 modifier_clauses:
   118 	modifier_clause
   119 	| modifier_clauses modifier_clause;
   121 modifier_clause_list:
   122 	'{' modifier_clauses '}' ;
   124 part_clause:
   125 	ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); }
   126           modifier_clause_list ';'
   127           { input_set_modifier_context (INPUT_MODIFIER_ALL); }
   128 	| EVEN { input_set_modifier_context (INPUT_MODIFIER_ODD); }
   129 	  modifier_clause_list ';'
   130           { input_set_modifier_context (INPUT_MODIFIER_ALL); } ;
   132 input_clause:
   133 	input_file_clause
   134 	| image_clause
   135 	| images_clause
   136 	| part_clause
   137 	| modifier_clause
   138 	| input_clause_list ;
   140 input_clauses:
   141 	input_clause
   142 	| input_clauses input_clause ;
   144 input_clause_list:
   145 	'{' input_clauses '}' ;
   147 input_statement:
   148 	INPUT input_clauses ;
   150 output_file_clause:
   151 	FILE_KEYWORD STRING  ';' { output_set_file ($2) } ;
   153 page_ranges:
   154 	range { output_pages ($1.first, $1.last); }
   155 	| page_ranges ',' range { output_pages ($3.first, $3.last); } ;
   157 page_clause:
   158 	PAGE INTEGER ';' { output_pages ($2, $2); }
   159 	| PAGE STRING ',' INTEGER ';' { output_pages ($4, $4); } ;
   161 pages_clause:
   162 	PAGES page_ranges ';'
   163 	| PAGES STRING ',' page_ranges ';' ;
   165 bookmark_clause:
   166 	BOOKMARK INTEGER ',' STRING ';'
   167 	| BOOKMARK STRING ';' ;
   169 output_clause:
   170 	output_file_clause
   171 	| page_clause | pages_clause
   172 	| bookmark_clause
   173 	| output_clause_list ;
   175 output_clauses:
   176 	output_clause
   177 	| output_clauses output_clause ;
   179 output_clause_list:
   180 	'{' output_clauses '}' ;
   182 output_statement:
   183 	OUTPUT output_clauses ;