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