This commit is contained in:
2022-02-21 12:44:43 +01:00
parent 986228c449
commit c61f68540d
21 changed files with 827 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
#ifndef IR_H
#define IR_H
/* This is the tree node structure */
typedef struct n {
node_index_t type;
void *data;
struct s *entry;
uint64_t n_children;
struct n **children;
} node_t;
// Export the initializer function, it is needed by the parser
void node_init (
node_t *nd, node_index_t type, void *data, uint64_t n_children, ...
);
#endif

View File

@@ -0,0 +1,37 @@
#ifndef NODETYPES_H
#define NODETYPES_H
typedef enum {
PROGRAM,
GLOBAL_LIST,
GLOBAL,
STATEMENT_LIST,
PRINT_LIST,
EXPRESSION_LIST,
VARIABLE_LIST,
ARGUMENT_LIST,
PARAMETER_LIST,
DECLARATION_LIST,
FUNCTION,
STATEMENT,
BLOCK,
ASSIGNMENT_STATEMENT,
ADD_STATEMENT,
SUBTRACT_STATEMENT,
MULTIPLY_STATEMENT,
DIVIDE_STATEMENT,
RETURN_STATEMENT,
PRINT_STATEMENT,
NULL_STATEMENT,
IF_STATEMENT,
WHILE_STATEMENT,
EXPRESSION,
RELATION,
DECLARATION,
PRINT_ITEM,
IDENTIFIER_DATA,
NUMBER_DATA,
STRING_DATA
} node_index_t;
extern char *node_string[26];
#endif

View File

@@ -0,0 +1,35 @@
#ifndef VSLC_H
#define VSLC_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdarg.h>
// Numbers and names for the types of syntax tree nodes
#include "nodetypes.h"
// Definition of the tree node type
#include "ir.h"
// Token definitions and other things from bison, needs def. of node type
#include "y.tab.h"
/* This is generated from the bison grammar, calls on the flex specification */
int yyerror ( const char *error );
/* These are defined in the parser generated by bison */
extern int yylineno;
extern int yylex ( void );
extern char yytext[];
/* Global state */
extern node_t *root;
/* Global routines, called from main in vslc.c */
void simplify_syntax_tree ( void );
void print_syntax_tree ( void );
void destroy_syntax_tree ( void );
#endif