semantics.c

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