~lbnz/xr0

31679ac986b22618253f481d71269a76a7401fca — Xr0 Team 4 months ago 0f5178f feat/exec-branching
checkpoint
2 files changed, 19 insertions(+), 3 deletions(-)

M Makefile
M tests/3-program/100-lex/parse.x
M Makefile => Makefile +1 -1
@@ 81,7 81,7 @@ PARSER = $(BUILD_DIR)/lex-gen

lex-gen:
	@$(XR0C) tests/3-program/100-lex/parse.x > build/parse.c
	@c89 -o $(PARSER) $(BUILD_DIR)/parse.c
	@c89 -g -o $(PARSER) $(BUILD_DIR)/parse.c
	@$(PARSER) > $(BUILD_DIR)/gen_firstchar
	@echo '%' > $(BUILD_DIR)/percent
	@diff $(BUILD_DIR)/gen_firstchar $(BUILD_DIR)/percent

M tests/3-program/100-lex/parse.x => tests/3-program/100-lex/parse.x +18 -2
@@ 160,9 160,19 @@ lexer_create(char *pre, char *post, int npat, struct pattern *pattern,
void
lexer_destroy(struct lexer *l)
{
	int i;

	free(l->pre);
	free(l->post);
	for (i = 0; i < l->npat; i++) {
		free(l->pattern[i].name);
		free(l->pattern[i].pattern);
	}
	free(l->pattern);
	for (i = 0; i < l->ntok; i++) {
		free(l->token[i].name);
		free(l->token[i].action);
	}
	free(l->token);
	free(l);
}


@@ 471,7 481,9 @@ count_patterns(char *pos)
	for (; strncmp(pos, "%%", 2) != 0; n++) {
		parsed = parse_pattern(pos);
		pos = skipws(parsed.pos);
		/* TODO: clean up r.p */
		free(parsed.p->name);
		free(parsed.p->pattern);
		free(parsed.p);
	}

	return n;


@@ 510,6 522,7 @@ parse_defs_n(char *pos, int npat)
		for (i = 0; i < npat; i++) {
			parsed = parse_pattern(pos);
			p[i] = *parsed.p;
			free(parsed.p);
			pos = skipws(parsed.pos);
		}
	}


@@ 590,7 603,9 @@ count_tokens(char *pos)
	for (; *pos != '\0' && strncmp(pos, "%%", 2) != 0 ; n++) {
		r = parse_token(pos);
		pos = skipws(r.pos);
		/* TODO: clean up r.tk */
		free(r.tk->name);
		free(r.tk->action);
		free(r.tk);
	}

	return n;


@@ 612,6 627,7 @@ parse_rules_n(char *pos, int ntok)
		for (i = 0; i < ntok; i++) {
			parsed = parse_token(pos);
			t[i] = *parsed.tk;
			free(parsed.tk);
			pos = skipws(parsed.pos);
		}
	}