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