Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.2 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Declaration of Expression.
  4. //
  5. #pragma once
  6. #include "engcontrol.h"
  7. // The expression class takes input of a well-formed expression in infix (the order appearing in the script source)
  8. // notation. The blocks are converted to postfix notation and appeanded to the given script's exprs list and followed
  9. // with an _end block.
  10. // A working stack is used to perform the conversion. The stack to use is passed by reference so that the same stack
  11. // may be used to evaluate multiple expressions. This allows the stack to grow as needed until it reaches the max size
  12. // needed to process the expressions, minimizing reallocation thereafter.
  13. class Expression
  14. {
  15. public:
  16. Expression(Script &script, SmartRef::Stack<ExprBlock> &stack, ExprBlocks *peblocks) : m_script(script), m_stack(stack), m_eblocks(peblocks ? *peblocks : m_script.exprs) {}
  17. // Note: For unary - (negation), use TOKEN_sub instead of TOKEN_op_minus.
  18. HRESULT Add(ExprBlock b) { if (b.k == ExprBlock::_end) {assert(false); return E_INVALIDARG;} return m_e.Add(b); }
  19. HRESULT Generate();
  20. private:
  21. HRESULT InfixToPostfix();
  22. private:
  23. ExprBlocks m_e;
  24. Script &m_script;
  25. SmartRef::Stack<ExprBlock> &m_stack;
  26. ExprBlocks &m_eblocks;
  27. };