//***************************************************************************
//
//								PARSER.H
//
//***************************************************************************

#ifndef ABLPARSE_H
#define	ABLPARSE_H

#include "ablgen.h"
#include "ablsymt.h"
#include "ablerr.h"

//***************************************************************************
namespace ABL
{

typedef enum {
	USE_EXPR,
	USE_TARGET,
	USE_REFPARAM
} UseType;

typedef enum {
	BLOCK_MODULE,
	BLOCK_ROUTINE
} BlockType;

//***************************************************************************

//----------
// FUNCTIONS

TypePtr baseType (TypePtr thisType);

TypePtr expression (void);
TypePtr variable (SymTableNodePtr variableIdPtr);
TypePtr arraySubscriptList (TypePtr typePtr);
//TypePtr routineCall (SymTableNodePtr routineIdPtr, BOOL parmCheckFlag);
TypePtr baseType (void);
void checkRelationalOpTypes (TypePtr type1, TypePtr type2);
long isAssignTypeCompatible (TypePtr type1, TypePtr type2);
void ifTokenGet (TokenCodeType tokenCode);
void ifTokenGetElseError (TokenCodeType tokenCode, SyntaxErrorType errCode);

// DECL routines
void declarations (SymTableNodePtr routineIdPtr, long allowFunctions, long allowStates);
void constDefinitions (void);
void doConst (SymTableNodePtr constantIdPtr);
void varDeclarations (SymTableNodePtr routineIdPtr);
void varOrFieldDeclarations (SymTableNodePtr routineIdPtr, long offset);
void typeDefinitions (void);
TypePtr doType (void);
TypePtr identifierType (SymTableNodePtr idPtr);
TypePtr enumerationType (void);
TypePtr subrangeType (void);
TypePtr arrayType (void);
long arraySize (TypePtr typePtr);
TypePtr makeStringType (long length);

// ROUTINE functions
void module (void);
SymTableNodePtr moduleHeader (void);
void routine (void);
SymTableNodePtr functionHeader (void);
SymTableNodePtr formalParamList (long* count, long* totalSize);
TypePtr routineCall (SymTableNodePtr routineIdPtr, long paramCheckFlag);
TypePtr declaredRoutineCall (SymTableNodePtr routineIdPtr, long paramCheckFlag);
void actualParamList (SymTableNodePtr routineIdPtr, long paramCheckFlag);
void block (SymTableNodePtr routineIdPtr);
void state (void);
SymTableNodePtr stateHeader (void);

// STATEMNT routines
void compoundStatement (void);
void assignmentStatement (SymTableNodePtr varIdPtr);
void repeatStatement (void);
void whileStatement (void);
void ifStatement (void);
void forStatement (void);
void switchStatement (void);
void statement (void);

// STANDARD routines
TypePtr stdPrint (void);
TypePtr stdAbs (void);
TypePtr stdRound (void);
TypePtr stdTrunc (void);
TypePtr stdSqrt (void);
TypePtr stdRandom (void);
TypePtr standardRoutineCall (SymTableNodePtr routineIdPtr);

// FILE routines
long openSourceFile (char* sourceFileName);
long closeSourceFile (void);

#if !ANALYZE_ON
#define	analyzeConstDefn(idPtr)
#define	analyzeVarDecl(idPtr)
#define	analyzeTypeDefn(idPtr)
#define	analyzeRoutineHeader(idPtr)
#define	analyzeBlock(idPtr)
#endif
}
//***************************************************************************

#endif

