mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
49 lines
912 B
C
49 lines
912 B
C
#pragma once
|
|
|
|
#include "literal.h"
|
|
#include "opcodes.h"
|
|
|
|
//nodes are the intermediaries between parsers and compilers
|
|
typedef union _node Node;
|
|
|
|
typedef enum NodeType {
|
|
NODE_ERROR,
|
|
NODE_LITERAL, //a simple value
|
|
NODE_UNARY, //one child
|
|
NODE_BINARY, //two children, left and right
|
|
// NODE_GROUPING,
|
|
} NodeType;
|
|
|
|
typedef struct NodeLiteral {
|
|
NodeType type;
|
|
Literal literal;
|
|
} NodeLiteral;
|
|
|
|
typedef struct NodeUnary {
|
|
NodeType type;
|
|
Opcode opcode;
|
|
Node* child;
|
|
} NodeUnary;
|
|
|
|
typedef struct NodeBinary {
|
|
NodeType type;
|
|
Opcode opcode;
|
|
Node* left;
|
|
Node* right;
|
|
} NodeBinary;
|
|
|
|
union _node {
|
|
NodeType type;
|
|
NodeLiteral atomic;
|
|
NodeUnary unary;
|
|
NodeBinary binary;
|
|
};
|
|
|
|
void freeNode(Node* node);
|
|
void emitNodeLiteral(Node** nodeHandle, Literal literal);
|
|
void emitNodeUnary(Node** nodeHandle, Opcode opcode);
|
|
void emitNodeBinary(Node** nodeHandle, Node* rhs, Opcode opcode);
|
|
|
|
void printNode(Node* node);
|
|
|