summaryrefslogtreecommitdiff
path: root/parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/parser.c b/parser.c
index c577105..987f26d 100644
--- a/parser.c
+++ b/parser.c
@@ -10,6 +10,7 @@
#include "gate.h"
+static FILE* fd;
static struct token *cursor;
#ifdef emit_error
@@ -18,7 +19,8 @@ static struct token *cursor;
#endif /* ifdef emit_error */
#define emit_error(...) fprintf(stderr, "Error (%zd,%zd): ", cursor->loc.line, cursor->loc.column);\
- fprintf(stderr, __VA_ARGS__)
+ fprintf(stderr, __VA_ARGS__);\
+ indicate_file_area(fd, cursor->loc.line, cursor->loc.column, cursor->span)
//static struct op_lookup uop_handlers[] = {
@@ -54,10 +56,44 @@ expect(enum TOKEN_TYPE e) {
return 0;
}
+static void
+kerchunk() {
+ cursor = cursor->next;
+}
int
-parse(struct token *t) {
+parse(FILE *f, struct token *t) {
+ char *token_desc = "(internal error)";
+ fd = f;
cursor = t;
- expect(TOK_MODULE);
+
+ if (expect(TOK_MODULE)) {
+ return 1;
+ }
+ kerchunk();
+
+ if (expect(TOK_IDENT)) {
+ return 1;
+ }
+ emit_error("Debug: module is named %s\n", cursor->value);
+ kerchunk();
+
+ if (expect(TOK_EOL)) {
+ return 1;
+ }
+ kerchunk();
+
+ while (cursor) {
+ switch(cursor->type) {
+ case TOK_EOL:
+ kerchunk();
+ break;
+ /* FIXME implement everything */
+ default:
+ token_desc = get_token_description(cursor->type);
+ emit_error("Unexpected %s\n", token_desc);
+ return 1;
+ }
+ }
return 0;
}