
/* Semantics.h - Declaration file for semantic related actions
	by Jason Plumb */

/* Global table of operations */

#define LT		0
#define	GT		1
#define	LE		2
#define GE		3
#define	NE		4
#define EQ		5
#define ADD		6
#define SUB		7
#define MUL		8
#define DIV		9
#define ASSIGN	10
#define READ	11
#define READLN	12
#define WRITE	13
#define WRITELN	14
#define JMP		15
#define JTRUE	16
#define JFALSE	17
#define JGT		18
#define JLE		19
#define JNE		20

/* Declarations for the quad table */
typedef struct TQTNODE{
	
	int operation;					//This is an index into the operation table
	int operand1;
	int oper1offset;				//Offset to operand 1
	int operand2;
	int oper2offset;				//Offset to operand 2
	int result;
	int resultoffset;				//Offset to result

}QTNode, *pQTNode;

#define QT_LENGTH	10000		/* Max length of quad table */

typedef struct TQTABLE{
//	int iSize;
	int iNQ;					/* Index of next quad */
	QTNode nodes[QT_LENGTH];
}QTable;

/* Quad table related function defs */
void qt_init();
int qt_NQ();
int gentemp();		// Generates a temporary variable
void genquad(int iOperation, int iOperand1, int iOper1Offset, 
							 int iOperand2, int iOper2Offset, 
							 int iResult,   int iResultOffset);
void quad(int iIndex, int iWhich, int iVal);
void qt_debug_print();

#define SAS_LENGTH	100
#define NULLOP		-9999999
#define IFTAG		-9999998
#define IOTAG		-9999997
#define ELSEIFTAG	-9999996
#define EMPTY_STACK	-9999995

/* Semantic action stack */
typedef struct TSAS{

	int iSize;
	int nodes[SAS_LENGTH];

}SAS;


/* Semantics related function definitions */
void sas_init();
bool sas_push(int iVal);
int sas_pop();