Parse.
This commit is contained in:
parent
e5bb4dfd96
commit
ad8ac61b98
@ -1,6 +1,8 @@
|
|||||||
%{
|
%{
|
||||||
|
#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);
|
int yylex(void);
|
||||||
void yyerror(char const*);
|
void yyerror(char const*);
|
||||||
%}
|
%}
|
||||||
@ -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 {
|
||||||
|
@ -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));
|
||||||
|
@ -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); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user