This commit is contained in:
Jacob Signorovitch 2024-11-16 10:42:50 -05:00
parent e5bb4dfd96
commit ad8ac61b98
3 changed files with 19 additions and 4 deletions

View File

@ -1,8 +1,10 @@
%{ %{
#include <stdio.h>
#include "../../src/include/ast.h" #include "../../src/include/ast.h"
#include "../../src/include/lexer.h" #include "../../src/include/lexer.h"
int yylex(void);
void yyerror(char const*); int yylex(void);
void yyerror(char const*);
%} %}
%code requires { %code requires {
@ -15,6 +17,8 @@
AST* ast; AST* ast;
} }
%define parse.error verbose
%token<intval> NUM %token<intval> NUM
%token<strval> CALL %token<strval> CALL
%token PLUS %token PLUS
@ -22,6 +26,17 @@
%% %%
input:
%empty
| input line
;
line:
'\n'
| exp '\n' { printf("it worked. 👍\n"); }
;
exp: exp:
NUM { $$ = ast_init(AST_TYPE_NUM, ast_type_num_init($1)); } NUM { $$ = ast_init(AST_TYPE_NUM, ast_type_num_init($1)); }
| NUM PLUS NUM { | NUM PLUS NUM {

View File

@ -77,7 +77,7 @@
printf(COL_BWHI "%s ]\n" COL_RESET, INDENT_spacing->buf); printf(COL_BWHI "%s ]\n" COL_RESET, INDENT_spacing->buf);
// End an indent block. // 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. // Allocate a pointer with a type.
#define talloc(T, X) T* X = malloc(sizeof(T)); #define talloc(T, X) T* X = malloc(sizeof(T));

View File

@ -172,4 +172,4 @@ int yylex() {
return 0; 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); }