Parse.
This commit is contained in:
parent
e5bb4dfd96
commit
ad8ac61b98
@ -1,8 +1,10 @@
|
||||
%{
|
||||
#include <stdio.h>
|
||||
#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<intval> NUM
|
||||
%token<strval> 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 {
|
||||
|
@ -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));
|
||||
|
@ -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); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user