Sun, 30 Dec 2001 16:29:50 +0000
Initial revision
semantics.c | file | annotate | diff | revisions | |
semantics.h | file | annotate | diff | revisions |
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 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/semantics.h Sun Dec 30 16:29:50 2001 +0000 2.3 @@ -0,0 +1,27 @@ 2.4 +typedef enum 2.5 +{ 2.6 + INPUT_CONTEXT_ALL, 2.7 + INPUT_CONTEXT_ODD, 2.8 + INPUT_CONTEXT_EVEN 2.9 +} input_context_type_t; 2.10 + 2.11 + 2.12 +extern int line; /* line number in spec file */ 2.13 + 2.14 + 2.15 +extern int input_count; /* total input pages in spec */ 2.16 +extern int output_count; /* total output pages in spec */ 2.17 + 2.18 + 2.19 +boolean parse_spec_file (char *fn); 2.20 + 2.21 + 2.22 +/* semantic routines for input statements */ 2.23 +void input_push_context (input_context_type_t type); 2.24 +void input_pop_context (void); 2.25 +void input_set_file (char *name); 2.26 +void input_images (int first, int last); 2.27 + 2.28 +/* semantic routines for output statements */ 2.29 +void output_set_file (char *name); 2.30 +void output_pages (int first, int last);