Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/parse-private.h @ 16263:9acb86e6ac90
4/10 commits reworking the lexer
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 11 Mar 2013 14:28:11 -0400 |
parents | 2fc554ffbc28 |
children |
rev | line source |
---|---|
14333
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
3 Copyright (C) 2012 John W. Eaton |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 This file is part of Octave. |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 option) any later version. |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 for more details. |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 */ |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 #if !defined (octave_parse_private_h) |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 #define octave_parse_private_h 1 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 #include <stack> |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #include "symtab.h" |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 // Keep track of symbol table information when parsing functions. |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 class symtab_context |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 { |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 private: |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 class frame |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 { |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 public: |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 frame (symbol_table::scope_id s, symbol_table::scope_id c) |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 : m_scope (s), m_context (c) { } |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 frame (const frame& f) : m_scope (f.m_scope), m_context (f.m_context) { } |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 frame& operator = (const frame& f) |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 { |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 if (&f != this) |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 { |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 m_scope = f.m_scope; |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 m_context = f.m_context; |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 } |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 return *this; |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 } |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 ~frame (void) { } |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 symbol_table::scope_id scope (void) const { return m_scope; } |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 symbol_table::scope_id context (void) const { return m_context; } |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 private: |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 symbol_table::scope_id m_scope; |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 symbol_table::scope_id m_context; |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 }; |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 std::stack<frame> frame_stack; |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 public: |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 symtab_context (void) : frame_stack () { } |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 void clear (void) |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 { |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 while (! frame_stack.empty ()) |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 frame_stack.pop (); |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 } |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 bool empty (void) const { return frame_stack.empty (); } |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 void pop (void) |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 { |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 frame tmp = frame_stack.top (); |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 symbol_table::set_scope_and_context (tmp.scope (), tmp.context ()); |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 frame_stack.pop (); |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 } |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
86 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 void push (void) |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 { |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 frame_stack.push (frame (symbol_table::current_scope (), |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 symbol_table::current_context ())); |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 } |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 }; |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 extern symtab_context parser_symtab_context; |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 |
6dd710b73150
maint: add yet another file omitted from earlier commit
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 #endif |