slash

slash is a simple type-oriented programming language
Log | Files | Refs | README | LICENSE

pipeline.c (868B)


      1 /*
      2  * pipeline.c -- compilation pipeline
      3  */
      4 
      5 #include <stdio.h>
      6 
      7 #include "lex.h"
      8 #include "pipeline.h"
      9 #include "stat.h"
     10 
     11 static void ofile(void);
     12 static void lex(void);
     13 static void end(void);
     14 
     15 /* open stat.i_infile -> stat.i_fstream */
     16 static void
     17 ofile(void)
     18 {
     19 	stat.i_fstream = fopen(stat.i_infile, "r"); /* RO mode */
     20 
     21 	if (!stat.i_fstream) {
     22 		perror("opening input");
     23 		end();
     24 	}
     25 }
     26 
     27 static void
     28 lex(void)
     29 {
     30 	tok_t tk;
     31 
     32 	if (!stat.i_fstream) return;
     33 
     34 	/* 1. init */
     35 	lex_init();
     36 
     37 	/* 2. lup */
     38 	do {
     39 		tk = nexttok();
     40 
     41 		/* debug: can be removed */
     42 		puts(tokname(tk.type));
     43 		if (tk.type == TOK_IDENT)
     44 			printf("(%s)", tk.lexeme);
     45 		printf("\n");
     46 		 
     47 		 (void)tk;
     48 	} while (tk.type != TOK_EOF);
     49 }
     50 
     51 static void
     52 end(void)
     53 {
     54 	if (stat.i_fstream) {
     55 		fclose(stat.i_fstream); /* don't leave the fd open */
     56 	}
     57 }
     58 
     59 void
     60 compile(void)
     61 {
     62 	ofile();
     63 
     64 	lex();
     65 
     66 	end();
     67 }
     68