actually actually compile and run
This commit is contained in:
parent
5f6febbdf5
commit
6cdf57f468
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
jeger
|
||||
regtest
|
||||
*.out
|
||||
*.so
|
||||
|
13
Makefile
13
Makefile
@ -8,8 +8,15 @@ CPPFLAGS += ${CFLAGS}
|
||||
|
||||
OUTPUT := jeger
|
||||
|
||||
main: object/main.o object/generator.o object/jeger.yy.o
|
||||
${LINK.cxx}
|
||||
${OUTPUT}: object/main.o object/generator.o object/jeger.yy.o
|
||||
${LINK.cpp} -o ${OUTPUT} $?
|
||||
|
||||
test:
|
||||
./${OUTPUT} source/jeger.l
|
||||
|
||||
clean:
|
||||
-rm ${OBJECT.d}/*.o
|
||||
-rm ${OUTPUT}
|
||||
|
||||
object/%.yy.cpp: source/%.l
|
||||
flex -o $@ $<
|
||||
@ -18,4 +25,4 @@ object/%.o: source/%.c
|
||||
${COMPILE.c} $< -o $@
|
||||
|
||||
object/%.o: source/%.cpp
|
||||
${COMPILE.cxx} $< -o $@
|
||||
${COMPILE.cpp} $< -o $@
|
||||
|
@ -6,9 +6,12 @@
|
||||
#include "jeger.h"
|
||||
|
||||
//#define AS_SYMBOL(c) (c-'a')
|
||||
#define AS_SYMBOL(c) c
|
||||
#define AS_SYMBOL(c) ((int)c)
|
||||
#define TOKEN_OFFSET 128 /* XXX */
|
||||
|
||||
int alphabet_size = 128;
|
||||
rule_t * patterns;
|
||||
|
||||
static inline
|
||||
void put_header(FILE * f, const int alphabet_size, const int n_states, const int no_match) {
|
||||
fputs(
|
||||
@ -76,7 +79,7 @@ int get_most_common_prefix(const char * pattern, char * * prefixes, int current_
|
||||
return r;
|
||||
}
|
||||
|
||||
int get_max_number_of_states(const pattern_t * patterns) {
|
||||
int get_max_number_of_states(const rule_t * patterns) {
|
||||
int r = 0;
|
||||
int state_max_accumulator = -1;
|
||||
for (int i = 0; patterns[i].pattern != NULL; i++) {
|
||||
@ -111,7 +114,7 @@ void generate(const char * filename) {
|
||||
patterns[pattern_index].pattern != NULL;
|
||||
pattern_index++
|
||||
) {
|
||||
const pattern_t * pattern = &patterns[pattern_index];
|
||||
const rule_t * pattern = &patterns[pattern_index];
|
||||
|
||||
int current_state_start = states[pattern->state];
|
||||
if (current_state_start == -1) {
|
||||
|
@ -3,10 +3,11 @@
|
||||
|
||||
typedef struct {
|
||||
int state;
|
||||
const char * pattern;
|
||||
} pattern_t;
|
||||
char * pattern;
|
||||
char * code;
|
||||
} rule_t;
|
||||
|
||||
extern pattern_t * patterns;
|
||||
extern rule_t * patterns;
|
||||
extern int alphabet_size;
|
||||
|
||||
extern void generate(const char * filename);
|
||||
|
@ -38,13 +38,13 @@
|
||||
typedef struct {
|
||||
char * pattern;
|
||||
char * code;
|
||||
} rule_t;
|
||||
} rule_t2;
|
||||
|
||||
string definition_section_code_buffer;
|
||||
string code_section_code_buffer;
|
||||
|
||||
map<string, vector<rule_t>> rules;
|
||||
map<string, vector<rule_t>>::iterator current_state;
|
||||
map<string, vector<rule_t2>> rules;
|
||||
map<string, vector<rule_t2>>::iterator current_state;
|
||||
string patter_buffer;
|
||||
string code_buffer;
|
||||
|
||||
@ -191,7 +191,7 @@ prefix={value} {
|
||||
\} {
|
||||
--nest_counter;
|
||||
if (nest_counter == -1) {
|
||||
current_state->second.push_back((rule_t) {
|
||||
current_state->second.push_back((rule_t2) {
|
||||
.pattern = strdup(patter_buffer.c_str()),
|
||||
.code = strdup(code_buffer.c_str()),
|
||||
});
|
||||
@ -217,7 +217,7 @@ prefix={value} {
|
||||
\\\\ { ; }
|
||||
\\\" { ; }
|
||||
\" { BEGIN IN_CODE; }
|
||||
.|\n { ; }
|
||||
.|\n { ; } /* XXX we are eating strings */
|
||||
}
|
||||
|
||||
<IN_COMMENT>{
|
||||
@ -238,32 +238,8 @@ prefix={value} {
|
||||
|
||||
%%
|
||||
|
||||
int parse(const char * filename) {
|
||||
int r = 0;
|
||||
FILE * f = fopen(filename, "r");
|
||||
if (!f) { return 2; }
|
||||
|
||||
yyin = f;
|
||||
|
||||
r = yylex();
|
||||
if (r) { return r; }
|
||||
|
||||
/* XXX fill globals */
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#ifdef SCANNER_MAIN
|
||||
|
||||
signed main(int argc, char * argv[]) {
|
||||
if (argc < 2) { return 1; }
|
||||
|
||||
FILE * f = fopen(argv[1], "r");
|
||||
if (!f) { return 2; }
|
||||
|
||||
yyin = f;
|
||||
yylex();
|
||||
|
||||
static
|
||||
void dump_parse_results(void) {
|
||||
puts(definition_section_code_buffer.c_str());
|
||||
puts("----------");
|
||||
|
||||
@ -277,8 +253,35 @@ signed main(int argc, char * argv[]) {
|
||||
|
||||
puts("----------");
|
||||
puts(code_section_code_buffer.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
extern "C"
|
||||
int parse(const char * filename) {
|
||||
int r = 0;
|
||||
FILE * f = fopen(filename, "r");
|
||||
if (!f) { return 2; }
|
||||
|
||||
yyin = f;
|
||||
|
||||
r = yylex();
|
||||
if (r) { return r; }
|
||||
|
||||
dump_parse_results();
|
||||
|
||||
patterns = (rule_t*)malloc(sizeof(rule_t)*(rules.size()+1));
|
||||
|
||||
int i = 0;
|
||||
for (const auto &rule_it : rules) {
|
||||
for (const auto &rule : rule_it.second) {
|
||||
patterns[i++] = (rule_t) {
|
||||
.state = i,
|
||||
.pattern = rule.pattern,
|
||||
.code = rule.code,
|
||||
};
|
||||
}
|
||||
}
|
||||
patterns[rules.size()] = (rule_t) { 0, NULL, NULL };
|
||||
|
||||
|
||||
return r;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user