File: grammar.texi

package info (click to toggle)
octave 4.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 94,200 kB
  • ctags: 52,925
  • sloc: cpp: 316,850; ansic: 43,469; fortran: 23,670; sh: 13,805; yacc: 8,204; objc: 7,939; lex: 3,631; java: 2,127; makefile: 1,746; perl: 1,022; awk: 988
file content (137 lines) | stat: -rw-r--r-- 5,364 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
@c DO NOT EDIT!  Generated automatically by munge-texi.pl.

@c Copyright (C) 1996-2015 John W. Eaton
@c
@c This file is part of Octave.
@c
@c Octave is free software; you can redistribute it and/or modify it
@c under the terms of the GNU General Public License as published by the
@c Free Software Foundation; either version 3 of the License, or (at
@c your option) any later version.
@c
@c Octave is distributed in the hope that it will be useful, but WITHOUT
@c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@c FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
@c for more details.
@c
@c You should have received a copy of the GNU General Public License
@c along with Octave; see the file COPYING.  If not, see
@c <http://www.gnu.org/licenses/>.

@node Grammar and Parser
@appendix Grammar and Parser
@cindex grammar rules
@cindex language definition

This appendix will eventually contain a semi-formal description of
Octave's language.

@menu
* Keywords::
* Parser::
@end menu

@node Keywords
@section Keywords
@cindex keywords

The following identifiers are keywords, and may not be used as variable
or function names:

@multitable @columnfractions .33 .33 .33
@item @code{__FILE__} @tab @code{__LINE__} @tab @code{break}
@item @code{case} @tab @code{catch} @tab @code{classdef}
@item @code{continue} @tab @code{do} @tab @code{else}
@item @code{elseif} @tab @code{end} @tab @code{end_try_catch}
@item @code{end_unwind_protect} @tab @code{endclassdef} @tab @code{endenumeration}
@item @code{endevents} @tab @code{endfor} @tab @code{endfunction}
@item @code{endif} @tab @code{endmethods} @tab @code{endparfor}
@item @code{endproperties} @tab @code{endswitch} @tab @code{endwhile}
@item @code{enumeration} @tab @code{events} @tab @code{for}
@item @code{function} @tab @code{global} @tab @code{if}
@item @code{methods} @tab @code{otherwise} @tab @code{parfor}
@item @code{persistent} @tab @code{properties} @tab @code{return}
@item @code{switch} @tab @code{try} @tab @code{until}
@item @code{unwind_protect} @tab @code{unwind_protect_cleanup} @tab @code{while}
@end multitable

The function @code{iskeyword} can be used to quickly check whether an
identifier is reserved by Octave.

@c iskeyword libinterp/parse-tree/lex.cc
@anchor{XREFiskeyword}
@deftypefn  {Built-in Function} {} iskeyword ()
@deftypefnx {Built-in Function} {} iskeyword (@var{name})
Return true if @var{name} is an Octave keyword.

If @var{name} is omitted, return a list of keywords.
@seealso{@ref{XREFisvarname,,isvarname}, @ref{XREFexist,,exist}}
@end deftypefn


@node Parser
@section Parser
@cindex parser

The parser has a number of variables that affect its internal operation.
These variables are generally documented in the manual alongside the code that
they affect.  For example, @code{allow_noninteger_range_as_index} is discussed
in the section on index expressions.

In addition, there are three non-specific parser customization functions.
@code{add_input_event_hook} can be used to schedule a user function for
periodic evaluation.  @code{remove_input_event_hook} will stop a user function
from being evaluated periodically.

@c add_input_event_hook libinterp/corefcn/input.cc
@anchor{XREFadd_input_event_hook}
@deftypefn  {Built-in Function} {@var{id} =} add_input_event_hook (@var{fcn})
@deftypefnx {Built-in Function} {@var{id} =} add_input_event_hook (@var{fcn}, @var{data})
Add the named function or function handle @var{fcn} to the list of functions
to call periodically when Octave is waiting for input.

The function should have the form

@example
@var{fcn} (@var{data})
@end example

If @var{data} is omitted, Octave calls the function without any arguments.

The returned identifier may be used to remove the function handle from the
list of input hook functions.
@seealso{@ref{XREFremove_input_event_hook,,remove_input_event_hook}}
@end deftypefn


@c remove_input_event_hook libinterp/corefcn/input.cc
@anchor{XREFremove_input_event_hook}
@deftypefn  {Built-in Function} {} remove_input_event_hook (@var{name})
@deftypefnx {Built-in Function} {} remove_input_event_hook (@var{fcn_id})
Remove the named function or function handle with the given identifier
from the list of functions to call periodically when Octave is waiting
for input.
@seealso{@ref{XREFadd_input_event_hook,,add_input_event_hook}}
@end deftypefn


Finally, when the parser cannot identify an input token it calls a particular
function to handle this.  By default, this is the internal function
@qcode{"__unimplemented__"} which makes suggestions about possible Octave
substitutes for @sc{matlab} functions.

@c missing_function_hook libinterp/corefcn/variables.cc
@anchor{XREFmissing_function_hook}
@deftypefn  {Built-in Function} {@var{val} =} missing_function_hook ()
@deftypefnx {Built-in Function} {@var{old_val} =} missing_function_hook (@var{new_val})
@deftypefnx {Built-in Function} {} missing_function_hook (@var{new_val}, "local")
Query or set the internal variable that specifies the function to call when
an unknown identifier is requested.

When called from inside a function with the @qcode{"local"} option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
@seealso{@ref{XREFmissing_component_hook,,missing_component_hook}}
@end deftypefn