Mercurial > octave-dspies
comparison src/lex.l @ 4214:b9317f3973ec
[project @ 2002-12-04 04:57:01 by jwe]
author | jwe |
---|---|
date | Wed, 04 Dec 2002 04:57:01 +0000 |
parents | e96f52432059 |
children | ccfdb55c8156 |
comparison
equal
deleted
inserted
replaced
4213:f8f7fc582c62 | 4214:b9317f3973ec |
---|---|
30 | 30 |
31 #include <cctype> | 31 #include <cctype> |
32 #include <cstring> | 32 #include <cstring> |
33 | 33 |
34 #include <string> | 34 #include <string> |
35 #include <stack> | |
35 | 36 |
36 #ifdef HAVE_UNISTD_H | 37 #ifdef HAVE_UNISTD_H |
37 #ifdef HAVE_SYS_TYPES_H | 38 #ifdef HAVE_SYS_TYPES_H |
38 #include <sys/types.h> | 39 #include <sys/types.h> |
39 #endif | 40 #endif |
40 #include <unistd.h> | 41 #include <unistd.h> |
41 #endif | 42 #endif |
42 | |
43 #include "SLStack.h" | |
44 | 43 |
45 #include "cmd-edit.h" | 44 #include "cmd-edit.h" |
46 #include "quit.h" | 45 #include "quit.h" |
47 #include "lo-sstream.h" | 46 #include "lo-sstream.h" |
48 | 47 |
85 // information. This has to appear before lex.h is included, because | 84 // information. This has to appear before lex.h is included, because |
86 // one of the macros defined there uses token_stack. | 85 // one of the macros defined there uses token_stack. |
87 // | 86 // |
88 // XXX FIXME XXX -- this should really be static, but that causes | 87 // XXX FIXME XXX -- this should really be static, but that causes |
89 // problems on some systems. | 88 // problems on some systems. |
90 SLStack <token*> token_stack; | 89 std::stack <token*> token_stack; |
91 | 90 |
92 // Did eat_whitespace() eat a space or tab, or a newline, or both? | 91 // Did eat_whitespace() eat a space or tab, or a newline, or both? |
93 | 92 |
94 typedef int yum_yum; | 93 typedef int yum_yum; |
95 | 94 |
97 const yum_yum ATE_SPACE_OR_TAB = 1; | 96 const yum_yum ATE_SPACE_OR_TAB = 1; |
98 const yum_yum ATE_NEWLINE = 2; | 97 const yum_yum ATE_NEWLINE = 2; |
99 | 98 |
100 // Is the closest nesting level a square bracket, squiggly brace or a paren? | 99 // Is the closest nesting level a square bracket, squiggly brace or a paren? |
101 | 100 |
102 class bracket_brace_paren_nesting_level : public SLStack <int> | 101 class bracket_brace_paren_nesting_level |
103 { | 102 { |
104 public: | 103 public: |
105 | 104 |
106 bracket_brace_paren_nesting_level (void) : SLStack<int> () { } | 105 bracket_brace_paren_nesting_level (void) : context () { } |
107 | 106 |
108 ~bracket_brace_paren_nesting_level (void) { } | 107 ~bracket_brace_paren_nesting_level (void) { } |
109 | 108 |
110 void bracket (void) { push (BRACKET); } | 109 void bracket (void) { context.push (BRACKET); } |
111 bool is_bracket (void) { return ! empty () && top () == BRACKET; } | 110 bool is_bracket (void) |
112 | 111 { return ! context.empty () && context.top () == BRACKET; } |
113 void brace (void) { push (BRACE); } | 112 |
114 bool is_brace (void) { return ! empty () && top () == BRACE; } | 113 void brace (void) { context.push (BRACE); } |
115 | 114 bool is_brace (void) |
116 void paren (void) { push (PAREN); } | 115 { return ! context.empty () && context.top () == BRACE; } |
117 bool is_paren (void) { return ! empty () && top () == PAREN; } | 116 |
118 | 117 void paren (void) { context.push (PAREN); } |
119 bool none (void) { return empty (); } | 118 bool is_paren (void) |
120 | 119 { return ! context.empty () && context.top () == PAREN; } |
121 void remove (void) { if (! empty ()) SLStack<int>::pop (); } | 120 |
121 bool none (void) { return context.empty (); } | |
122 | |
123 void remove (void) { if (! context.empty ()) context.pop (); } | |
124 | |
125 void clear (void) { while (! context.empty ()) context.pop (); } | |
122 | 126 |
123 private: | 127 private: |
128 | |
129 std::stack<int> context; | |
124 | 130 |
125 enum { BRACKET = 1, BRACE = 2, PAREN = 3 }; | 131 enum { BRACKET = 1, BRACE = 2, PAREN = 3 }; |
126 | 132 |
127 bracket_brace_paren_nesting_level (const bracket_brace_paren_nesting_level&); | 133 bracket_brace_paren_nesting_level (const bracket_brace_paren_nesting_level&); |
128 | 134 |
817 nesting_level.clear (); | 823 nesting_level.clear (); |
818 | 824 |
819 // Clear out the stack of token info used to track line and column | 825 // Clear out the stack of token info used to track line and column |
820 // numbers. | 826 // numbers. |
821 while (! token_stack.empty ()) | 827 while (! token_stack.empty ()) |
822 delete token_stack.pop (); | 828 { |
829 delete token_stack.top (); | |
830 token_stack.pop (); | |
831 } | |
823 | 832 |
824 // Can be reset by defining a function. | 833 // Can be reset by defining a function. |
825 if (! (reading_script_file || reading_fcn_file)) | 834 if (! (reading_script_file || reading_fcn_file)) |
826 { | 835 { |
827 current_input_column = 1; | 836 current_input_column = 1; |