Line 66... |
Line 66... |
// Branch operands
|
// Branch operands
|
OP_BRA, OP_BZ, OP_BNZ, OP_BGE, OP_BGT, OP_BLT, OP_BRC, OP_BRV,
|
OP_BRA, OP_BZ, OP_BNZ, OP_BGE, OP_BGT, OP_BLT, OP_BRC, OP_BRV,
|
// Single operand instructions that have no explicit conditions
|
// Single operand instructions that have no explicit conditions
|
OP_CLR, OP_TRAP, OP_NEG,
|
OP_CLR, OP_TRAP, OP_NEG,
|
// BAREOPs that can have conditions
|
// BAREOPs that can have conditions
|
OP_HALT, OP_RTU, OP_BUSY,
|
OP_HALT, OP_RTU, OP_BUSY, OP_RETN,
|
// BAREOPs without conditions
|
// BAREOPs without conditions
|
OP_BREAK, OP_NOOP,
|
OP_BREAK, OP_NOOP,
|
// Error condition--undefined operand
|
// Error condition--undefined operand
|
OP_NONE
|
OP_NONE
|
} LEXOPCODE;
|
} LEXOPCODE;
|
Line 93... |
Line 93... |
// node type is one of:
|
// node type is one of:
|
// 'B' a branch with two sides
|
// 'B' a branch with two sides
|
// 'N' a number
|
// 'N' a number
|
// 'I' an identifier
|
// 'I' an identifier
|
// 'A' ?? an address ?? would we need this?
|
// 'A' ?? an address ?? would we need this?
|
|
virtual ~AST(void) {}
|
char m_node_type;
|
char m_node_type;
|
virtual bool isdefined(void) = 0;
|
virtual bool isdefined(void) = 0;
|
virtual int eval(void) = 0;
|
virtual int eval(void) = 0;
|
virtual void reduce(void) = 0;
|
virtual void reduce(void) = 0;
|
virtual void dump(FILE *fp) = 0;
|
virtual void dump(FILE *fp) = 0;
|
Line 191... |
Line 192... |
AST *m_left, *m_right;
|
AST *m_left, *m_right;
|
|
|
AST_BRANCH(int op, AST *l, AST *r)
|
AST_BRANCH(int op, AST *l, AST *r)
|
: m_op(op), m_left(l), m_right(r) { m_node_type = 'B';
|
: m_op(op), m_left(l), m_right(r) { m_node_type = 'B';
|
}
|
}
|
|
~AST_BRANCH(void) {
|
|
if (m_left)
|
|
delete m_left;
|
|
if (m_right)
|
|
delete m_right;
|
|
}
|
|
|
bool isdefined(void) {
|
bool isdefined(void) {
|
return ((m_left)&&(m_right)
|
return ((m_left)&&(m_right)
|
&&(m_left->isdefined())
|
&&(m_left->isdefined())
|
&&(m_right->isdefined()));
|
&&(m_right->isdefined()));
|
}
|
}
|
~AST_BRANCH(void) { delete m_left; delete m_right; }
|
|
int eval(void);
|
int eval(void);
|
void reduce(void);
|
void reduce(void);
|
void dump(FILE *fp) {
|
void dump(FILE *fp) {
|
fprintf(fp, "(");
|
fprintf(fp, "(");
|
m_left->dump(fp);
|
m_left->dump(fp);
|