Brain  1.0.0
A fast esoteric language!
Expr.h
1 /* This is the source code of Brain Programming Language.
2  * It is licensed under GNU GPL v. 3 or later.
3  * You should have received a copy of the license in this archive (see LICENSE).
4  *
5  * Copyright Brain, 2016.
6  */
7 
8 #ifndef EXPR_H
9 #define EXPR_H
10 
11 #include <llvm/IR/IRBuilder.h>
12 #include <llvm/IR/Module.h>
13 
14 #include "../../utils/ArgsOptions.h"
15 #include "../general/ASTInfo.h"
16 
17 #ifndef __cast_capital__
18  #define CAST_TO_C_STRING castToCStr
19 #else
20  #define CAST_TO_C_STRING CastToCStr
21 #endif // __cast_capital__
22 
26 typedef enum
27 {
28  TT_SHIFT_LEFT = '<',
29  TT_SHIFT_RIGHT = '>',
30  TT_INCREMENT = '+',
31  TT_DECREMENT = '-',
32  TT_OUTPUT = '.',
33  TT_INPUT = ',',
34  TT_BEGIN_WHILE = '[',
35  TT_END_WHILE = ']',
36  TT_BEGIN_FOR = '{',
37  TT_END_FOR = '}',
38  TT_MUL = '*',
39  TT_DIV = '/',
40  TT_REM = '%',
41  TT_DEBUG = '#',
42  TT_BREAK = '!',
43  TT_IF_THEN = '?',
44  TT_IF_ELSE = ':',
45  TT_IF_END = ';',
46  TT_FLOAT = '$'
47 } TokenType;
48 
52 typedef enum
53 {
54  ET_NOT_IMPORTANT,
55  ET_BRANCH,
56  ET_TERMINAL
57 } ExpressionType;
58 
62 class Expr
63 {
64 public:
65  virtual ~Expr() {}
66 
73  virtual void code_gen(llvm::Module *M, llvm::IRBuilder<> &B,
74  llvm::BasicBlock *BreakBB) = 0;
79  virtual void debug_description(int level) = 0;
84  virtual void ast_code_gen() = 0;
89  virtual bool update_expression(char update) { return false; }
93  virtual ExpressionType expression_category() { return ET_NOT_IMPORTANT; }
94 };
95 
96 #endif // EXPR_H
Abstract class in which all expressions in Brain implement from.
Definition: Expr.h:62
virtual void debug_description(int level)=0
Virtual method for the AST&#39;s emission.
virtual ExpressionType expression_category()
Returns the category of the expression given by the caller.
Definition: Expr.h:93
virtual void code_gen(llvm::Module *M, llvm::IRBuilder<> &B, llvm::BasicBlock *BreakBB)=0
Virtual method for code generation.
virtual void ast_code_gen()=0
Virtual method for the reverse code generation from the AST. It prints out to the stdout the token it...
virtual bool update_expression(char update)
Virtual method for updating the AST exprs.
Definition: Expr.h:89