1.1 --- a/semantics.c Sun Dec 30 16:29:50 2001 +0000 1.2 +++ b/semantics.c Sun Dec 30 17:09:08 2001 +0000 1.3 @@ -1,24 +1,55 @@ 1.4 +#include <stdlib.h> 1.5 +#include <string.h> 1.6 #include <stdio.h> 1.7 1.8 #include "type.h" 1.9 +#include "semantics.h" 1.10 #include "parser.tab.h" 1.11 -#include "semantics.h" 1.12 1.13 1.14 FILE *yyin; 1.15 int line; /* line number in spec file */ 1.16 1.17 1.18 -int input_count; /* total input pages in spec */ 1.19 -int output_count; /* total output pages in spec */ 1.20 +int input_page_count; /* total input pages in spec */ 1.21 +int output_page_count; /* total output pages in spec */ 1.22 + 1.23 + 1.24 +input_context_t *current_input_context; 1.25 1.26 1.27 void input_push_context (input_context_type_t type) 1.28 { 1.29 + input_context_t *new_input_context; 1.30 + 1.31 + new_input_context = malloc (sizeof (input_context_t)); 1.32 + if (! new_input_context) 1.33 + { 1.34 + fprintf (stderr, "failed to calloc an input context\n"); 1.35 + return; 1.36 + } 1.37 + 1.38 + if (current_input_context) 1.39 + { 1.40 + memcpy (new_input_context, current_input_context, sizeof (input_context_t)); 1.41 + new_input_context->page_count = 0; 1.42 + } 1.43 + else 1.44 + memset (new_input_context, 0, sizeof (input_context_t)); 1.45 + 1.46 + new_input_context->parent_input_context = current_input_context; 1.47 + current_input_context = new_input_context; 1.48 }; 1.49 1.50 void input_pop_context (void) 1.51 { 1.52 + if (! current_input_context) 1.53 + { 1.54 + fprintf (stderr, "failed to pop an input context\n"); 1.55 + return; 1.56 + } 1.57 + 1.58 + current_input_context = current_input_context->parent_input_context; 1.59 }; 1.60 1.61 void input_set_file (char *name) 1.62 @@ -27,20 +58,25 @@ 1.63 1.64 void input_images (int first, int last) 1.65 { 1.66 - input_count += ((last - first) + 1); 1.67 + input_page_count += ((last - first) + 1); 1.68 if (first == last) 1.69 printf ("image %d\n", first); 1.70 else 1.71 - printf ("iamges %d..%d\n", first, last); 1.72 + printf ("images %d..%d\n", first, last); 1.73 } 1.74 1.75 + 1.76 +void output_push_context (void) 1.77 +{ 1.78 +}; 1.79 + 1.80 void output_set_file (char *name) 1.81 { 1.82 }; 1.83 1.84 void output_pages (int first, int last) 1.85 { 1.86 - output_count += ((last - first) + 1); 1.87 + output_page_count += ((last - first) + 1); 1.88 if (first == last) 1.89 printf ("page %d\n", first); 1.90 else 1.91 @@ -67,8 +103,20 @@ 1.92 1.93 line = 1; 1.94 1.95 + input_push_context (INPUT_CONTEXT_ALL); /* create initial input context */ 1.96 + output_push_context (); /* create initial output context */ 1.97 + 1.98 yyparse (); 1.99 1.100 + if (input_page_count != output_page_count) 1.101 + { 1.102 + fprintf (stderr, "input page count %d != output page count %d\n", 1.103 + input_page_count, output_page_count); 1.104 + goto fail; 1.105 + } 1.106 + 1.107 + fprintf (stderr, "%d pages specified\n", input_page_count); 1.108 + 1.109 result = 1; 1.110 1.111 fail: