parser.y

Thu, 20 Feb 2003 12:20:28 +0000

author
eric
date
Thu, 20 Feb 2003 12:20:28 +0000
changeset 60
ffb5b1e54eb2
parent 48
3d0be1c1c1b2
child 63
6eddf63aa517
permissions
-rw-r--r--

fix includes.

     1 %{
     2   #include <stdbool.h>
     3   #include <stdint.h>
     4   #include <stdio.h>
     5   #include "semantics.h"
     6 %}
     8 %union {
     9   int integer;
    10   char character;
    11   double fp;
    12   char *string;
    13   page_size_t size;
    14   range_t range;
    15   page_label_t page_label;
    16 }
    18 %token <integer> INTEGER
    19 %token <fp> FLOAT
    20 %token <string> STRING
    21 %token <character> CHARACTER
    22 %token <size> PAGE_SIZE
    24 %token ELIPSIS
    26 %token CM
    27 %token INCH
    29 %token EVEN
    30 %token ODD
    31 %token ALL
    33 %token PORTRAIT
    34 %token LANDSCAPE
    36 %token FILE_KEYWORD
    37 %token IMAGE
    38 %token IMAGES
    39 %token ROTATE
    40 %token CROP
    41 %token SIZE
    42 %token RESOLUTION
    43 %token INPUT
    45 %token LABEL
    46 %token PAGE
    47 %token PAGES
    48 %token BOOKMARK
    49 %token OUTPUT
    51 %token AUTHOR
    52 %token CREATOR
    53 %token TITLE
    54 %token SUBJECT
    55 %token KEYWORDS
    57 %type <range> range
    58 %type <range> image_ranges
    59 %type <range> page_ranges
    61 %type <fp> unit
    63 %type <fp> length
    65 %type <integer> orientation
    67 %type <size> page_size
    69 %%
    71 statements: 
    72 	statement
    73 	| statements statement ;
    75 statement:
    76 	input_statement
    77 	| output_statement ;
    80 range:
    81 	INTEGER ELIPSIS INTEGER { $$.first = $1; $$.last = $3; }
    82 	| INTEGER { $$.first = $1; $$.last = $1; } ;
    84 image_ranges:
    85 	range { input_images ($1); }
    86 	| image_ranges ',' range { input_images ($3); } ;
    89 input_file_clause:
    90 	FILE_KEYWORD STRING  ';'  { input_set_file ($2) } ;
    92 image_clause:
    93 	IMAGE INTEGER ';' { range_t range = { $2, $2 }; input_images (range); } ;
    95 images_clause:
    96 	IMAGES image_ranges ';' ;
    98 rotate_clause:
    99 	ROTATE INTEGER ';' { input_set_rotation ($2) } ;
   101 unit:
   102 	/* empty */  /* default to INCH */ { $$ = 1.0; }
   103 	| CM { $$ = (1.0 / 25.4); }
   104 	| INCH { $$ = 1.0; } ;
   106 length:
   107 	FLOAT unit { $$ = $1 * $2; } ;
   109 crop_clause:
   110 	CROP PAGE_SIZE ';'
   111 	| CROP PAGE_SIZE orientation ';'
   112 	| CROP length ',' length ';'
   113 	| CROP length ',' length ',' length ',' length ';' ;
   115 orientation:
   116 	PORTRAIT { $$ = 0; }
   117 	| LANDSCAPE { $$ = 1; } ;
   119 page_size:
   120 	PAGE_SIZE { $$ = $1; }
   121 	| PAGE_SIZE orientation { if ($2)
   122                                     {
   123                                       $$.width = $1.height;
   124 				      $$.height = $1.width;
   125                                     }
   126                                   else
   127                                     $$ = $1;
   128                                 }
   129 	| length ',' length { $$.width = $1; $$.height = $3; } ;
   131 size_clause:
   132 	SIZE page_size ';' { input_set_page_size ($2); } ;
   134 resolution_clause:
   135 	RESOLUTION FLOAT unit ;
   137 modifier_clause:
   138 	rotate_clause | crop_clause | size_clause | resolution_clause;
   140 modifier_clauses:
   141 	modifier_clause
   142 	| modifier_clauses modifier_clause;
   144 modifier_clause_list:
   145 	'{' modifier_clauses '}' ;
   147 part_clause:
   148 	ODD { input_set_modifier_context (INPUT_MODIFIER_ODD); }
   149           modifier_clause_list ';'
   150           { input_set_modifier_context (INPUT_MODIFIER_ALL); }
   151 	| EVEN { input_set_modifier_context (INPUT_MODIFIER_EVEN); }
   152 	  modifier_clause_list ';'
   153           { input_set_modifier_context (INPUT_MODIFIER_ALL); } ;
   155 input_clause:
   156 	input_file_clause
   157 	| image_clause
   158 	| images_clause
   159 	| part_clause
   160 	| modifier_clause
   161 	| input_clause_list ;
   163 input_clauses:
   164 	input_clause
   165 	| input_clauses input_clause ;
   167 input_clause_list:
   168 	'{' input_clauses '}' ;
   170 input_statement:
   171 	INPUT input_clauses ;
   173 pdf_file_attribute:
   174 	AUTHOR STRING { output_set_author ($2); }
   175 	| CREATOR STRING { output_set_creator ($2); }
   176 	| TITLE STRING { output_set_title ($2); }
   177 	| SUBJECT STRING { output_set_subject ($2); }
   178 	| KEYWORDS STRING { output_set_keywords ($2); } ;
   180 pdf_file_attribute_list:
   181 	pdf_file_attribute
   182 	| pdf_file_attribute_list pdf_file_attribute ;
   184 pdf_file_attributes:
   185 	/* empty */
   186 	| pdf_file_attribute_list ;
   188 output_file_clause:
   189 	FILE_KEYWORD STRING { output_set_file ($2); }
   190 	pdf_file_attributes ';' ;
   192 label_clause:
   193 	LABEL ';' { page_label_t label = { NULL, '\0' }; output_set_page_label (label); }
   194 	| LABEL STRING ';' { page_label_t label = { $2, '\0' }; output_set_page_label (label); }
   195 	| LABEL CHARACTER ';' { page_label_t label = { NULL, $2 }; output_set_page_label (label); }
   196 	| LABEL STRING ',' CHARACTER ';' { page_label_t label = { $2, $4 }; output_set_page_label (label); } ;
   198 page_ranges:
   199 	range { output_pages ($1); }
   200 	| page_ranges ',' range { output_pages ($3); } ;
   202 page_clause:
   203 	PAGE INTEGER ';' { range_t range = { $2, $2 }; output_pages (range); } ;
   205 pages_clause:
   206 	PAGES page_ranges ';' ;
   208 bookmark_name:
   209 	STRING { output_set_bookmark ($1); } ;
   211 bookmark_name_list:
   212 	bookmark_name
   213 	| bookmark_name_list ',' bookmark_name ;
   215 bookmark_clause:
   216 	BOOKMARK { output_push_context (); bookmark_level++; }
   217 	bookmark_name_list
   218 	output_clause_list ';' { bookmark_level--; output_pop_context (); } ;
   220 output_clause:
   221 	output_file_clause
   222 	| label_clause
   223 	| page_clause | pages_clause
   224 	| bookmark_clause
   225 	| output_clause_list ;
   227 output_clauses:
   228 	output_clause
   229 	| output_clauses output_clause ;
   231 output_clause_list:
   232 	'{' { output_push_context (); }
   233 	output_clauses '}' { output_pop_context (); } ;
   235 output_statement:
   236 	OUTPUT output_clauses ;