HTMLify
tokens.h
Views: 45 | Author: abh
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#ifndef VARIABLE_H
#define VARIABLE_H
// Variable
typedef enum {
character,
integer,
floating,
string,
none,
} VarType;
typedef union {
char _char;
int _int;
float _float;
char *_str;
} VarValue;
typedef struct {
char name[64];
VarType type;
VarValue value;
} Variable;
// Token
typedef enum {
ASN, // Assign
ADD,
SUB,
DIV,
MUL,
} Operator;
typedef enum {
DEF,
INT,
FLOAT,
CHAR,
STR,
DEL,
PRINT,
TYPE,
} Keyword;
typedef enum {
LITERAL,
OPERATOR,
VARIABLE,
KEYWORD,
NONE,
} TokenType;
typedef union {
Variable *variable;
Operator operator;
Keyword keyword;
char *literal;
} TokenValue;
typedef struct {
TokenType type;
TokenValue value;
} Token;
// Variable functions
extern Variable *Variables;
extern int Variables_count;
Variable *Variable_init(char *name, VarType type);
void Variable_assign(Variable *var, VarValue value);
void Variable_repr(Variable *var, char *str);
Variable Variable_op(Variable *this, Operator op, const Variable *that);
Variable *Get_variable(char *name, bool named);
void Del_variable(char *name);
bool Exist_variable(char *name);
VarValue Literal_value(const char *name, VarType type);
// Token functions
TokenType Token_type(const char *name);
Keyword Get_keyword(const char *name);
Operator Get_operator(const char *name);
char *Type_token(Token token);
#endif