Rename files
This commit is contained in:
8
Makefile
8
Makefile
@@ -5,7 +5,7 @@ CFLAGS=-std=c11 -D_FILE_OFFSET_BITS=64 -D_POSIX_C_SOURCE=200112L -Wall -Wextra $
|
||||
LD=gcc
|
||||
LDFLAGS=$(DEBUG_FLAGS)
|
||||
|
||||
lambda: main.o parse.o term.o
|
||||
lambda: main.o token.o lc.o
|
||||
$(LD) $(LDFLAGS) -o $@ $^
|
||||
|
||||
%.o: %.c
|
||||
@@ -17,6 +17,6 @@ clean:
|
||||
.PHONY: clean
|
||||
|
||||
# Dependencies
|
||||
main.o: parse.h term.h
|
||||
parse.o: parse.h util.h
|
||||
term.o: term.h
|
||||
main.o: token.h lc.h
|
||||
token.o: token.h util.h
|
||||
lc.o: lc.h token.h
|
||||
|
||||
6
main.c
6
main.c
@@ -1,4 +1,4 @@
|
||||
#include "parse.h"
|
||||
#include "token.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -17,12 +17,12 @@ int main(int argc, const char **argv) {
|
||||
fread(text, 1, length, in);
|
||||
fclose(in);
|
||||
TokenStream stream;
|
||||
TokenStreamError err;
|
||||
ParseError err;
|
||||
Token token;
|
||||
token_stream_init(&stream, text, length);
|
||||
while (!token_stream_is_eof(&stream)) {
|
||||
token_stream_next(&stream, &token, &err);
|
||||
if (token_stream_error_set(&err)) {
|
||||
if (parse_error_is_set(&err)) {
|
||||
printf("Error at %zu:%zu: %s\n", err.pos.line, err.pos.column,
|
||||
err.message);
|
||||
free(text);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "parse.h"
|
||||
#include "token.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
@@ -109,7 +109,7 @@ static int pprint_character(int c, char *buf, size_t buf_size) {
|
||||
}
|
||||
|
||||
ATTR_FORMAT(3, 4)
|
||||
static void sprintf_error(TokenStreamError *error, const SrcPos *pos,
|
||||
static void sprintf_error(ParseError *error, const SrcPos *pos,
|
||||
const char *restrict fmt, ...) {
|
||||
if (error) {
|
||||
error->set = true;
|
||||
@@ -134,10 +134,10 @@ static void sprintf_error(TokenStreamError *error, const SrcPos *pos,
|
||||
static bool read_next_ident(TokenStream *restrict stream, Token *restrict out);
|
||||
// consume = before using
|
||||
static bool read_next_reduce(TokenStream *restrict stream, Token *restrict out,
|
||||
TokenStreamError *restrict error);
|
||||
ParseError *restrict error);
|
||||
|
||||
bool token_stream_next(TokenStream *restrict stream, Token *restrict out,
|
||||
TokenStreamError *restrict error) {
|
||||
ParseError *restrict error) {
|
||||
if (error) {
|
||||
error->set = false;
|
||||
}
|
||||
@@ -214,7 +214,7 @@ static bool read_next_ident(TokenStream *restrict stream, Token *restrict out) {
|
||||
}
|
||||
|
||||
static bool read_next_reduce(TokenStream *restrict stream, Token *restrict out,
|
||||
TokenStreamError *restrict error) {
|
||||
ParseError *restrict error) {
|
||||
size_t len = 0;
|
||||
SrcPos start = *POS;
|
||||
int c;
|
||||
@@ -56,7 +56,7 @@ typedef struct {
|
||||
bool set;
|
||||
SrcPos pos;
|
||||
char message[64];
|
||||
} TokenStreamError;
|
||||
} ParseError;
|
||||
|
||||
inline static void token_stream_init(TokenStream *stream, const char *src,
|
||||
size_t src_len) {
|
||||
@@ -74,11 +74,11 @@ inline static bool token_stream_is_eof(TokenStream *stream) {
|
||||
|
||||
// return true on success, false on error
|
||||
bool token_stream_next(TokenStream *restrict stream, Token *restrict out,
|
||||
TokenStreamError *restrict error);
|
||||
static inline void token_stream_error_clear(TokenStreamError *error) {
|
||||
ParseError *restrict error);
|
||||
static inline void parse_error_clear(ParseError *error) {
|
||||
error->set = false;
|
||||
}
|
||||
static inline bool token_stream_error_set(const TokenStreamError *error) {
|
||||
static inline bool parse_error_is_set(const ParseError *error) {
|
||||
return error->set;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user