mirror of
https://github.com/iritmaximus/ttk91-compiler.git
synced 2026-10-12 19:13:40 +03:00
implemented ast creation
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
#ifndef COMMENT_H
|
||||
#define COMMENT_H
|
||||
|
||||
|
||||
struct comment {
|
||||
char *text;
|
||||
};
|
||||
|
||||
struct comment * comment_create(char *text);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef EXPR_H
|
||||
#define EXPR_H
|
||||
|
||||
#include "oper.h"
|
||||
#include "ttk_register.h"
|
||||
#include "value.h"
|
||||
#include "label.h"
|
||||
#include "comment.h"
|
||||
|
||||
typedef enum {
|
||||
INSTRUCTION,
|
||||
LABEL_DEF,
|
||||
COMMENT
|
||||
} expr_t;
|
||||
|
||||
struct expr {
|
||||
expr_t kind;
|
||||
struct label *label;
|
||||
struct oper *oper;
|
||||
struct ttk_register *first_arg;
|
||||
struct value *second_arg;
|
||||
struct comment *comment;
|
||||
struct expr *next;
|
||||
};
|
||||
|
||||
struct expr * expr_create(expr_t kind, struct label *l, struct oper *o, struct ttk_register *f_arg, struct value *s_arg, struct comment *c, struct expr *n);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef LABEL_H
|
||||
#define LABEL_H
|
||||
|
||||
#include "expr.h"
|
||||
|
||||
typedef enum {
|
||||
LABEL_CONST,
|
||||
LABEL_TAG
|
||||
} label_t;
|
||||
|
||||
struct label {
|
||||
label_t kind;
|
||||
const char *name;
|
||||
int value;
|
||||
};
|
||||
|
||||
struct label * label_create(label_t kind, char *name, int value);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef OPER_H
|
||||
#define OPER_H
|
||||
|
||||
#include "ttk_register.h"
|
||||
|
||||
typedef enum {
|
||||
OPER_DATA,
|
||||
OPER_AR,
|
||||
OPER_LOGIC,
|
||||
OPER_BRANCH,
|
||||
OPER_STACK,
|
||||
OPER_SYS
|
||||
} oper_t;
|
||||
|
||||
struct oper {
|
||||
oper_t kind;
|
||||
char* oper_name;
|
||||
};
|
||||
|
||||
struct oper * oper_create(oper_t kind, char* oper_name);
|
||||
|
||||
#endif
|
||||
+20
-2
@@ -79,7 +79,25 @@ extern int yydebug;
|
||||
|
||||
/* Value type. */
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef int YYSTYPE;
|
||||
union YYSTYPE
|
||||
{
|
||||
#line 39 "src/parser.bison"
|
||||
|
||||
struct expr *expr;
|
||||
struct oper *oper;
|
||||
struct ttk_register *ttk_register;
|
||||
struct value *value;
|
||||
struct pure_value *pure_value;
|
||||
struct label *label;
|
||||
struct comment *comment;
|
||||
char* name;
|
||||
int num;
|
||||
char character;
|
||||
|
||||
#line 98 "include/token.h"
|
||||
|
||||
};
|
||||
typedef union YYSTYPE YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define YYSTYPE_IS_DECLARED 1
|
||||
#endif
|
||||
@@ -88,7 +106,7 @@ typedef int YYSTYPE;
|
||||
extern YYSTYPE yylval;
|
||||
|
||||
|
||||
int yyparse (void);
|
||||
int yyparse (struct expr *parse_result);
|
||||
|
||||
|
||||
#endif /* !YY_YY_INCLUDE_TOKEN_H_INCLUDED */
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef REGISTER_H
|
||||
#define REGISTER_H
|
||||
|
||||
struct ttk_register {
|
||||
int id;
|
||||
int value;
|
||||
};
|
||||
|
||||
struct ttk_register * ttk_register_create(char* id, int value);
|
||||
int parse_register_num(char *name);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef VALUE_H
|
||||
#define VALUE_H
|
||||
|
||||
#include "ttk_register.h"
|
||||
#include "label.h"
|
||||
|
||||
typedef enum {
|
||||
REGISTER,
|
||||
NUMBER,
|
||||
LABEL
|
||||
} value_t;
|
||||
|
||||
typedef enum {
|
||||
NONE,
|
||||
INDEXED
|
||||
} index_t;
|
||||
|
||||
typedef enum {
|
||||
DIRECT,
|
||||
IMMEDIATE,
|
||||
INDIRECT
|
||||
} addr_mode_t;
|
||||
|
||||
struct value {
|
||||
addr_mode_t addr_mode;
|
||||
index_t indexing_mode;
|
||||
struct pure_value *value;
|
||||
struct ttk_register *index_register;
|
||||
};
|
||||
|
||||
struct pure_value {
|
||||
value_t kind;
|
||||
struct ttk_register *ttk_register;
|
||||
int number;
|
||||
struct label *label;
|
||||
};
|
||||
|
||||
struct value * value_create(addr_mode_t addr_m, index_t i_m, struct pure_value *value, struct ttk_register *i_reg);
|
||||
struct pure_value * pure_value_create(value_t kind, struct ttk_register *ttk_reg, int num, struct label *l);
|
||||
addr_mode_t parse_addr_mode(char addr_mode);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user