/***************************************************************************
**
**    $Header:   D:/EPSLDV1/SRC/LOG/SYMSYN.H__   1.8   20 Jun 1996 09:30:32   ZJRD  $
**
**    $Log:   D:/EPSLDV1/SRC/LOG/SYMSYN.H__  $
** 
**    Rev 1.8   20 Jun 1996 09:30:32   ZJRD
** EasyPack/SLD Version 1.20a
** 
**    Rev 1.6   10 Jun 1996 10:25:10   ZJRD
** EasyPack/SLD Version 1.20
** 
**    Rev 1.4   29 May 1996 09:37:58   ZJRD
** No change.
** 
**    Rev 1.3   16 May 1996 09:01:08   ZJRD
** No change.
** 
**    Rev 1.2   10 May 1996 09:15:24   ZJRD
** EasyPack/SLD Version 1.93
** 
**    Rev 1.1   02 May 1996 10:31:14   ZJRD
** EasyPack/SLD Version 1.92
** 
**    Rev 1.1   18 Apr 1996 12:56:40   Shirley
** EasyPack/SLD Version 1.91
** 
**    Rev 1.0   12 Apr 1996 10:36:02   Shirley
** Initial revision.
** 
****************************************************************************/
/****************************************************************************
**
**  Name:  SYMSYN.H
**
**  Description:
**      All expression object's basic class have the prefix: CSymSyntax
**      Major header file used by expression.
**
**  Status:  CODED
**
**    Rev 1.0   13 March 1996 8:30:00am   Gates Hua
** Initial revision.
**
**  Copyright (C) 1996 Microtek International.  All rights reserved.
**
*****************************************************************************/
#ifndef _SYMSYN_H_
#define _SYMSYN_H_
                       /****************************
                        *                          *
                        *       INCLUDE FILES      *
                        *                          *
                        ****************************/
#include "symtoken.h"               
#include "symstack.h"
#include "symcalc.h"

                       /****************************
                        *                          *
                        *        DEFINITIONS       *
                        *                          *
                        ****************************/
    
                       /****************************
                        *                          *
                        *        PROTOTYPES        *
                        *                          *
                        ****************************/

/**********************************************************************
*                                                                     *
*    The Expression use this class to save token information          *
*                                                                     *
**********************************************************************/                        
class CSymSyntax : public CSymToken {
////////////////////////////////////////////////////////////////////
//   Algorithm
//   1. put input string in CSymObj's m_strCmd
//   2. analyse tokens
//   3. check syntax
//   4. calculate C expression's value
//       4.1 get one token : if NULL goto 4.3 
//           push operand to m_stkOperand; 
//       Or  push operator to m_stkOperator;
//       4.2 Check operator , Will the operand be calculated ?
//           Yes :  pop operand to calculate , 
//					push result to m_stkOperand ; goto 4.1
//           No : goto 4.1
//		 4.3 pop operand to C expression's value
////////////////////////////////////////////////////////////////////    
public :
    CSymSyntax() : CSymToken() {
		m_bValidSyntax = TRUE;
		m_bValidResult = TRUE;
		m_pValue = 0;
    }
    CSymSyntax(const char *str) : CSymToken() {
		m_bValidSyntax = TRUE;
		m_bValidResult = TRUE;
		m_pValue = 0;
		InitStrCmd( str );
    }
    ~CSymSyntax() {          
    	if ( m_pValue ) delete m_pValue;
		DeleteOperandStack();
		DeleteOperatorStack();
		DeleteSyntaxStack();
		DeleteArrayNum();
    }
     
protected :
	class CSymStack m_stkOperand;   // operand stack;
	class CSymStack m_stkOperator;  // operator stack;
	class CSymStack m_stkSyntax;  // syntax stack;
	class CSymStack m_stkArrayNum;  // array number;
	class CSymCalc *m_pValue;
	BOOL m_bValidSyntax;
	BOOL m_bValidResult;

public :
	int DisplayValue(char* temp) {
		if ( m_pValue ) return ( m_pValue->DisplayValue(temp) );
		return FAILURE;
	}

public :
	int GetExpAddr(ADDRESS_TYPE& addr);
	int GetTypeIndex(TYPE_INDEX& type);
	int IsComplexResult(int& nFlag);
	int IsSymbol(int& nFlag);
	int IsUserVariable();
	
public :
	void DeleteOperandStack(void);
	void DeleteOperatorStack(void);
	void DeleteSyntaxStack(void);
	void DeleteArrayNum(void);
	
public :
	int IsVariable(void);
	int CalculateValue(void);

	int Init(const char *str,int flag = 0);	
	int CheckSyntax(void);               
	void DisplayValue(void) {
		if ( m_pValue ) m_pValue->Display();
	}
	int GetStatus(BOOL& bResult) {
		if ( m_pValue ) return ( m_pValue->GetStatus(bResult) );
		return FAILURE;
	}
	int GetExpName(CString& strName) {
		return GetAllTokenNameToStr(strName);
	}
	int ReflushExpress(void);
};
                
#endif
/******************************** E O F ***********************************/
