diff --git a/src/grammar.y b/src/grammar.y index b8d608c..5611fa6 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -1,8 +1,10 @@ %{ + #include #include "../../src/include/ast.h" #include "../../src/include/lexer.h" - int yylex(void); - void yyerror(char const*); + + int yylex(void); + void yyerror(char const*); %} %code requires { @@ -15,6 +17,8 @@ AST* ast; } +%define parse.error verbose + %token NUM %token CALL %token PLUS @@ -22,6 +26,17 @@ %% +input: + %empty + | input line + ; + + +line: + '\n' + | exp '\n' { printf("it worked. 👍\n"); } + ; + exp: NUM { $$ = ast_init(AST_TYPE_NUM, ast_type_num_init($1)); } | NUM PLUS NUM { diff --git a/src/include/util.h b/src/include/util.h index 1cd2355..dccc37b 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -77,7 +77,7 @@ printf(COL_BWHI "%s ]\n" COL_RESET, INDENT_spacing->buf); // End an indent block. -#define INDENT_END dstr_destroy(INDENT_spacing); +#define INDENT_END printf(COL_RESET); dstr_destroy(INDENT_spacing); // Allocate a pointer with a type. #define talloc(T, X) T* X = malloc(sizeof(T)); diff --git a/src/lexer.c b/src/lexer.c index c7cc28b..0394c02 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -172,4 +172,4 @@ int yylex() { return 0; } -void yyerror(char const* s) { fprintf(stderr, "%s\n", s); } +void yyerror(char const* s) { fprintf(stderr, "Syntax error:\n%s\n", s); }