Start using driver, and switch to file IO.

This commit is contained in:
2020-09-09 13:00:06 -07:00
parent 0e40c9e216
commit 308ec615b9
4 changed files with 80 additions and 17 deletions

View File

@@ -0,0 +1,43 @@
#pragma once
#include <string>
#include <fstream>
#include "definition.hpp"
#include "location.hh"
#include "parser.hpp"
struct parse_driver;
void scanner_init(parse_driver* d, yyscan_t* scanner);
void scanner_destroy(yyscan_t* scanner);
struct parse_driver {
std::string file_name;
std::ifstream file_stream;
yy::location location;
size_t file_offset;
std::vector<size_t> line_offsets;
definition_group global_defs;
parse_driver(const std::string& file)
: file_name(file) {}
void run_parse() {
file_stream.open(file_name);
if(!file_stream.good()) throw 0;
yyscan_t scanner;
scanner_init(this, &scanner);
yy::parser parser(scanner, *this);
parser();
scanner_destroy(&scanner);
}
int get() {
return file_stream.get();
}
};
#define YY_DECL yy::parser::symbol_type yylex(yyscan_t yyscanner, parse_driver& drv)
YY_DECL;