home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-base.tgz / octave-1.1.1p1-base.tar / fsf / octave / src / tree-cmd.h < prev    next >
C/C++ Source or Header  |  1995-01-03  |  5KB  |  269 lines

  1. // tree-cmd.h                                          -*- C++ -*-
  2. /*
  3.  
  4. Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton
  5.  
  6. This file is part of Octave.
  7.  
  8. Octave is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. Octave is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with Octave; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. */
  23.  
  24. #if !defined (octave_tree_cmd_h)
  25. #define octave_tree_cmd_h 1
  26.  
  27. #include <iostream.h>
  28.  
  29. class tree_statement_list;
  30. class tree_global_init_list;
  31. class tree_if_command_list;
  32. class tree_expression;
  33. class tree_index_expression;
  34. class tree_constant;
  35. class symbol_record;
  36.  
  37. class tree_command;
  38. class tree_global_command;
  39. class tree_while_command;
  40. class tree_for_command;
  41. class tree_if_command;
  42. class tree_unwind_protect_command;
  43. class tree_break_command;
  44. class tree_continue_command;
  45. class tree_return_command;
  46.  
  47. #include "tree-base.h"
  48.  
  49. // A base class for commands.
  50.  
  51. class
  52. tree_command : public tree
  53. {
  54. public:
  55.   tree_command (int l = -1, int c = -1) : tree (l, c) { }
  56.  
  57.   virtual void eval (void) = 0;
  58. };
  59.  
  60. class
  61. tree_global_command : public tree_command
  62. {
  63. public:
  64.   tree_global_command (int l = -1, int c = -1) : tree_command (l, c)
  65.     { init_list = 0; }
  66.  
  67.   tree_global_command (tree_global_init_list *t, int l = -1, int c = -1)
  68.     : tree_command (l, c)
  69.       { init_list = t; }
  70.  
  71.   ~tree_global_command (void);
  72.  
  73.   void eval (void);
  74.  
  75.   void print_code (ostream& os);
  76.  
  77. private:
  78.   tree_global_init_list *init_list;
  79. };
  80.  
  81. // While.
  82.  
  83. class
  84. tree_while_command : public tree_command
  85. {
  86. public:
  87.   tree_while_command (int l = -1, int c = -1) : tree_command (l, c)
  88.     {
  89.       expr = 0;
  90.       list = 0;
  91.     }
  92.  
  93.   tree_while_command (tree_expression *e, int l = -1, int c = -1)
  94.     : tree_command (l, c)
  95.       {
  96.     expr = e;
  97.     list = 0;
  98.       }
  99.  
  100.   tree_while_command (tree_expression *e, tree_statement_list *lst,
  101.               int l = -1, int c = -1)
  102.     : tree_command (l, c)
  103.       {
  104.     expr = e;
  105.     list = lst;
  106.       }
  107.  
  108.   ~tree_while_command (void);
  109.  
  110.   void eval (void);
  111.  
  112.   void eval_error (void);
  113.  
  114.   void print_code (ostream& os);
  115.  
  116. private:
  117.   tree_expression *expr;    // Expression to test.
  118.   tree_statement_list *list;    // List of commands to execute.
  119. };
  120.  
  121. // For.
  122.  
  123. class
  124. tree_for_command : public tree_command
  125. {
  126. public:
  127.   tree_for_command (int l = -1, int c = -1) : tree_command (l, c)
  128.     {
  129.       id = 0;
  130.       expr = 0;
  131.       list = 0;
  132.     }
  133.  
  134.   tree_for_command (tree_index_expression *ident, tree_expression *e,
  135.             tree_statement_list *lst, int l = -1, int c = -1)
  136.     : tree_command (l, c)
  137.       {
  138.     id = ident;
  139.     expr = e;
  140.     list = lst;
  141.       }
  142.  
  143.   ~tree_for_command (void);
  144.  
  145.   void eval (void);
  146.  
  147.   void eval_error (void);
  148.  
  149.   void print_code (ostream& os);
  150.  
  151. private:
  152.   void do_for_loop_once (tree_constant *rhs, int& quit);
  153.  
  154.   tree_index_expression *id;    // Identifier to modify.
  155.   tree_expression *expr;    // Expression to evaluate.
  156.   tree_statement_list *list;    // List of commands to execute.
  157. };
  158.  
  159. // If.
  160.  
  161. class
  162. tree_if_command : public tree_command
  163. {
  164. public:
  165.   tree_if_command (int l = -1, int c = -1) : tree_command (l, c)
  166.     { list = 0; }
  167.  
  168.   tree_if_command (tree_if_command_list *lst, int l = -1, int c = -1)
  169.     : tree_command (l, c)
  170.       { list = lst; }
  171.  
  172.   ~tree_if_command (void);
  173.  
  174.   void eval (void);
  175.  
  176.   void eval_error (void);
  177.  
  178.   void print_code (ostream& os);
  179.  
  180. private:
  181.   tree_if_command_list *list;
  182. };
  183.  
  184. // Simple exception handling.
  185.  
  186. class
  187. tree_unwind_protect_command : public tree_command
  188. {
  189. public:
  190.   tree_unwind_protect_command (int l = -1, int c = -1) : tree_command (l, c)
  191.     {
  192.       unwind_protect_code = 0;
  193.       cleanup_code = 0;
  194.     }
  195.  
  196.   tree_unwind_protect_command (tree_statement_list *tc,
  197.                    tree_statement_list *cc,
  198.                    int l = -1, int c = -1)
  199.     : tree_command (l, c)
  200.       {
  201.     unwind_protect_code = tc;
  202.     cleanup_code = cc;
  203.       }
  204.  
  205.   ~tree_unwind_protect_command (void);
  206.  
  207.   void eval (void);
  208.  
  209.   void print_code (ostream& os);
  210.  
  211. private:
  212.   tree_statement_list *unwind_protect_code;
  213.   tree_statement_list *cleanup_code;
  214. };
  215.  
  216. // Break.
  217.  
  218. class
  219. tree_break_command : public tree_command
  220. {
  221. public:
  222.   tree_break_command (int l = -1, int c = -1) : tree_command (l, c) { }
  223.  
  224.   ~tree_break_command (void) { }
  225.  
  226.   void eval (void);
  227.  
  228.   void print_code (ostream& os);
  229. };
  230.  
  231. // Continue.
  232.  
  233. class
  234. tree_continue_command : public tree_command
  235. {
  236. public:
  237.   tree_continue_command (int l = -1, int c = -1) : tree_command (l, c) { }
  238.  
  239.   ~tree_continue_command (void) { }
  240.  
  241.   void eval (void);
  242.  
  243.   void print_code (ostream& os);
  244. };
  245.  
  246. // Return.
  247.  
  248. class
  249. tree_return_command : public tree_command
  250. {
  251. public:
  252.   tree_return_command (int l = -1, int c = -1) : tree_command (l, c) { }
  253.  
  254.   ~tree_return_command (void) { }
  255.  
  256.   void eval (void);
  257.  
  258.   void print_code (ostream& os);
  259. };
  260.  
  261. #endif
  262.  
  263. /*
  264. ;;; Local Variables: ***
  265. ;;; mode: C++ ***
  266. ;;; page-delimiter: "^/\\*" ***
  267. ;;; End: ***
  268. */
  269.