Mercurial > hg > octave-lyh
annotate libinterp/parse-tree/pt-binop.h @ 16253:a89cf57ba3a5
partial cleanup of continuation handling in lexer
* lex.h, lex.ll (octave_lexer::handle_continuation): New function.
(octave_lexer::finish_comment): Move to octave_lexer::finish_comment.
Don't return token. New argument, looking_at_continuation. If not
handling continuation, unput newline character.
(^{S}*{CCHAR}\{{S}*{NL}): Call yyless before finishing comment.
(^{S}*{CCHAR}\{{S}*{NL}, <BLOCK_COMMENT_START>^{S}*{CCHAR}\{{S}*{NL},
<LINE_COMMENT_START>{ANY_INCLUDING_NL},
<LINE_COMMENT_START>{S}*{CCHAR}.*{NL}): Don't return token.
(<LINE_COMMENT_START>{S}*{CCHAR}.*{NL}): Don't give COMMAND_START
start state special treatment.
({CONT}{S}*{NL}|{CONT}{S}*{COMMENT}):
Call octave_lexer::handle_continuation.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 09 Mar 2013 21:44:14 -0500 |
parents | 2fc554ffbc28 |
children |
rev | line source |
---|---|
2980 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
2980 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2980 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2980 | 20 |
21 */ | |
22 | |
23 #if !defined (octave_tree_binop_h) | |
24 #define octave_tree_binop_h 1 | |
25 | |
26 #include <string> | |
27 | |
28 class tree_walker; | |
29 | |
30 class octave_value; | |
31 class octave_value_list; | |
32 class octave_lvalue; | |
33 | |
34 #include "ov.h" | |
35 #include "pt-exp.h" | |
7336 | 36 #include "symtab.h" |
2980 | 37 |
38 // Binary expressions. | |
39 | |
40 class | |
41 tree_binary_expression : public tree_expression | |
42 { | |
43 public: | |
44 | |
45 tree_binary_expression (int l = -1, int c = -1, | |
10313 | 46 octave_value::binary_op t |
47 = octave_value::unknown_binary_op) | |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
48 : tree_expression (l, c), op_lhs (0), op_rhs (0), etype (t), |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
49 eligible_for_braindead_shortcircuit (false) { } |
2980 | 50 |
51 tree_binary_expression (tree_expression *a, tree_expression *b, | |
10313 | 52 int l = -1, int c = -1, |
53 octave_value::binary_op t | |
54 = octave_value::unknown_binary_op) | |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
55 : tree_expression (l, c), op_lhs (a), op_rhs (b), etype (t), |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
56 eligible_for_braindead_shortcircuit (false) { } |
2980 | 57 |
58 ~tree_binary_expression (void) | |
59 { | |
60 delete op_lhs; | |
61 delete op_rhs; | |
62 } | |
63 | |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
64 void mark_braindead_shortcircuit (const std::string& file) |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
65 { |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
66 if (etype == octave_value::op_el_and |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
67 || etype == octave_value::op_el_or) |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
68 { |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
69 if (file.empty ()) |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
70 warning_with_id ("Octave:possible-matlab-short-circuit-operator", |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
71 "possible Matlab-style short-circuit operator at line %d, column %d", |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
72 line (), column ()); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
73 else |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
74 warning_with_id ("Octave:possible-matlab-short-circuit-operator", |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
75 "%s: possible Matlab-style short-circuit operator at line %d, column %d", |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
76 file.c_str (), line (), column ()); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
77 |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
78 eligible_for_braindead_shortcircuit = true; |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
79 |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
80 op_lhs->mark_braindead_shortcircuit (file); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
81 op_rhs->mark_braindead_shortcircuit (file); |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
82 } |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
83 } |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
84 |
4267 | 85 bool has_magic_end (void) const |
86 { | |
87 return ((op_lhs && op_lhs->has_magic_end ()) | |
10313 | 88 || (op_rhs && op_rhs->has_magic_end ())); |
4267 | 89 } |
90 | |
4023 | 91 bool is_binary_expression (void) const { return true; } |
92 | |
3933 | 93 bool rvalue_ok (void) const { return true; } |
2980 | 94 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
95 octave_value rvalue1 (int nargout = 1); |
2980 | 96 |
3010 | 97 octave_value_list rvalue (int nargout); |
2980 | 98 |
3523 | 99 std::string oper (void) const; |
2980 | 100 |
4023 | 101 octave_value::binary_op op_type (void) const { return etype; } |
102 | |
2980 | 103 tree_expression *lhs (void) { return op_lhs; } |
104 tree_expression *rhs (void) { return op_rhs; } | |
105 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
106 tree_expression *dup (symbol_table::scope_id scope, |
10313 | 107 symbol_table::context_id context) const; |
5861 | 108 |
2980 | 109 void accept (tree_walker& tw); |
110 | |
111 protected: | |
112 | |
113 // The operands for the expression. | |
114 tree_expression *op_lhs; | |
115 tree_expression *op_rhs; | |
116 | |
117 private: | |
118 | |
119 // The type of the expression. | |
120 octave_value::binary_op etype; | |
2988 | 121 |
11091
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
122 // TRUE if this is an | or & expression in the condition of an IF |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
123 // or WHILE statement. |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
124 bool eligible_for_braindead_shortcircuit; |
5677f3f7b5fa
Matlab compatible short-circuit behavior for & and | operators
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
125 |
2988 | 126 // No copying! |
127 | |
128 tree_binary_expression (const tree_binary_expression&); | |
129 | |
130 tree_binary_expression& operator = (const tree_binary_expression&); | |
2980 | 131 }; |
132 | |
133 // Boolean expressions. | |
134 | |
135 class | |
136 tree_boolean_expression : public tree_binary_expression | |
137 { | |
138 public: | |
139 | |
140 enum type | |
141 { | |
142 unknown, | |
143 bool_and, | |
144 bool_or | |
145 }; | |
146 | |
147 tree_boolean_expression (int l = -1, int c = -1, type t = unknown) | |
148 : tree_binary_expression (l, c), etype (t) { } | |
149 | |
150 tree_boolean_expression (tree_expression *a, tree_expression *b, | |
10313 | 151 int l = -1, int c = -1, type t = unknown) |
2980 | 152 : tree_binary_expression (a, b, l, c), etype (t) { } |
153 | |
154 ~tree_boolean_expression (void) { } | |
155 | |
4023 | 156 bool is_boolean_expression (void) const { return true; } |
157 | |
3933 | 158 bool rvalue_ok (void) const { return true; } |
2980 | 159 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
160 octave_value rvalue1 (int nargout = 1); |
2980 | 161 |
162 octave_value_list rvalue (int nargout); | |
163 | |
3523 | 164 std::string oper (void) const; |
2980 | 165 |
4023 | 166 type op_type (void) const { return etype; } |
167 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
168 tree_expression *dup (symbol_table::scope_id scope, |
10313 | 169 symbol_table::context_id context) const; |
5861 | 170 |
2980 | 171 private: |
172 | |
173 // The type of the expression. | |
174 type etype; | |
2988 | 175 |
176 // No copying! | |
177 | |
178 tree_boolean_expression (const tree_boolean_expression&); | |
179 | |
180 tree_boolean_expression& operator = (const tree_boolean_expression&); | |
2980 | 181 }; |
182 | |
183 #endif |