home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / sql_1.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  3.8 KB  |  155 lines

  1. /*++
  2.  
  3. Copyright (C) 1999 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     SQL_1.H
  8.  
  9. Abstract:
  10.  
  11.     Level 1 Syntax SQL Parser
  12.  
  13. History:
  14.  
  15. --*/
  16.  
  17. #ifndef _SQL_1_H_
  18. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  19. #define _SQL_1_H_
  20.  
  21. struct SQL_LEVEL_1_TOKEN
  22. {
  23.     enum { OP_EXPRESSION = 1, TOKEN_AND, TOKEN_OR, TOKEN_NOT };
  24.     enum { IFUNC_NONE = 0, IFUNC_UPPER = 1, IFUNC_LOWER = 2 };
  25.  
  26.     int nTokenType; //  OP_EXPRESSION,TOKEN_AND, TOKEN_OR, TOKEN_NOT
  27.     
  28.  
  29.     // If the field is a OP_EXPRESSION, then the following are used.
  30.     enum { OP_EQUAL = 1, OP_NOT_EQUAL, OP_EQUALorGREATERTHAN,
  31.                OP_EQUALorLESSTHAN, OP_LESSTHAN, OP_GREATERTHAN, OP_LIKE };
  32.     
  33.     BSTR    pPropertyName;        // Name of the property on which the operator is applied
  34.     int     nOperator;            // Operator that is applied on property
  35.     BOOL    bConstIsStrNumeric;    // True if the vConstValue is a BSTR and is a UINT32 or any 64bit number
  36.     VARIANT vConstValue;        // Value applied by operator
  37.     BSTR    pPropName2;         // Property compared to.
  38.  
  39.     DWORD   dwPropertyFunction; // 0=no instrinsic function applied
  40.     DWORD   dwConstFunction;    // "
  41.     
  42.     SQL_LEVEL_1_TOKEN();
  43.     SQL_LEVEL_1_TOKEN(SQL_LEVEL_1_TOKEN&);
  44.    ~SQL_LEVEL_1_TOKEN(); 
  45.     SQL_LEVEL_1_TOKEN& operator=(SQL_LEVEL_1_TOKEN &Src);
  46.     
  47.     void Dump(FILE *);
  48. };
  49.  
  50.  
  51. // Contains RPN version of expression.
  52. // ===================================
  53.  
  54. struct SQL_LEVEL_1_RPN_EXPRESSION
  55. {
  56.     int nNumTokens;
  57.     int nCurSize;
  58.     SQL_LEVEL_1_TOKEN *pArrayOfTokens;
  59.     BSTR bsClassName;
  60.  
  61.     int nNumberOfProperties;          // Zero means all properties selected
  62.     int nCurPropSize;
  63.     BSTR *pbsRequestedPropertyNames;  // Array of property names which values are to be returned if
  64.     
  65.     SQL_LEVEL_1_RPN_EXPRESSION();
  66.    ~SQL_LEVEL_1_RPN_EXPRESSION();
  67.    
  68.    //Note: this method deletes the token it is passed as an argument
  69.     void AddToken(SQL_LEVEL_1_TOKEN *pTok);
  70.     void AddToken(SQL_LEVEL_1_TOKEN &pTok);
  71.     void AddProperty(LPWSTR pProp);
  72.     void Dump(const char *pszTextFile);
  73. };
  74.  
  75.  
  76. class SQL1_Parser
  77. {
  78.     CGenLexer *m_pLexer;
  79.     int        m_nLine;
  80.     wchar_t*   m_pTokenText;
  81.     int        m_nCurrentToken;
  82.     SQL_LEVEL_1_RPN_EXPRESSION* m_pExpression;
  83.  
  84.     //Cleanup used by d'tor and SetSource
  85.     void Cleanup();
  86.  
  87.     //Init used by c'tor and SetSource
  88.     void Init(CGenLexSource *pSrc);
  89.  
  90.     // Semantic transfer variables.
  91.     // ============================
  92.     VARIANT    m_vTypedConst;
  93.     int        m_nRelOp;
  94.     DWORD      m_dwConstFunction;
  95.     DWORD      m_dwPropFunction;
  96.     LPWSTR     m_pIdent;
  97.     LPWSTR     m_pPropComp;
  98.     BOOL       m_bConstIsStrNumeric;
  99.         
  100.     // Parsing functions.
  101.     // ==================
  102.     BOOL Next();
  103.     
  104.     int parse();
  105.  
  106.     int prop_list();
  107.     int class_name();
  108.     int opt_where();
  109.     int expr();
  110.     int property_name();
  111.     int prop_list_2();
  112.     int term();
  113.     int expr2();
  114.     int simple_expr();
  115.     int term2();
  116.     int leading_ident_expr();
  117.     int finalize();
  118.     int rel_operator();
  119.     int equiv_operator();
  120.     int comp_operator();
  121.     int is_operator();
  122.     int trailing_prop_expr();
  123.     int trailing_prop_expr2();
  124.     int trailing_or_null();
  125.     int trailing_const_expr();
  126.     int unknown_func_expr();
  127.     int typed_constant();
  128.  
  129. public:
  130.     enum { 
  131.         SUCCESS,
  132.         SYNTAX_ERROR,
  133.         LEXICAL_ERROR,
  134.         FAILED,
  135.         BUFFER_TOO_SMALL
  136.         };
  137.  
  138.     SQL1_Parser(CGenLexSource *pSrc);
  139.    ~SQL1_Parser();
  140.  
  141.     int GetQueryClass(LPWSTR pBuf, int nBufSize);
  142.        
  143.     int Parse(SQL_LEVEL_1_RPN_EXPRESSION **pOutput);
  144.         // use operator delete on pOutput
  145.             
  146.     int CurrentLine() { return m_nLine; }
  147.     LPWSTR CurrentToken() { return m_pTokenText; }
  148.     void SetSource(CGenLexSource *pSrc);
  149. };
  150.  
  151. #pragma option pop /*P_O_Pop*/
  152. #endif
  153.  
  154.  
  155.