parser.y

Sun, 30 Dec 2001 04:16:46 +0000

author
eric
date
Sun, 30 Dec 2001 04:16:46 +0000
changeset 15
dda3d673b82b
parent 12
c3e2c2344560
child 17
d4699dfddcc0
permissions
-rw-r--r--

*** empty log message ***

     1 %{
     2   #include <stdio.h>
     3   #include "type.h"
     4   #include "tiff2pdf.h"
     5 %}
     7 %union {
     8   int integer;
     9   double fp;
    10   char *string;
    11   struct { double width; double height; } size;
    12   struct { int first; int last; } 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  ';'  { open_tiff_input_file ($2) } ;
    79 image_clause:
    80 	IMAGE INTEGER ';' { input_images ($2, $2); }
    81 	| IMAGE INTEGER modifier_clause_list ';' { input_images ($2, $2); } ;
    83 images_clause:
    84 	IMAGES image_ranges ';'
    85 	| IMAGES image_ranges modifier_clause_list ';'
    86 	| IMAGES image_ranges part_clauses ';' ;
    88 rotate_clause:
    89 	ROTATE INTEGER ';' ;
    91 unit:
    92 	/* empty */  /* default to INCH */ { $$ = 25.4; }
    93 	| CM { $$ = 1.0; }
    94 	| INCH { $$ = 25.4; } ;
    96 length:
    97 	FLOAT unit { $$ = $1 * $2; } ;
    99 crop_clause:
   100 	CROP PAGE_SIZE ';'
   101 	| CROP PAGE_SIZE orientation ';'
   102 	| CROP length ',' length ';'
   103 	| CROP length ',' length ',' length ',' length ';' ;
   105 orientation:
   106 	PORTRAIT
   107 	| LANDSCAPE ;
   109 size_clause:
   110 	SIZE PAGE_SIZE ';'
   111 	| SIZE PAGE_SIZE orientation ';'
   112 	| SIZE length ',' length ';' ;
   114 resolution_clause:
   115 	RESOLUTION FLOAT unit ;
   117 modifier_clause:
   118 	rotate_clause | crop_clause | size_clause | resolution_clause;
   120 modifier_clauses:
   121 	modifier_clause
   122 	| modifier_clauses modifier_clause;
   124 modifier_clause_list:
   125 	'{' modifier_clauses '}' ;
   127 part:
   128 	EVEN | ODD | ALL ;
   130 part_clause:
   131 	part modifier_clause_list;
   133 part_clauses:
   134 	part_clause
   135 	| part_clauses part_clause;
   137 input_clause:
   138 	input_file_clause
   139 	| image_clause
   140 	| images_clause
   141 	| modifier_clause
   142 	| input_clause_list ;
   144 input_clauses:
   145 	input_clause
   146 	| input_clauses input_clause ;
   148 input_clause_list:
   149 	'{' input_clauses '}' ;
   151 input_statement:
   152 	INPUT input_clauses ;
   154 output_file_clause:
   155 	FILE_KEYWORD STRING  ';' { open_pdf_output_file ($2) } ;
   157 page_ranges:
   158 	range { output_pages ($1.first, $1.last); }
   159 	| page_ranges ',' range { output_pages ($3.first, $3.last); } ;
   161 page_clause:
   162 	PAGE INTEGER ';' { output_pages ($2, $2); }
   163 	| PAGE STRING ',' INTEGER ';' { output_pages ($4, $4); } ;
   165 pages_clause:
   166 	PAGES page_ranges ';'
   167 	| PAGES STRING ',' page_ranges ';' ;
   169 bookmark_clause:
   170 	BOOKMARK INTEGER ',' STRING ';'
   171 	| BOOKMARK STRING ';' ;
   173 output_clause:
   174 	output_file_clause
   175 	| page_clause | pages_clause
   176 	| bookmark_clause
   177 	| output_clause_list ;
   179 output_clauses:
   180 	output_clause
   181 	| output_clauses output_clause ;
   183 output_clause_list:
   184 	'{' output_clauses '}' ;
   186 output_statement:
   187 	OUTPUT output_clauses ;