#ifndef AST_H
#define AST_H
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
typedef enum {
VAR_UNKNOWN = 0,
VAR_VOID,
VAR_STRING_ARRAY,
VAR_BOOL,
VAR_INT,
VAR_INT_ARRAY,
VAR_CLASS
} ast_var_type;
typedef struct {
ast_var_type type;
const char *classname;
} ast_type;
typedef enum {
INT_CONST,
BOOL_CONST,
VARNAME,
THIS_PTR,
NOT_EXPR,
NEW_CLASS,
NEW_INT_ARRAY,
ARRAY_LENGTH,
ARRAY_INDEX,
METHOD_CALL,
BINOP,
} ast_expr_type;
typedef struct ast_expr {
int lineno;
ast_expr_type type;
ast_type expr_type;
union {
int int_const;
bool bool_const;
struct {
const char *id;
};
struct ast_expr *expr;
struct {
struct ast_expr *object;
const char *method;
struct ast_expr *exp_list;
};
struct {
struct ast_expr *lhs, *rhs;
int oper;
};
struct {
struct ast_expr *array, *array_index;
};
};
struct ast_expr *next;
} ast_expr;
typedef enum {
BLOCK,
IF_ELSE,
WHILE_STMT,
SYS_OUT,
VAR_ASSIGN,
ARRAY_ASSIGN,
} ast_stmt_type;
typedef struct ast_stmt {
int lineno;
ast_stmt_type type;
union {
struct ast_stmt *stmt_list;
struct {
ast_expr *cond;
union {
struct ast_stmt *while_branch;
struct {
struct ast_stmt *true_branch, *false_branch;
};
};
};
struct {
const char *id;
ast_expr *array_index;
ast_expr *assign_expr;
};
struct ast_expr *expr;
};