GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
parse.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_parse_h)
27#define octave_parse_h 1
28
29#include "octave-config.h"
30
31#include <cstdio>
32
33#include <deque>
34#include <map>
35#include <memory>
36#include <set>
37#include <string>
38
39#include "input.h"
40#include "lex.h"
41#include "pt-misc.h"
42#include "symscope.h"
43#include "token.h"
44
45class octave_function;
48
49namespace octave
50{
51 class comment_list;
52 class parse_exception;
53 class tree;
54 class tree_anon_fcn_handle;
55 class tree_arg_size_spec;
56 class tree_arg_validation;
57 class tree_arg_validation_fcns;
58 class tree_args_block_attribute_list;
59 class tree_args_block_validation_list;
60 class tree_argument_list;
61 class tree_arguments_block;
62 class tree_array_list;
63 class tree_cell;
64 class tree_classdef;
65 class tree_classdef_attribute_list;
66 class tree_classdef_body;
67 class tree_classdef_enum_block;
68 class tree_classdef_enum_list;
69 class tree_classdef_events_block;
70 class tree_classdef_events_list;
71 class tree_classdef_methods_block;
72 class tree_classdef_methods_list;
73 class tree_classdef_properties_block;
74 class tree_classdef_property_list;
75 class tree_classdef_superclass_list;
76 class tree_colon_expression;
77 class tree_command;
78 class tree_constant;
79 class tree_decl_command;
80 class tree_decl_init_list;
81 class tree_expression;
82 class tree_fcn_handle;
83 class tree_function_def;
84 class tree_identifier;
85 class tree_if_clause;
86 class tree_if_command;
87 class tree_if_command_list;
88 class tree_index_expression;
89 class tree_matrix;
90 class tree_matrix;
91 class tree_parameter_list;
92 class tree_spmd_command;
93 class tree_statement;
94 class tree_statement_list;
95 class tree_statement_listtree_statement;
96 class tree_switch_case;
97 class tree_switch_case_list;
98 class tree_switch_command;
99}
100
101#include "ovl.h"
102
103// Nonzero means print parser debugging info (-d).
104extern int octave_debug;
105
106namespace octave
107{
109 {
110 private:
111
113 {
114 public:
115
116 typedef std::pair<symbol_scope, std::string> value_type;
117
118 typedef std::deque<value_type>::iterator iterator;
119 typedef std::deque<value_type>::const_iterator const_iterator;
120
121 typedef std::deque<value_type>::reverse_iterator reverse_iterator;
122 typedef std::deque<value_type>::const_reverse_iterator const_reverse_iterator;
123
124 parent_scope_info (void) = delete;
125
128 { }
129
130 // No copying!
131
133
135
136 ~parent_scope_info (void) = default;
137
138 OCTINTERP_API std::size_t size (void) const;
139
140 OCTINTERP_API void push (const value_type& elt);
141
142 OCTINTERP_API void push (const symbol_scope& id);
143
144 OCTINTERP_API void pop (void);
145
146 OCTINTERP_API bool name_ok (const std::string& name);
147
148 OCTINTERP_API bool name_current_scope (const std::string& name);
149
150 OCTINTERP_API symbol_scope parent_scope (void) const;
151
152 OCTINTERP_API std::string parent_name (void) const;
153
154 OCTINTERP_API void clear (void);
155
156 private:
157
159 std::deque<value_type> m_info;
160 std::set<std::string> m_all_names;
161 };
162
163 public:
164
165 OCTINTERP_API base_parser (base_lexer& lxr);
166
167 // No copying!
168
169 base_parser (const base_parser&) = delete;
170
172
173 virtual ~base_parser (void);
174
175 base_lexer& get_lexer (void) const { return m_lexer; }
176
177 bool at_end_of_input (void) const { return m_lexer.m_end_of_input; }
178
179 OCTINTERP_API void reset (void);
180
181 void classdef_object (const std::shared_ptr<tree_classdef>& obj)
182 {
183 m_classdef_object = obj;
184 }
185
186 std::shared_ptr<tree_classdef> classdef_object (void) const
187 {
188 return m_classdef_object;
189 }
190
191 OCTINTERP_API void statement_list (std::shared_ptr<tree_statement_list>& lst);
192
193 std::shared_ptr<tree_statement_list> statement_list (void) const
194 {
195 return m_stmt_list;
196 }
197
198 void parsing_subfunctions (bool flag)
199 {
201 }
202
203 bool parsing_subfunctions (void) const
204 {
206 }
207
208 void parsing_local_functions (bool flag)
209 {
211 }
212
213 bool parsing_local_functions (void) const
214 {
216 }
217
218 int curr_fcn_depth (void) const
219 {
220 return m_curr_fcn_depth;
221 }
222
223 void endfunction_found (bool flag)
224 {
225 m_endfunction_found = flag;
226 }
227
228 bool endfunction_found (void) const
229 {
230 return m_endfunction_found;
231 }
232
233 // Error messages for mismatched end tokens.
234 OCTINTERP_API void
236
237 // Check to see that end tokens are properly matched.
238 OCTINTERP_API bool end_token_ok (token *tok, token::end_tok_type expected);
239
240 // Handle pushing symbol table for new function scope.
241 OCTINTERP_API bool push_fcn_symtab (void);
242
243 // Build a constant.
244 OCTINTERP_API tree_constant * make_constant (token *tok_val);
245
246 OCTINTERP_API tree_black_hole * make_black_hole (void);
247
248 OCTINTERP_API tree_matrix * make_matrix (tree_argument_list *row);
249
250 OCTINTERP_API tree_matrix *
252
253 OCTINTERP_API tree_cell * make_cell (tree_argument_list *row);
254
255 OCTINTERP_API tree_cell *
257
258 // Build a function handle.
259 OCTINTERP_API tree_fcn_handle * make_fcn_handle (token *tok_val);
260
261 // Build an anonymous function handle.
262 OCTINTERP_API tree_anon_fcn_handle *
264 tree_expression *expr, const filepos& at_pos);
265
266 // Build a colon expression.
267 OCTINTERP_API tree_expression *
269 tree_expression *incr = nullptr);
270
271 // Build a binary expression.
272 OCTINTERP_API tree_expression *
273 make_binary_op (int op, tree_expression *op1, token *tok_val,
274 tree_expression *op2);
275
276 // Build a boolean expression.
277 OCTINTERP_API tree_expression *
278 make_boolean_op (int op, tree_expression *op1, token *tok_val,
279 tree_expression *op2);
280
281 // Build a prefix expression.
282 OCTINTERP_API tree_expression *
283 make_prefix_op (int op, tree_expression *op1, token *tok_val);
284
285 // Build a postfix expression.
286 OCTINTERP_API tree_expression *
287 make_postfix_op (int op, tree_expression *op1, token *tok_val);
288
289 // Build an unwind-protect command.
290 OCTINTERP_API tree_command *
292 tree_statement_list *cleanup, token *end_tok,
293 comment_list *lc, comment_list *mc);
294
295 // Build a try-catch command.
296 OCTINTERP_API tree_command *
298 char catch_sep, tree_statement_list *cleanup,
299 token *end_tok, comment_list *lc,
300 comment_list *mc);
301
302 // Build a while command.
303 OCTINTERP_API tree_command *
304 make_while_command (token *while_tok, tree_expression *expr,
305 tree_statement_list *body, token *end_tok,
306 comment_list *lc);
307
308 // Build a do-until command.
309 OCTINTERP_API tree_command *
311 tree_expression *expr, comment_list *lc);
312
313 // Build a for command.
314 OCTINTERP_API tree_command *
315 make_for_command (int tok_id, token *for_tok, tree_argument_list *lhs,
316 tree_expression *expr, tree_expression *maxproc,
317 tree_statement_list *body, token *end_tok,
318 comment_list *lc);
319
320 // Build a break command.
321 OCTINTERP_API tree_command * make_break_command (token *break_tok);
322
323 // Build a continue command.
324 OCTINTERP_API tree_command * make_continue_command (token *continue_tok);
325
326 // Build a return command.
327 OCTINTERP_API tree_command * make_return_command (token *return_tok);
328
329 // Build an spmd command.
330
331 OCTINTERP_API tree_spmd_command *
333 token *end_tok, comment_list *lc, comment_list *tc);
334
335 // Start an if command.
336 OCTINTERP_API tree_if_command_list *
338
339 // Finish an if command.
340 OCTINTERP_API tree_if_command *
342 token *end_tok, comment_list *lc);
343
344 // Build an elseif clause.
345 OCTINTERP_API tree_if_clause *
346 make_elseif_clause (token *elseif_tok, tree_expression *expr,
348
349 OCTINTERP_API tree_if_clause *
350 make_else_clause (token *else_tok, comment_list *lc,
351 tree_statement_list *list);
352
353 OCTINTERP_API tree_if_command_list *
355
356 // Finish a switch command.
357 OCTINTERP_API tree_switch_command *
358 finish_switch_command (token *switch_tok, tree_expression *expr,
359 tree_switch_case_list *list, token *end_tok,
360 comment_list *lc);
361
362 OCTINTERP_API tree_switch_case_list *
364
365 // Build a switch case.
366 OCTINTERP_API tree_switch_case *
367 make_switch_case (token *case_tok, tree_expression *expr,
369
370 OCTINTERP_API tree_switch_case *
372 tree_statement_list *list);
373
374 OCTINTERP_API tree_switch_case_list *
376
377 // Build an assignment to a variable.
378 OCTINTERP_API tree_expression *
379 make_assign_op (int op, tree_argument_list *lhs, token *eq_tok,
380 tree_expression *rhs);
381
382 // Define a script.
383 OCTINTERP_API void
385
386 // Handle identifier that is recognized as a function name.
387 OCTINTERP_API tree_identifier *
389
390 // Define a function.
391 OCTINTERP_API tree_function_def *
392 make_function (token *fcn_tok, tree_parameter_list *ret_list,
393 tree_identifier *id, tree_parameter_list *param_list,
394 tree_statement_list *body, tree_statement *end_fcn_stmt,
395 comment_list *lc);
396
397 // Begin defining a function.
398 OCTINTERP_API octave_user_function *
400 tree_statement_list *body, tree_statement *end_function);
401
402 // Create a no-op statement for end_function.
403 OCTINTERP_API tree_statement *
404 make_end (const std::string& type, bool eof,
405 const filepos& beg_pos, const filepos& end_pos);
406
407 // Do most of the work for defining a function.
408 OCTINTERP_API octave_user_function *
410
411 // Finish defining a function.
412 OCTINTERP_API tree_function_def *
415 int l, int c);
416
417 OCTINTERP_API tree_statement_list *
419
420 // Make an arguments validation block.
421 OCTINTERP_API tree_arguments_block *
422 make_arguments_block (token *arguments_tok,
424 tree_args_block_validation_list *validation_list,
425 token *end_tok, comment_list *lc, comment_list *tc);
426
427 OCTINTERP_API tree_args_block_attribute_list *
429
430 // Make an argument validation.
431 OCTINTERP_API tree_arg_validation *
433 tree_identifier *class_name,
434 tree_arg_validation_fcns *validation_fcns,
435 tree_expression *default_value);
436
437 // Make an argument validation list.
438 OCTINTERP_API tree_args_block_validation_list *
440
441 // Append an argument validation to an existing list.
442 OCTINTERP_API tree_args_block_validation_list *
444 tree_arg_validation *arg_validation);
445
446 // Make an argument size specification object.
447 OCTINTERP_API tree_arg_size_spec *
449
450 // Make a list of argument validation functions.
451 OCTINTERP_API tree_arg_validation_fcns *
453
454 // Reset state after parsing function.
455 OCTINTERP_API void
457
458 OCTINTERP_API tree_classdef *
461 tree_classdef_body *body, token *end_tok,
462 comment_list *lc, comment_list *tc);
463
464 OCTINTERP_API tree_classdef_properties_block *
468 token *end_tok, comment_list *lc,
469 comment_list *tc);
470
471 OCTINTERP_API tree_classdef_property_list *
473
474 OCTINTERP_API tree_classdef_property *
477
478 OCTINTERP_API tree_classdef_property_list *
481
482 OCTINTERP_API tree_classdef_methods_block *
486 token *end_tok, comment_list *lc,
487 comment_list *tc);
488
489 OCTINTERP_API tree_classdef_events_block *
493 token *end_tok, comment_list *lc,
494 comment_list *tc);
495
496 OCTINTERP_API tree_classdef_events_list *
498
499 OCTINTERP_API tree_classdef_event *
501
502 OCTINTERP_API tree_classdef_events_list *
505
506 OCTINTERP_API tree_classdef_enum_block *
510 token *end_tok, comment_list *lc,
511 comment_list *tc);
512
513 OCTINTERP_API tree_classdef_enum_list *
515
516 OCTINTERP_API tree_classdef_enum *
518 comment_list *lc);
519
520 OCTINTERP_API tree_classdef_enum_list *
522 tree_classdef_enum *elt);
523
524 OCTINTERP_API tree_classdef_superclass_list *
526
527 OCTINTERP_API tree_classdef_superclass *
529
530 OCTINTERP_API tree_classdef_superclass_list *
533
534 OCTINTERP_API tree_classdef_attribute_list *
536
537 OCTINTERP_API tree_classdef_attribute *
539 tree_expression *expr = nullptr);
540
541 OCTINTERP_API tree_classdef_attribute *
543
544 OCTINTERP_API tree_classdef_attribute_list *
547
548 OCTINTERP_API tree_classdef_body *
550
551 OCTINTERP_API tree_classdef_body *
553
554 OCTINTERP_API tree_classdef_body *
556
557 OCTINTERP_API tree_classdef_body *
559
560 OCTINTERP_API tree_classdef_body *
563
564 OCTINTERP_API tree_classdef_body *
567
568 OCTINTERP_API tree_classdef_body *
571
572 OCTINTERP_API tree_classdef_body *
575
576 OCTINTERP_API octave_user_function *
579
580 OCTINTERP_API tree_function_def *
582 tree_parameter_list *ret_list,
583 comment_list *cl);
584
585 OCTINTERP_API tree_classdef_methods_list *
587
588 OCTINTERP_API tree_classdef_methods_list *
590 tree_function_def *fcn_def);
591
592 OCTINTERP_API bool
594 tree_statement_list *local_fcns);
595
596 // Make an index expression.
597 OCTINTERP_API tree_index_expression *
599 tree_argument_list *args, char type);
600
601 // Make an indirect reference expression.
602 OCTINTERP_API tree_index_expression *
603 make_indirect_ref (tree_expression *expr, const std::string&);
604
605 // Make an indirect reference expression with dynamic field name.
606 OCTINTERP_API tree_index_expression *
608
609 // Make a declaration command.
610 OCTINTERP_API tree_decl_command *
611 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst);
612
613 OCTINTERP_API tree_decl_init_list *
615
616 OCTINTERP_API tree_decl_elt *
617 make_decl_elt (tree_identifier *id, token *eq_op = nullptr,
618 tree_expression *expr = nullptr);
619
620 OCTINTERP_API tree_decl_init_list *
622
623 // Validate an function parameter list.
624 OCTINTERP_API bool
627 // Validate matrix or cell
628 OCTINTERP_API bool validate_array_list (tree_expression *e);
629
630 // Validate matrix object used in "[lhs] = ..." assignments.
631 OCTINTERP_API tree_argument_list *
633
634 // Finish building an array_list (common action for finish_matrix
635 // and finish_cell).
636 OCTINTERP_API tree_expression *
637 finish_array_list (tree_array_list *a, token *open_delim,
638 token *close_delim);
639
640 // Finish building a matrix list.
641 OCTINTERP_API tree_expression *
642 finish_matrix (tree_matrix *m, token *open_delim, token *close_delim);
643
644 // Finish building a cell list.
645 OCTINTERP_API tree_expression *
646 finish_cell (tree_cell *c, token *open_delim, token *close_delim);
647
648 OCTINTERP_API tree_identifier *
649 make_identifier (token *ident);
650
651 OCTINTERP_API tree_superclass_ref *
652 make_superclass_ref (token *superclassref);
653
654 OCTINTERP_API tree_metaclass_query *
655 make_metaclass_query (token *metaquery);
656
657 // Set the print flag for a statement based on the separator type.
658 OCTINTERP_API tree_statement_list *
660
661 // Finish building a statement.
662 template <typename T>
663 OCTINTERP_API tree_statement * make_statement (T *arg);
664
665 // Create a statement list.
666 OCTINTERP_API tree_statement_list *
668
669 // Append a statement to an existing statement list.
670 OCTINTERP_API tree_statement_list *
672 tree_statement *stmt, bool warn_missing_semi);
673
674 OCTINTERP_API tree_argument_list *
676
677 OCTINTERP_API tree_argument_list *
679
680 OCTINTERP_API tree_parameter_list *
682
683 OCTINTERP_API tree_parameter_list *
685
686 OCTINTERP_API tree_parameter_list *
688 tree_identifier *id);
689
690 OCTINTERP_API tree_parameter_list *
692
693 OCTINTERP_API tree_parameter_list *
695
696 // Don't allow parsing command syntax. If the parser/lexer is
697 // reset, this setting is also reset to the default (allow command
698 // syntax).
699 OCTINTERP_API void disallow_command_syntax (void);
700
701 // Generic error messages.
702 OCTINTERP_API void bison_error (const std::string& s);
703 OCTINTERP_API void bison_error (const std::string& s, const filepos& pos);
704 OCTINTERP_API void bison_error (const std::string& s, int line, int column);
705 OCTINTERP_API void bison_error (const std::list<parse_exception>& pe);
706 OCTINTERP_API void bison_error (const parse_exception& pe);
707
708 friend OCTINTERP_API octave_value
709 parse_fcn_file (interpreter& interp, const std::string& full_file,
710 const std::string& file, const std::string& dir_name,
711 const std::string& dispatch_type,
712 const std::string& package_name, bool require_file,
713 bool force_script, bool autoload, bool relative_lookup);
714
715 // Thih interface allows push or pull parsers to be used
716 // equivalently, provided that the push parser also owns its input
717 // method (see below). Alternatively, the push parser interface may
718 // use a separate run method and completely separate input from
719 // lexical analysis and parsing.
720
721 virtual int run (void) = 0;
722
723 // Check primary script or function generated by the parser for
724 // semantic errors.
725 OCTINTERP_API bool validate_primary_fcn (void);
726
727 OCTINTERP_API bool finish_input (tree_statement_list *lst,
728 bool at_eof = false);
729
730 protected:
731
732 // Contains error message if Bison-generated parser returns non-zero
733 // status.
734 std::string m_parse_error_msg;
735
736 // Have we found an explicit end to a function?
738
739 // TRUE means we are in the process of autoloading a function.
741
742 // TRUE means the current function file was found in a relative path
743 // element.
745
746 // FALSE if we are still at the primary function. Subfunctions can
747 // only be declared inside function files.
749
750 // TRUE if we are parsing local functions defined at after a
751 // classdef block. Local functions can only be declared inside
752 // classdef files.
754
755 // Maximum function depth detected. Used to determine whether
756 // we have nested functions or just implicitly ended subfunctions.
758
759 // = 0 currently outside any function.
760 // = 1 inside the primary function or a subfunction.
761 // > 1 means we are looking at a function definition that seems to be
762 // inside a function. Note that the function still might not be a
763 // nested function.
765
766 // Scope where we install all subfunctions and nested functions. Only
767 // used while reading function files.
769
770 // Name of the current class when we are parsing class methods or
771 // constructors.
772 std::string m_curr_class_name;
773
774 // Name of the current package when we are parsing an element contained
775 // in a package directory (+-directory).
777
778 // Nested function scopes and names currently being parsed.
780
781 // Pointer to the primary user function or user script function.
783
784 // List of subfunction names, initially in the order they are
785 // installed in the symbol table, then ordered as they appear in the
786 // file. Eventually stashed in the primary function object.
787 std::list<std::string> m_subfunction_names;
788
789 // Pointer to the classdef object we just parsed, if any.
790 std::shared_ptr<tree_classdef> m_classdef_object;
791
792 // Result of parsing input.
793 std::shared_ptr <tree_statement_list> m_stmt_list;
794
795 // State of the lexer.
797
798 // Internal state of the Bison parser.
800
801 private:
802
803 // Maybe print a warning if an assignment expression is used as the
804 // test in a logical expression.
805 OCTINTERP_API void maybe_warn_assign_as_truth_value (tree_expression *expr);
806
807 // Maybe print a warning about switch labels that aren't constants.
808 OCTINTERP_API void maybe_warn_variable_switch_label (tree_expression *expr);
809
810 // Maybe print a warning.
811 OCTINTERP_API void maybe_warn_missing_semi (tree_statement_list *);
812 };
813
814 // Publish externally used friend functions.
815
816 extern OCTINTERP_API octave_value
817 parse_fcn_file (interpreter& interp, const std::string& full_file,
818 const std::string& file, const std::string& dir_name,
819 const std::string& dispatch_type,
820 const std::string& package_name, bool require_file,
821 bool force_script, bool autoload, bool relative_lookup);
822
823 class parser : public base_parser
824 {
825 public:
826
828 : base_parser (*(new lexer (interp)))
829 { }
830
831 parser (FILE *file, interpreter& interp)
832 : base_parser (*(new lexer (file, interp)))
833 { }
834
835 parser (FILE *file, interpreter& interp, std::string encoding)
836 : base_parser (*(new lexer (file, interp, encoding)))
837 { }
838
839 parser (const std::string& eval_string, interpreter& interp)
840 : base_parser (*(new lexer (eval_string, interp)))
841 { }
842
843 // The lexer must be allocated with new. The parser object
844 // takes ownership of and deletes the lexer object in its
845 // destructor.
846
848 : base_parser (*lxr)
849 { }
850
851 // No copying!
852
853 parser (const parser&) = delete;
854
855 parser& operator = (const parser&) = delete;
856
857 ~parser (void) = default;
858
859 OCTINTERP_API int run (void);
860 };
861
863 {
864 public:
865
867 : base_parser (*(new push_lexer (interp))),
868 m_interpreter (interp), m_reader ()
869 { }
870
871 // The parser assumes ownership of READER, which must be created
872 // with new.
873
875 : base_parser (*(new push_lexer (interp))),
876 m_interpreter (interp), m_reader (reader)
877 { }
878
879 // No copying!
880
881 push_parser (const push_parser&) = delete;
882
884
885 ~push_parser (void) = default;
886
887 // Use the push parser in the same way as the pull parser. The
888 // parser arranges for input through the M_READER object. See, for
889 // example, interpreter::main_loop.
890
891 OCTINTERP_API int run (void);
892
893 // Parse INPUT. M_READER is not used. The user is responsible for
894 // collecting input.
895
896 OCTINTERP_API int run (const std::string& input, bool eof);
897
898 private:
899
901
902 std::shared_ptr<input_reader> m_reader;
903 };
904
905 extern OCTINTERP_API std::string
906 get_help_from_file (const std::string& nm, bool& symbol_found,
907 std::string& file);
908
909 extern OCTINTERP_API std::string
910 get_help_from_file (const std::string& nm, bool& symbol_found);
911
912 extern OCTINTERP_API octave_value
913 load_fcn_from_file (const std::string& file_name,
914 const std::string& dir_name = "",
915 const std::string& dispatch_type = "",
916 const std::string& package_name = "",
917 const std::string& fcn_name = "",
918 bool autoload = false);
919
920 extern OCTINTERP_API void
921 source_file (const std::string& file_name,
922 const std::string& context = "",
923 bool verbose = false, bool require_file = true);
924
925 extern OCTINTERP_API octave_value_list
926 feval (const char *name,
927 const octave_value_list& args = octave_value_list (),
928 int nargout = 0);
929
930 extern OCTINTERP_API octave_value_list
931 feval (const std::string& name,
932 const octave_value_list& args = octave_value_list (),
933 int nargout = 0);
934
935 extern OCTINTERP_API octave_value_list
937 const octave_value_list& args = octave_value_list (),
938 int nargout = 0);
939
940 extern OCTINTERP_API octave_value_list
941 feval (const octave_value& val,
942 const octave_value_list& args = octave_value_list (),
943 int nargout = 0);
944
945 extern OCTINTERP_API octave_value_list
946 feval (const octave_value_list& args, int nargout = 0);
947
948 extern OCTINTERP_API void
950}
951
952#endif
OCTINTERP_API void clear(void)
Definition: oct-parse.cc:6679
parent_scope_info(const parent_scope_info &)=delete
std::deque< value_type >::iterator iterator
Definition: parse.h:118
OCTINTERP_API bool name_ok(const std::string &name)
Definition: oct-parse.cc:6618
OCTINTERP_API void push(const symbol_scope &id)
parent_scope_info & operator=(const parent_scope_info &)=delete
OCTINTERP_API bool name_current_scope(const std::string &name)
Definition: oct-parse.cc:6656
std::deque< value_type >::const_iterator const_iterator
Definition: parse.h:119
std::deque< value_type >::reverse_iterator reverse_iterator
Definition: parse.h:121
OCTINTERP_API std::string parent_name(void) const
Definition: oct-parse.cc:6674
std::pair< symbol_scope, std::string > value_type
Definition: parse.h:116
OCTINTERP_API std::size_t size(void) const
Definition: oct-parse.cc:6594
OCTINTERP_API symbol_scope parent_scope(void) const
Definition: oct-parse.cc:6668
std::deque< value_type >::const_reverse_iterator const_reverse_iterator
Definition: parse.h:122
OCTINTERP_API void pop(void)
Definition: oct-parse.cc:6612
OCTINTERP_API void push(const value_type &elt)
Definition: oct-parse.cc:6600
std::set< std::string > m_all_names
Definition: parse.h:160
std::deque< value_type > m_info
Definition: parse.h:159
parent_scope_info(base_parser &parser)
Definition: parse.h:126
OCTINTERP_API tree_argument_list * append_argument_list(tree_argument_list *list, tree_expression *expr)
Definition: oct-parse.cc:9471
OCTINTERP_API tree_arg_validation * make_arg_validation(tree_arg_size_spec *size_spec, tree_identifier *class_name, tree_arg_validation_fcns *validation_fcns, tree_expression *default_value)
Definition: oct-parse.cc:8271
OCTINTERP_API void bison_error(const std::list< parse_exception > &pe)
OCTINTERP_API tree_decl_command * make_decl_command(int tok, token *tok_val, tree_decl_init_list *lst)
Definition: oct-parse.cc:9028
OCTINTERP_API bool validate_primary_fcn(void)
Definition: oct-parse.cc:9918
OCTINTERP_API tree_classdef_attribute_list * append_classdef_attribute(tree_classdef_attribute_list *list, tree_classdef_attribute *elt)
Definition: oct-parse.cc:8709
std::shared_ptr< tree_statement_list > statement_list(void) const
Definition: parse.h:193
OCTINTERP_API void disallow_command_syntax(void)
Definition: oct-parse.cc:9512
OCTINTERP_API tree_command * make_unwind_command(token *unwind_tok, tree_statement_list *body, tree_statement_list *cleanup, token *end_tok, comment_list *lc, comment_list *mc)
Definition: oct-parse.cc:7310
OCTINTERP_API octave_user_function * frob_function(tree_identifier *id, octave_user_function *fcn)
OCTINTERP_API tree_cell * make_cell(tree_argument_list *row)
Definition: oct-parse.cc:9347
OCTINTERP_API tree_index_expression * make_indirect_ref(tree_expression *expr, const std::string &)
OCTINTERP_API tree_fcn_handle * make_fcn_handle(token *tok_val)
Definition: oct-parse.cc:6953
bool m_parsing_local_functions
Definition: parse.h:753
OCTINTERP_API tree_switch_command * finish_switch_command(token *switch_tok, tree_expression *expr, tree_switch_case_list *list, token *end_tok, comment_list *lc)
Definition: oct-parse.cc:7683
octave_value m_primary_fcn
Definition: parse.h:782
OCTINTERP_API tree_switch_case_list * make_switch_case_list(tree_switch_case *switch_case)
Definition: oct-parse.cc:7723
OCTINTERP_API void recover_from_parsing_function(void)
Definition: oct-parse.cc:8322
OCTINTERP_API tree_argument_list * validate_matrix_for_assignment(tree_expression *e)
Definition: oct-parse.cc:9185
OCTINTERP_API tree_classdef_attribute_list * make_classdef_attribute_list(tree_classdef_attribute *attr)
Definition: oct-parse.cc:8688
OCTINTERP_API tree_classdef_body * make_classdef_body(tree_classdef_properties_block *pb)
Definition: oct-parse.cc:8716
OCTINTERP_API tree_expression * make_assign_op(int op, tree_argument_list *lhs, token *eq_tok, tree_expression *rhs)
Definition: oct-parse.cc:7764
OCTINTERP_API tree_if_command * finish_if_command(token *if_tok, tree_if_command_list *list, token *end_tok, comment_list *lc)
Definition: oct-parse.cc:7610
OCTINTERP_API tree_classdef_properties_block * make_classdef_properties_block(token *tok_val, tree_classdef_attribute_list *a, tree_classdef_property_list *plist, token *end_tok, comment_list *lc, comment_list *tc)
Definition: oct-parse.cc:8427
void * m_parser_state
Definition: parse.h:799
OCTINTERP_API bool validate_array_list(tree_expression *e)
Definition: oct-parse.cc:9160
OCTINTERP_API tree_function_def * finish_classdef_external_method(octave_user_function *fcn, tree_parameter_list *ret_list, comment_list *cl)
Definition: oct-parse.cc:8817
OCTINTERP_API base_parser(base_lexer &lxr)
Definition: oct-parse.cc:6685
OCTINTERP_API tree_identifier * make_identifier(token *ident)
Definition: oct-parse.cc:9362
OCTINTERP_API tree_classdef_events_list * make_classdef_events_list(tree_classdef_event *e)
Definition: oct-parse.cc:8580
OCTINTERP_API tree_index_expression * make_indirect_ref(tree_expression *expr, tree_expression *field)
OCTINTERP_API tree_matrix * append_matrix_row(tree_matrix *matrix, tree_argument_list *row)
Definition: oct-parse.cc:9326
OCTINTERP_API bool finish_input(tree_statement_list *lst, bool at_eof=false)
Definition: oct-parse.cc:9889
OCTINTERP_API tree_classdef * make_classdef(token *tok_val, tree_classdef_attribute_list *a, tree_identifier *id, tree_classdef_superclass_list *sc, tree_classdef_body *body, token *end_tok, comment_list *lc, comment_list *tc)
Definition: oct-parse.cc:8350
OCTINTERP_API tree_parameter_list * make_parameter_list(tree_parameter_list::in_or_out io)
Definition: oct-parse.cc:9478
OCTINTERP_API tree_parameter_list * append_parameter_list(tree_parameter_list *list, tree_decl_elt *t)
Definition: oct-parse.cc:9498
OCTINTERP_API tree_classdef_property * make_classdef_property(comment_list *lc, tree_identifier *id, tree_arg_validation *av)
Definition: oct-parse.cc:8489
OCTINTERP_API tree_classdef_superclass_list * make_classdef_superclass_list(tree_classdef_superclass *sc)
Definition: oct-parse.cc:8669
base_parser(const base_parser &)=delete
bool parsing_subfunctions(void) const
Definition: parse.h:203
std::shared_ptr< tree_classdef > m_classdef_object
Definition: parse.h:790
OCTINTERP_API tree_if_command_list * append_if_clause(tree_if_command_list *list, tree_if_clause *clause)
Definition: oct-parse.cc:7674
parent_scope_info m_function_scopes
Definition: parse.h:779
int m_curr_fcn_depth
Definition: parse.h:764
OCTINTERP_API tree_command * make_return_command(token *return_tok)
Definition: oct-parse.cc:7556
virtual ~base_parser(void)
Definition: oct-parse.cc:6695
int curr_fcn_depth(void) const
Definition: parse.h:218
OCTINTERP_API tree_identifier * make_fcn_name(tree_identifier *id)
Definition: oct-parse.cc:7928
symbol_scope m_primary_fcn_scope
Definition: parse.h:768
OCTINTERP_API tree_cell * append_cell_row(tree_cell *cell, tree_argument_list *row)
Definition: oct-parse.cc:9353
OCTINTERP_API tree_matrix * make_matrix(tree_argument_list *row)
Definition: oct-parse.cc:9320
OCTINTERP_API void reset(void)
Definition: oct-parse.cc:6711
OCTINTERP_API tree_command * make_for_command(int tok_id, token *for_tok, tree_argument_list *lhs, tree_expression *expr, tree_expression *maxproc, tree_statement_list *body, token *end_tok, comment_list *lc)
Definition: oct-parse.cc:7454
OCTINTERP_API tree_expression * make_binary_op(int op, tree_expression *op1, token *tok_val, tree_expression *op2)
Definition: oct-parse.cc:7112
OCTINTERP_API void bison_error(const std::string &s, const filepos &pos)
OCTINTERP_API tree_decl_elt * make_decl_elt(tree_identifier *id, token *eq_op=nullptr, tree_expression *expr=nullptr)
Definition: oct-parse.cc:9086
OCTINTERP_API tree_command * make_do_until_command(token *until_tok, tree_statement_list *body, tree_expression *expr, comment_list *lc)
Definition: oct-parse.cc:7434
OCTINTERP_API tree_command * make_continue_command(token *continue_tok)
Definition: oct-parse.cc:7539
OCTINTERP_API void bison_error(const std::string &s)
OCTINTERP_API tree_if_clause * make_else_clause(token *else_tok, comment_list *lc, tree_statement_list *list)
Definition: oct-parse.cc:7664
void endfunction_found(bool flag)
Definition: parse.h:223
bool at_end_of_input(void) const
Definition: parse.h:177
OCTINTERP_API tree_command * make_while_command(token *while_tok, tree_expression *expr, tree_statement_list *body, token *end_tok, comment_list *lc)
Definition: oct-parse.cc:7399
OCTINTERP_API tree_command * make_try_command(token *try_tok, tree_statement_list *body, char catch_sep, tree_statement_list *cleanup, token *end_tok, comment_list *lc, comment_list *mc)
Definition: oct-parse.cc:7343
bool endfunction_found(void) const
Definition: parse.h:228
OCTINTERP_API tree_switch_case_list * append_switch_case(tree_switch_case_list *list, tree_switch_case *elt)
Definition: oct-parse.cc:7755
OCTINTERP_API tree_black_hole * make_black_hole(void)
Definition: oct-parse.cc:6945
OCTINTERP_API void maybe_warn_variable_switch_label(tree_expression *expr)
Definition: oct-parse.cc:9963
OCTINTERP_API tree_classdef_property_list * append_classdef_property(tree_classdef_property_list *list, tree_classdef_property *elt)
Definition: oct-parse.cc:8648
OCTINTERP_API tree_classdef_attribute * make_not_classdef_attribute(tree_identifier *id)
Definition: oct-parse.cc:8703
bool m_fcn_file_from_relative_lookup
Definition: parse.h:744
OCTINTERP_API tree_statement * make_end(const std::string &type, bool eof, const filepos &beg_pos, const filepos &end_pos)
Definition: oct-parse.cc:8120
std::string m_curr_class_name
Definition: parse.h:772
OCTINTERP_API tree_classdef_body * append_classdef_enum_block(tree_classdef_body *body, tree_classdef_enum_block *block)
Definition: oct-parse.cc:8761
OCTINTERP_API tree_args_block_attribute_list * make_args_attribute_list(tree_identifier *attribute_name)
Definition: oct-parse.cc:8284
OCTINTERP_API tree_function_def * make_function(token *fcn_tok, tree_parameter_list *ret_list, tree_identifier *id, tree_parameter_list *param_list, tree_statement_list *body, tree_statement *end_fcn_stmt, comment_list *lc)
Definition: oct-parse.cc:7962
OCTINTERP_API tree_statement_list * make_statement_list(tree_statement *stmt)
Definition: oct-parse.cc:9449
OCTINTERP_API octave_user_function * start_function(tree_identifier *id, tree_parameter_list *param_list, tree_statement_list *body, tree_statement *end_function)
Definition: oct-parse.cc:7986
std::string m_curr_package_name
Definition: parse.h:776
void parsing_local_functions(bool flag)
Definition: parse.h:208
std::list< std::string > m_subfunction_names
Definition: parse.h:787
OCTINTERP_API tree_classdef_enum_list * append_classdef_enum(tree_classdef_enum_list *list, tree_classdef_enum *elt)
Definition: oct-parse.cc:8662
OCTINTERP_API tree_classdef_methods_block * make_classdef_methods_block(token *tok_val, tree_classdef_attribute_list *a, tree_classdef_methods_list *mlist, token *end_tok, comment_list *lc, comment_list *tc)
Definition: oct-parse.cc:8506
OCTINTERP_API void bison_error(const std::string &s, int line, int column)
OCTINTERP_API tree_constant * make_constant(token *tok_val)
Definition: oct-parse.cc:6884
OCTINTERP_API void end_token_error(token *tok, token::end_tok_type expected)
Definition: oct-parse.cc:6833
base_lexer & m_lexer
Definition: parse.h:796
OCTINTERP_API bool finish_classdef_file(tree_classdef *cls, tree_statement_list *local_fcns)
Definition: oct-parse.cc:8865
OCTINTERP_API tree_metaclass_query * make_metaclass_query(token *metaquery)
Definition: oct-parse.cc:9391
OCTINTERP_API tree_classdef_events_block * make_classdef_events_block(token *tok_val, tree_classdef_attribute_list *a, tree_classdef_events_list *elist, token *end_tok, comment_list *lc, comment_list *tc)
Definition: oct-parse.cc:8547
OCTINTERP_API void maybe_warn_missing_semi(tree_statement_list *)
Definition: oct-parse.cc:9979
OCTINTERP_API tree_classdef_body * append_classdef_properties_block(tree_classdef_body *body, tree_classdef_properties_block *block)
Definition: oct-parse.cc:8740
OCTINTERP_API tree_switch_case * make_switch_case(token *case_tok, tree_expression *expr, tree_statement_list *list, comment_list *lc)
Definition: oct-parse.cc:7731
OCTINTERP_API tree_switch_case * make_default_switch_case(token *default_tok, comment_list *lc, tree_statement_list *list)
Definition: oct-parse.cc:7745
OCTINTERP_API tree_expression * finish_matrix(tree_matrix *m, token *open_delim, token *close_delim)
Definition: oct-parse.cc:9310
OCTINTERP_API tree_statement * make_statement(T *arg)
OCTINTERP_API tree_classdef_superclass * make_classdef_superclass(token *fqident)
Definition: oct-parse.cc:8675
OCTINTERP_API tree_anon_fcn_handle * make_anon_fcn_handle(tree_parameter_list *param_list, tree_expression *expr, const filepos &at_pos)
Definition: oct-parse.cc:6966
OCTINTERP_API tree_command * make_break_command(token *break_tok)
Definition: oct-parse.cc:7522
OCTINTERP_API tree_statement_list * append_statement_list(tree_statement_list *list, char sep, tree_statement *stmt, bool warn_missing_semi)
Definition: oct-parse.cc:9455
OCTINTERP_API bool push_fcn_symtab(void)
Definition: oct-parse.cc:6853
OCTINTERP_API tree_classdef_methods_list * make_classdef_methods_list(tree_function_def *fcn_def)
Definition: oct-parse.cc:8836
OCTINTERP_API tree_expression * make_prefix_op(int op, tree_expression *op1, token *tok_val)
Definition: oct-parse.cc:7234
OCTINTERP_API tree_statement_list * append_function_body(tree_statement_list *body, tree_statement_list *list)
Definition: oct-parse.cc:8225
OCTINTERP_API tree_classdef_enum * make_classdef_enum(tree_identifier *id, tree_expression *expr, comment_list *lc)
Definition: oct-parse.cc:8641
OCTINTERP_API bool validate_param_list(tree_parameter_list *lst, tree_parameter_list::in_or_out type)
Definition: oct-parse.cc:9093
OCTINTERP_API tree_spmd_command * make_spmd_command(token *spmd_tok, tree_statement_list *body, token *end_tok, comment_list *lc, comment_list *tc)
Definition: oct-parse.cc:7567
OCTINTERP_API tree_decl_init_list * make_decl_init_list(tree_decl_elt *elt)
Definition: oct-parse.cc:9073
OCTINTERP_API tree_classdef_enum_block * make_classdef_enum_block(token *tok_val, tree_classdef_attribute_list *a, tree_classdef_enum_list *elist, token *end_tok, comment_list *lc, comment_list *tc)
Definition: oct-parse.cc:8602
OCTINTERP_API octave_user_function * start_classdef_external_method(tree_identifier *id, tree_parameter_list *pl)
Definition: oct-parse.cc:8768
OCTINTERP_API tree_decl_init_list * append_decl_init_list(tree_decl_init_list *list, tree_decl_elt *elt)
Definition: oct-parse.cc:9079
OCTINTERP_API tree_classdef_body * append_classdef_events_block(tree_classdef_body *body, tree_classdef_events_block *block)
Definition: oct-parse.cc:8754
void classdef_object(const std::shared_ptr< tree_classdef > &obj)
Definition: parse.h:181
base_parser & operator=(const base_parser &)=delete
OCTINTERP_API tree_index_expression * make_index_expression(tree_expression *expr, tree_argument_list *args, char type)
Definition: oct-parse.cc:8932
OCTINTERP_API tree_args_block_validation_list * append_args_validation_list(tree_args_block_validation_list *list, tree_arg_validation *arg_validation)
Definition: oct-parse.cc:8299
bool m_parsing_subfunctions
Definition: parse.h:748
OCTINTERP_API tree_classdef_superclass_list * append_classdef_superclass(tree_classdef_superclass_list *list, tree_classdef_superclass *elt)
Definition: oct-parse.cc:8681
std::string m_parse_error_msg
Definition: parse.h:734
OCTINTERP_API tree_if_command_list * start_if_command(tree_expression *expr, tree_statement_list *list)
Definition: oct-parse.cc:7595
OCTINTERP_API tree_arg_size_spec * make_arg_size_spec(tree_argument_list *size_args)
Definition: oct-parse.cc:8306
OCTINTERP_API tree_expression * make_postfix_op(int op, tree_expression *op1, token *tok_val)
Definition: oct-parse.cc:7274
OCTINTERP_API tree_expression * finish_array_list(tree_array_list *a, token *open_delim, token *close_delim)
Definition: oct-parse.cc:9246
OCTINTERP_API tree_classdef_events_list * append_classdef_event(tree_classdef_events_list *list, tree_classdef_event *elt)
Definition: oct-parse.cc:8655
friend OCTINTERP_API octave_value parse_fcn_file(interpreter &interp, const std::string &full_file, const std::string &file, const std::string &dir_name, const std::string &dispatch_type, const std::string &package_name, bool require_file, bool force_script, bool autoload, bool relative_lookup)
Definition: oct-parse.cc:9790
OCTINTERP_API tree_if_clause * make_elseif_clause(token *elseif_tok, tree_expression *expr, tree_statement_list *list, comment_list *lc)
Definition: oct-parse.cc:7650
OCTINTERP_API tree_statement_list * set_stmt_print_flag(tree_statement_list *, char, bool)
Definition: oct-parse.cc:9402
OCTINTERP_API tree_expression * finish_cell(tree_cell *c, token *open_delim, token *close_delim)
Definition: oct-parse.cc:9337
OCTINTERP_API tree_arguments_block * make_arguments_block(token *arguments_tok, tree_args_block_attribute_list *attr_list, tree_args_block_validation_list *validation_list, token *end_tok, comment_list *lc, comment_list *tc)
Definition: oct-parse.cc:8241
bool m_endfunction_found
Definition: parse.h:737
OCTINTERP_API tree_classdef_methods_list * append_classdef_method(tree_classdef_methods_list *list, tree_function_def *fcn_def)
Definition: oct-parse.cc:8849
bool parsing_local_functions(void) const
Definition: parse.h:213
OCTINTERP_API tree_classdef_body * append_classdef_methods_block(tree_classdef_body *body, tree_classdef_methods_block *block)
Definition: oct-parse.cc:8747
OCTINTERP_API tree_expression * make_boolean_op(int op, tree_expression *op1, token *tok_val, tree_expression *op2)
Definition: oct-parse.cc:7205
bool m_autoloading
Definition: parse.h:740
OCTINTERP_API tree_expression * make_colon_expression(tree_expression *base, tree_expression *limit, tree_expression *incr=nullptr)
Definition: oct-parse.cc:7032
base_lexer & get_lexer(void) const
Definition: parse.h:175
virtual int run(void)=0
OCTINTERP_API tree_superclass_ref * make_superclass_ref(token *superclassref)
Definition: oct-parse.cc:9379
std::shared_ptr< tree_classdef > classdef_object(void) const
Definition: parse.h:186
OCTINTERP_API tree_classdef_enum_list * make_classdef_enum_list(tree_classdef_enum *e)
Definition: oct-parse.cc:8635
OCTINTERP_API void make_script(tree_statement_list *cmds, tree_statement *end_script)
Definition: oct-parse.cc:7897
OCTINTERP_API tree_argument_list * make_argument_list(tree_expression *expr)
Definition: oct-parse.cc:9465
OCTINTERP_API tree_args_block_validation_list * make_args_validation_list(tree_arg_validation *arg_validation)
Definition: oct-parse.cc:8293
OCTINTERP_API tree_classdef_property_list * make_classdef_property_list(tree_classdef_property *prop)
Definition: oct-parse.cc:8483
OCTINTERP_API tree_classdef_attribute * make_classdef_attribute(tree_identifier *id, tree_expression *expr=nullptr)
Definition: oct-parse.cc:8694
OCTINTERP_API tree_classdef_event * make_classdef_event(comment_list *lc, tree_identifier *id)
Definition: oct-parse.cc:8586
OCTINTERP_API tree_arg_validation_fcns * make_arg_validation_fcns(tree_argument_list *fcn_args)
Definition: oct-parse.cc:8314
std::shared_ptr< tree_statement_list > m_stmt_list
Definition: parse.h:793
OCTINTERP_API bool end_token_ok(token *tok, token::end_tok_type expected)
Definition: oct-parse.cc:6845
OCTINTERP_API void maybe_warn_assign_as_truth_value(tree_expression *expr)
Definition: oct-parse.cc:9943
void parsing_subfunctions(bool flag)
Definition: parse.h:198
OCTINTERP_API tree_function_def * finish_function(tree_parameter_list *ret_list, octave_user_function *fcn, comment_list *lc, int l, int c)
Definition: oct-parse.cc:8130
parser(FILE *file, interpreter &interp)
Definition: parse.h:831
parser & operator=(const parser &)=delete
parser(FILE *file, interpreter &interp, std::string encoding)
Definition: parse.h:835
~parser(void)=default
OCTINTERP_API int run(void)
Definition: oct-parse.cc:9633
parser(const parser &)=delete
parser(const std::string &eval_string, interpreter &interp)
Definition: parse.h:839
parser(interpreter &interp)
Definition: parse.h:827
parser(lexer *lxr)
Definition: parse.h:847
push_parser(const push_parser &)=delete
OCTINTERP_API int run(void)
Definition: oct-parse.cc:9750
~push_parser(void)=default
push_parser(interpreter &interp)
Definition: parse.h:866
push_parser(interpreter &interp, input_reader *reader)
Definition: parse.h:874
std::shared_ptr< input_reader > m_reader
Definition: parse.h:902
interpreter & m_interpreter
Definition: parse.h:900
push_parser & operator=(const push_parser &)=delete
QString name
OCTINTERP_API void cleanup_statement_list(tree_statement_list **lst)
OCTINTERP_API octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
OCTINTERP_API octave_value parse_fcn_file(interpreter &interp, const std::string &full_file, const std::string &file, const std::string &dir_name, const std::string &dispatch_type, const std::string &package_name, bool require_file, bool force_script, bool autoload, bool relative_lookup)
Definition: oct-parse.cc:9790
OCTINTERP_API octave_value load_fcn_from_file(const std::string &file_name, const std::string &dir_name="", const std::string &dispatch_type="", const std::string &package_name="", const std::string &fcn_name="", bool autoload=false)
OCTINTERP_API void source_file(const std::string &file_name, const std::string &context="", bool verbose=false, bool require_file=true)
OCTINTERP_API std::string get_help_from_file(const std::string &nm, bool &symbol_found, std::string &file)
static int input(yyscan_t yyscanner)
int octave_debug