oqlinterpreter.class.inc.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?
  2. class OqlNormalizeException extends OQLException
  3. {
  4. public function __construct($sIssue, $sInput, OqlName $oName, $aExpecting = null)
  5. {
  6. parent::__construct($sIssue, $sInput, 0, $oName->GetPos(), $oName->GetValue(), $aExpecting);
  7. }
  8. }
  9. class OqlInterpreterException extends OQLException
  10. {
  11. }
  12. class OqlInterpreter
  13. {
  14. public $m_sQuery;
  15. public function __construct($sQuery)
  16. {
  17. $this->m_sQuery = $sQuery;
  18. }
  19. protected function Parse()
  20. {
  21. $oLexer = new OQLLexer($this->m_sQuery);
  22. $oParser = new OQLParser($this->m_sQuery);
  23. while($oLexer->yylex())
  24. {
  25. $oParser->doParse($oLexer->token, $oLexer->value, $oLexer->getTokenPos());
  26. }
  27. $res = $oParser->doFinish();
  28. return $res;
  29. }
  30. public function ParseQuery()
  31. {
  32. $oRes = $this->Parse();
  33. if (!$oRes instanceof OqlQuery)
  34. {
  35. throw new OqlException('Expecting an OQL query', $this->m_sQuery, 0, 0, get_class($oRes), array('OqlQuery'));
  36. }
  37. return $oRes;
  38. }
  39. public function ParseExpression()
  40. {
  41. $oRes = $this->Parse();
  42. if (!$oRes instanceof Expression)
  43. {
  44. throw new OqlException('Expecting an OQL expression', $this->m_sQuery, 0, 0, get_class($oRes), array('Expression'));
  45. }
  46. return $oRes;
  47. }
  48. }
  49. ?>