create token nodes in lexer

This commit is contained in:
Josh Holtrop 2018-04-21 23:33:58 -04:00
parent 89889b778f
commit 57dcf9e62d
2 changed files with 14 additions and 1 deletions

View File

@ -1,6 +1,10 @@
#ifndef PARSER_H
#define PARSER_H
#include "Node.h"
#define YYSTYPE Node *
void parse(const char * filename);
#endif

View File

@ -7,13 +7,22 @@
#include "parser.tab.h"
#include "String.h"
#include <stdlib.h>
#include "Node.h"
#define YY_USER_ACTION yylloc->first_column += yyleng;
#define YY_USER_ACTION \
do { \
yylloc->first_column += yyleng; \
*yylval = Node_new(NODE_TYPE_TOKEN); \
(*yylval)->token.fname = current_file; \
(*yylval)->token.line = current_line; \
(*yylval)->token.text = String_new(yytext); \
} while(0);
static String * build_string = NULL;
static size_t current_line = 1u;
static String * current_file = NULL;
void handle_loc(const char * input);
void user_action(void);
%}