semantics.c

changeset 16
dbf5e39b1658
child 18
3de372e4b230
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/semantics.c	Sun Dec 30 16:29:50 2001 +0000
     1.3 @@ -0,0 +1,79 @@
     1.4 +#include <stdio.h>
     1.5 +
     1.6 +#include "type.h"
     1.7 +#include "parser.tab.h"
     1.8 +#include "semantics.h"
     1.9 +
    1.10 +
    1.11 +FILE *yyin;
    1.12 +int line;  /* line number in spec file */
    1.13 +
    1.14 +
    1.15 +int input_count;   /* total input pages in spec */
    1.16 +int output_count;  /* total output pages in spec */
    1.17 +
    1.18 +
    1.19 +void input_push_context (input_context_type_t type)
    1.20 +{
    1.21 +};
    1.22 +
    1.23 +void input_pop_context (void)
    1.24 +{
    1.25 +};
    1.26 +
    1.27 +void input_set_file (char *name)
    1.28 +{
    1.29 +};
    1.30 +
    1.31 +void input_images (int first, int last)
    1.32 +{
    1.33 +  input_count += ((last - first) + 1);
    1.34 +  if (first == last)
    1.35 +    printf ("image %d\n", first);
    1.36 +  else
    1.37 +    printf ("iamges %d..%d\n", first, last);
    1.38 +}
    1.39 +
    1.40 +void output_set_file (char *name)
    1.41 +{
    1.42 +};
    1.43 +
    1.44 +void output_pages (int first, int last)
    1.45 +{
    1.46 +  output_count += ((last - first) + 1);
    1.47 +  if (first == last)
    1.48 +    printf ("page %d\n", first);
    1.49 +  else
    1.50 +    printf ("pages %d..%d\n", first, last);
    1.51 +}
    1.52 +
    1.53 +
    1.54 +void yyerror (char *s)
    1.55 +{
    1.56 +  fprintf (stderr, "%d: %s\n", line, s);
    1.57 +}
    1.58 +
    1.59 +
    1.60 +boolean parse_spec_file (char *fn)
    1.61 +{
    1.62 +  boolean result = 0;
    1.63 +
    1.64 +  yyin = fopen (fn, "r");
    1.65 +  if (! yyin)
    1.66 +    {
    1.67 +      fprintf (stderr, "can't open spec file '%s'\n", fn);
    1.68 +      goto fail;
    1.69 +    }
    1.70 +
    1.71 +  line = 1;
    1.72 +
    1.73 +  yyparse ();
    1.74 +
    1.75 +  result = 1;
    1.76 +
    1.77 + fail:
    1.78 +  if (yyin)
    1.79 +    fclose (yyin);
    1.80 +
    1.81 +  return (result);
    1.82 +}