parser.y

Mon, 31 Dec 2001 07:25:08 +0000

author
eric
date
Mon, 31 Dec 2001 07:25:08 +0000
changeset 20
a1cd8cb9d09e
parent 19
e9bf1ed4f331
child 27
7a28031fe457
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 FORMAT
    42 %token PAGE
    43 %token PAGES
    44 %token BOOKMARK
    45 %token OUTPUT
    47 %type <range> range
    48 %type <range> image_ranges
    49 %type <range> page_ranges
    51 %type <fp> unit
    55 %type <fp> length
    57 %%
    59 statements: 
    60 	statement
    61 	| statements statement ;
    63 statement:
    64 	input_statement
    65 	| output_statement ;
    68 range:
    69 	INTEGER ELIPSIS INTEGER { $$.first = $1; $$.last = $3; }
    70 	| INTEGER { $$.first = $1; $$.last = $1; } ;
    72 image_ranges:
    73 	range { input_images ($1); }
    74 	| image_ranges ',' range { input_images ($3); } ;
    77 input_file_clause:
    78 	FILE_KEYWORD STRING  ';'  { input_set_file ($2) } ;
    80 image_clause:
    81 	IMAGE INTEGER ';' { range_t range = { $2, $2 }; input_images (range); } ;
    83 images_clause:
    84 	IMAGES image_ranges ';' ;
    86 rotate_clause:
    87 	ROTATE INTEGER ';' { input_set_rotation ($2) } ;
    89 unit:
    90 	/* empty */  /* default to INCH */ { $$ = 25.4; }
    91 	| CM { $$ = 1.0; }
    92 	| INCH { $$ = 25.4; } ;
    94 length:
    95 	FLOAT unit { $$ = $1 * $2; } ;
    97 crop_clause:
    98 	CROP PAGE_SIZE ';'
    99 	| CROP PAGE_SIZE orientation ';'
   100 	| CROP length ',' length ';'
   101 	| CROP length ',' length ',' length ',' length ';' ;
   103 orientation:
   104 	PORTRAIT
   105 	| LANDSCAPE ;
   107 size_clause:
   108 	SIZE PAGE_SIZE ';'
   109 	| SIZE PAGE_SIZE orientation ';'
   110 	| SIZE length ',' length ';' ;
   112 resolution_clause:
   113 	RESOLUTION FLOAT unit ;
   115 modifier_clause:
   116 	rotate_clause | crop_clause | size_clause | resolution_clause;
   118 modifier_clauses:
   119 	modifier_clause
   120 	| modifier_clauses modifier_clause;
   122 modifier_clause_list:
   123 	'{' modifier_clauses '}' ;
   125 part_clause:
   126 	ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); }
   127           modifier_clause_list ';'
   128           { input_set_modifier_context (INPUT_MODIFIER_ALL); }
   129 	| EVEN { input_set_modifier_context (INPUT_MODIFIER_EVEN); }
   130 	  modifier_clause_list ';'
   131           { input_set_modifier_context (INPUT_MODIFIER_ALL); } ;
   133 input_clause:
   134 	input_file_clause
   135 	| image_clause
   136 	| images_clause
   137 	| part_clause
   138 	| modifier_clause
   139 	| input_clause_list ;
   141 input_clauses:
   142 	input_clause
   143 	| input_clauses input_clause ;
   145 input_clause_list:
   146 	'{' input_clauses '}' ;
   148 input_statement:
   149 	INPUT input_clauses ;
   151 output_file_clause:
   152 	FILE_KEYWORD STRING  ';' { output_set_file ($2) } ;
   154 format_clause:
   155 	FORMAT STRING ';' { output_set_page_number_format ($2) } ;
   157 page_ranges:
   158 	range { output_pages ($1); }
   159 	| page_ranges ',' range { output_pages ($3); } ;
   161 page_clause:
   162 	PAGE INTEGER ';' { range_t range = { $2, $2 }; output_pages (range); } ;
   164 pages_clause:
   165 	PAGES page_ranges ';' ;
   167 bookmark_name:
   168 	STRING { output_set_bookmark ($1); } ;
   170 bookmark_name_list:
   171 	bookmark_name
   172 	| bookmark_name_list ',' bookmark_name ;
   174 bookmark_clause:
   175 	BOOKMARK { output_push_context (); }
   176 	bookmark_name_list
   177 	output_clause_list ';' { output_pop_context (); } ;
   179 output_clause:
   180 	output_file_clause
   181 	| format_clause
   182 	| page_clause | pages_clause
   183 	| bookmark_clause
   184 	| output_clause_list ;
   186 output_clauses:
   187 	output_clause
   188 	| output_clauses output_clause ;
   190 output_clause_list:
   191 	'{' { output_push_context (); }
   192 	output_clauses '}' { output_pop_context (); } ;
   194 output_statement:
   195 	OUTPUT output_clauses ;