diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-08-26 13:44:07 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-08-26 13:44:07 +0200 |
commit | 5f8c1d144b3c91f2c4ba75d709a74d83c1f3d5a0 (patch) | |
tree | f842fc870c24e5b913aa277747985f68f99b951a /grammar.y | |
parent | b5cc10cff15797bc9f89724ab53ac7d296fbbc0c (diff) |
ast and cleanup
Diffstat (limited to 'grammar.y')
-rw-r--r-- | grammar.y | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/grammar.y b/grammar.y deleted file mode 100644 index a37dae6..0000000 --- a/grammar.y +++ /dev/null @@ -1,99 +0,0 @@ -%{ -#include <stdio.h> - -#include "ast.c" - -extern FILE *yyin; - -extern int yylex(); -extern void yyerror(); - -ast_node* yyast = NULL; -%} - -%define parse.error verbose - -%union { - char* string; - int number; - ast_node* node; -} - -%token OPERATOR_PLUS -%token OPERATOR_MINUS -%token <string> ASSIGN - -%token FUNCTION -%token IF -%token ELSE -%token RETURN -%token <string> CONST -%token VAR - -%token <string> TYPE_INTEGER -%token <string> TYPE_STRING -%token <string> TYPE_VOID - -%token PARENTHESIS_LEFT -%token PARENTHESIS_RIGHT -%token BRACE_LEFT -%token BRACE_RIGHT -%token BRACKET_LEFT -%token BRACKET_RIGHT - -%token COMMA; -%token <string> COLON; - -%token <number> NUMBER; -%token <string> IDENTIFIER -%token COMMENT; - -%token END_OF_LINE; - -%type <node> program -%type <node> function -%type <node> arguments -%type <node> argument -%type <node> return_type -%type <node> variable_type -%type <node> statements -%type <node> statement -%type <node> expression - -%start program - -%% -program: - statement END_OF_LINE - | program program { $$ = create_program_node($1, $2); } - -variable_type: - TYPE_INTEGER { printf("variable_type:: %s\n", $1); $$ = create_type_node($1); } - | TYPE_STRING { $$ = create_type_node($1); } - - -statements: - statement - | statements END_OF_LINE statement - -statement: - // const henshin: integer = 2 - CONST IDENTIFIER COLON variable_type ASSIGN expression { printf("$1: %s -- $2: %s -- $3: %s -- $4: %s -- $5: %s -- $6: %s\n", $1, $2, $3, "4", $5, "6"); } - - -expression: - NUMBER -%% - -void main (int argc, char **argv) -{ - #ifdef YYDEBUG - yydebug = 1; - #endif - - //henshin_lex(); - yyin = fopen(argv[1], "r"); - yyparse(); - - printf("%s", yyast); -} |