Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1.  
  2. #ifndef __substitute_h__
  3. #define __substitute_h__
  4.  
  5. #include "yacasbase.h"
  6. #include "lispobject.h"
  7. #include "lispenvironment.h"
  8.  
  9.  
  10. /** Behaviour for substituting sub-expressions.
  11.  */
  12. class SubstBehaviourBase : public YacasBase
  13. {
  14. public:
  15.     virtual ~SubstBehaviourBase();
  16.     virtual LispBoolean Matches(LispPtr& aResult, LispPtr& aElement) = 0;
  17. };
  18.  
  19. /** main routine that can perform substituting of expressions
  20.  */
  21. void InternalSubstitute(LispPtr& aTarget, LispPtr& aSource,
  22.                         SubstBehaviourBase& aBehaviour);
  23.  
  24.  
  25. /** Substing one expression for another. The simplest form
  26.  * of substitution
  27.  */
  28. class SubstBehaviour : public SubstBehaviourBase
  29. {
  30. public:
  31.     SubstBehaviour(LispEnvironment& aEnvironment,LispPtr& aToMatch,
  32.                   LispPtr& aToReplaceWith);
  33.     virtual LispBoolean Matches(LispPtr& aResult, LispPtr& aElement);
  34. private:
  35.     LispEnvironment& iEnvironment;
  36.     LispPtr& iToMatch;
  37.     LispPtr& iToReplaceWith;
  38. };
  39.  
  40. /** subst behaviour for changing the local variables to have unique
  41.  * names.
  42.  */
  43. class LocalSymbolBehaviour : public SubstBehaviourBase
  44. {
  45. public:
  46.     LocalSymbolBehaviour(LispEnvironment& aEnvironment,
  47.                          LispString ** aOriginalNames,
  48.                          LispString ** aNewNames, LispInt aNrNames);
  49.     virtual LispBoolean Matches(LispPtr& aResult, LispPtr& aElement);
  50. private:
  51.     LispEnvironment& iEnvironment;
  52.     LispString ** iOriginalNames;
  53.     LispString ** iNewNames;
  54.     LispInt iNrNames;
  55. };
  56.  
  57. /** subst behaviour for backquote mechanism as in LISP.
  58.  * When typing `(...) all occurrences of @a will be
  59.  * replaced with:
  60.  * 1) a evaluated if a is an atom
  61.  * 2) function call with function name replaced by evaluated
  62.  *    head of function if a is a function. For instance, if
  63.  *    a is f(x) and f is g, then f(x) gets replaced by g(x)
  64.  */
  65. class BackQuoteBehaviour : public SubstBehaviourBase
  66. {
  67. public:
  68.     BackQuoteBehaviour(LispEnvironment& aEnvironment)
  69.         : iEnvironment(aEnvironment) {};
  70.     virtual LispBoolean Matches(LispPtr& aResult, LispPtr& aElement);
  71.     LispEnvironment& iEnvironment;
  72. };
  73.  
  74.  
  75.  
  76.  
  77. #endif
  78.  
  79.