summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-08-01 23:25:46 +1200
committerDavid Phillips <david@sighup.nz>2018-08-01 23:25:46 +1200
commiteee61ddbba165f772a0e720825dcf6810eaa2648 (patch)
treec9b238e386dfcf19f0c3244998efa8d2dc6d0a82
parente22abc4eaf4f1446c6ac31e4b709cb5206d4fe3b (diff)
downloadhence-eee61ddbba165f772a0e720825dcf6810eaa2648.tar.xz
Rename lexer and parser, fix compilation warnings
-rw-r--r--Makefile2
-rw-r--r--common.c2
-rw-r--r--common.h1
-rw-r--r--lex.c (renamed from lexer.c)4
-rw-r--r--lex.h (renamed from lexer.h)0
-rw-r--r--parse.c (renamed from parser.c)8
-rw-r--r--parse.h (renamed from parser.h)0
-rw-r--r--simulator.c6
8 files changed, 12 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 5ba9cc6..3c48b8b 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CFLAGS += -std=c99 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L -Wall -Wextra
all: simulator
-simulator: simulator.o common.o gate.o logic.o lexer.o parser.o
+simulator: simulator.o common.o gate.o logic.o lex.o parse.o
.PHONY: test
test: all
diff --git a/common.c b/common.c
index c0e0af4..fbc9ae2 100644
--- a/common.c
+++ b/common.c
@@ -7,7 +7,7 @@ indicate_file_area(FILE* fd, size_t line, size_t column, size_t span) {
char margin[] = " ";
/* FIXME use proper line counting, not this hack */
char buf[1024];
- char *line_start = &buf;
+ char *line_start = buf;
rewind(fd);
for (; line; line--) {
diff --git a/common.h b/common.h
index 5a6977d..069bc81 100644
--- a/common.h
+++ b/common.h
@@ -5,6 +5,5 @@
#include <stddef.h>
void indicate_file_area(FILE *fd, size_t line, size_t column, size_t span);
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
diff --git a/lexer.c b/lex.c
index 53c64e7..dc4a56e 100644
--- a/lexer.c
+++ b/lex.c
@@ -4,7 +4,7 @@
#include <string.h>
#include "common.h"
-#include "lexer.h"
+#include "lex.h"
#ifdef emit_error
#warn "Remember to remove the global emit_error
@@ -53,7 +53,7 @@ static char buf[BUFFER_SIZE];
static FILE* fd;
static size_t line_number = 0;
static size_t column_number = 0;
-static size_t leading_whitespace_len = 0;
+static ssize_t leading_whitespace_len = 0;
static struct token *tok_start = NULL;
static struct token *tok_cursor = NULL;
diff --git a/lexer.h b/lex.h
index 3ce15f4..3ce15f4 100644
--- a/lexer.h
+++ b/lex.h
diff --git a/parser.c b/parse.c
index 88e7a1e..668a700 100644
--- a/parser.c
+++ b/parse.c
@@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
-#include "lexer.h"
+#include "lex.h"
#include "common.h"
#include "error.h"
#include "logic.h"
@@ -59,8 +59,8 @@ static const char *filename;
static int
expect(enum TOKEN_TYPE e) {
- char *expected_desc = "(internal error)";
- char *observed_desc = "(internal error)";
+ const char *expected_desc = "(internal error)";
+ const char *observed_desc = "(internal error)";
if (!cursor || cursor->type != e) {
expected_desc = get_token_description(e);
@@ -105,7 +105,9 @@ parse_expr(void) {
break;
default:
emit("Error: Unexpected %s\n", get_token_description(cursor->type));
+ return 1;
}
+ return 0;
}
diff --git a/parser.h b/parse.h
index 95a1fa8..95a1fa8 100644
--- a/parser.h
+++ b/parse.h
diff --git a/simulator.c b/simulator.c
index 1b33aec..b9f69bd 100644
--- a/simulator.c
+++ b/simulator.c
@@ -3,8 +3,8 @@
//#include "gate.h"
//#include "logic.h"
-#include "lexer.h"
-#include "parser.h"
+#include "lex.h"
+#include "parse.h"
int main(int argc, char **argv) {
FILE *fd = NULL;
@@ -31,5 +31,5 @@ int main(int argc, char **argv) {
// gate_update();
// gate_dump();
- return 0;
+ return p;
}