@c DO NOT EDIT!  Generated automatically by munge-texi.pl.

@c Copyright (C) 1996-2026 The Octave Project Developers
@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
@c the Free Software Foundation, either version 3 of the License, or
@c (at your option) any later version.
@c
@c Octave is distributed in the hope that it will be useful, but
@c WITHOUT ANY WARRANTY; without even the implied warranty of
@c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@c GNU General Public License 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 <https://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 identifiers below are keywords, and may not be used as variable
or function names:

@subsubheading Categories:

@ref{XREFkwcategoryUtilityFunctions,,@w{Utility Functions}}@: |
@ref{XREFkwcategoryVariableDeclaration,,@w{Variable Declaration}}@: |
@ref{XREFkwcategoryFunctionDefinition,,@w{Function Definition}}@: |
@ref{XREFkwcategoryControlStructures,,@w{Control Statements}}@: |
@ref{XREFkwcategoryIteratingStructures,,@w{Iterating Structures}}@: |
@ref{XREFkwcategoryClassdefStructures,,@w{Classdef Structures}}@: |
@ref{XREFkwcategoryExecutionEnvironment,,@w{Execution Environment}}@:

@subsubheading Alphabetical keyword listing:

@ref{XREF__FILE__,,__FILE__}@: |
@ref{XREF__LINE__,,__LINE__}@: |
@ref{XREFbreak,,break}@: |
@ref{XREFcase,,case}@: |
@ref{XREFcatch,,catch}@: |
@ref{XREFclassdef,,classdef}@: |
@ref{XREFcontinue,,continue}@: |
@ref{XREFdo,,do}@: |
@ref{XREFelse,,else}@: |
@ref{XREFelseif,,elseif}@: |
@ref{XREFend,,end}@: |
@ref{XREFend_try_catch,,end_try_catch}@: |
@ref{XREFend_unwind_protect,,end_unwind_protect}@: |
@ref{XREFendclassdef,,endclassdef}@: |
@ref{XREFendenumeration,,endenumeration}@: |
@ref{XREFendevents,,endevents}@: |
@ref{XREFendfor,,endfor}@: |
@ref{XREFendfunction,,endfunction}@: |
@ref{XREFendif,,endif}@: |
@ref{XREFendmethods,,endmethods}@: |
@ref{XREFendparfor,,endparfor}@: |
@ref{XREFendproperties,,endproperties}@: |
@ref{XREFendswitch,,endswitch}@: |
@ref{XREFendwhile,,endwhile}@: |
@ref{XREFenumeration,,endenumeration}@: |
@ref{XREFevents,,events}@: |
@ref{XREFfor,,for}@: |
@ref{XREFfunction,,function}@: |
@ref{XREFglobal,,global}@: |
@ref{XREFif,,if}@: |
@ref{XREFkwpropertymethods,,methods}@: |
@ref{XREFotherwise,,otherwise}@: |
@ref{XREFparfor,,parfor}@: |
@ref{XREFpersistent,,persistent}@: |
@ref{XREFkwpropertyproperties,,properties}@: |
@ref{XREFreturn,,return}@: |
@ref{XREFswitch,,switch}@: |
@ref{XREFtry,,try}@: |
@ref{XREFuntil,,until}@: |
@ref{XREFunwind_protect,,unwind_protect}@: |
@ref{XREFunwind_protect_cleanup,,unwind_protect_cleanup}@: |
@ref{XREFwhile,,while}@:

@anchor{XREFkwcategoryUtilityFunctions}
@subheading Utility Functions:
The function @code{iskeyword} can be used to quickly check whether an
identifier is reserved by Octave.

@c iskeyword libinterp/parse-tree/lex.ll
@anchor{XREFiskeyword}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn  {} {} iskeyword ()
@deftypefnx {} {} iskeyword (@var{name})
Return true if @var{name} is an Octave keyword.

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


@anchor{XREFkwcategoryVariableDeclaration}
@subheading Variable Declaration:

@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFglobal}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} global @var{var}
Declare variables to have global scope.

@example
@group
global @var{x};
if (isempty (@var{x}))
  x = 1;
endif
@end group
@end example
@xseealso{@ref{XREFpersistent,,persistent}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFpersistent}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} persistent @var{var}
Declare variables as persistent.

A variable that has been declared persistent within a function will retain its
contents in memory between subsequent calls to the same function.  The
difference between persistent variables and global variables is that persistent
variables are local in scope to a particular function and are not visible
elsewhere.
@xseealso{@ref{XREFglobal,,global}}
@end deftypefn
@c ## FIXME: Can't have duplicate DOCSTRING entries.  The function properties()
@c ##        already has a docstring which overrides this keyword definition.
@c ##        If this is fixed, place \x1d char before keyword "properties".
@c ## properties
@c ## @c libinterp/parse-tree/oct-parse.yy
@c ## -*- texinfo -*-
@c ## @deftypefn {} {} properties
@c ## Begin a properties block in a classdef definition.
@c ## @end deftypefn


@anchor{XREFkwcategoryFunctionDefinition}
@subheading Function Definition:

@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFfunction}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn  {} {} function @var{outputs} = function_name (@var{input}, @dots{})
@deftypefnx {} {} function {} function_name (@var{input}, @dots{})
@deftypefnx {} {} function @var{outputs} = function_name
Begin a function body with name @code{function_name}, with @var{outputs} as
results, and with @var{inputs} as parameters.

The function can later be invoked in Octave using the syntax

@example
[@var{output1}, @var{output2}, @dots{}] = function_name (@var{input1}, @var{input2}, @dots{})
@end example

@xseealso{@ref{XREFreturn,,return}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFendfunction}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} endfunction
Mark the end of a function.
@xseealso{@ref{XREFfunction,,function}}
@end deftypefn


@c end libinterp/parse-tree/pt-eval.cc
@anchor{XREFend}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} end
Last element of an array or the end of any @code{for}, @code{parfor},
@code{if}, @code{do}, @code{while}, @code{function}, @code{switch},
@code{try}, or @code{unwind_protect} block.

As an index of an array, the magic index @qcode{"end"} refers to the
last valid entry in an indexing operation.

Example:

@example
@group
@var{x} = [ 1 2 3; 4 5 6 ];
@var{x}(1,end)
 @xresult{} 3
@var{x}(end,1)
 @xresult{} 4
@var{x}(end,end)
 @xresult{} 6
@end group
@end example

Programming notes:
@enumerate
@item
The @code{end} keyword cannot be used within @code{subsref},
@code{subsasgn}, or @code{substruct} for manual indexing operations.

@item
For custom classes, to enable use of @code{end} in indexing expressions it
must be overloaded with a function definition such as:

@example
@group
function last_index = end (obj, end_dim, ndim_obj)
  if (end_dim == ndim_obj)
    last_index = prod (size (obj)(end_dim:ndim_obj));
  else
    last_index = size (obj, end_dim);
  endif
endfunction
@end group
@end example

For more information, @pxref{Object Oriented Programming}.
@end enumerate

@xseealso{@ref{XREFfor,,for}, @ref{XREFparfor,,parfor}, @ref{XREFif,,if}, @ref{XREFdo,,do}, @ref{XREFwhile,,while}, @ref{XREFfunction,,function}, @ref{XREFswitch,,switch}, @ref{XREFtry,,try}, @ref{XREFunwind_protect,,unwind_protect}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFreturn}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} return
Return execution control immediately from a function or script to the calling
code.

@code{return} is used to stop executing code and exit an m-file immediately
rather than continuing until the end of the function or script is reached.

If the function or script was invoked directly, rather than from calling code
in an m-file, then Octave returns to the command line.
@xseealso{@ref{XREFfunction,,function}}
@end deftypefn


@anchor{XREFkwcategoryControlStructures}
@subheading Control Statements:

@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFif}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn  {} {} if (@var{cond}) @dots{} endif
@deftypefnx {} {} if (@var{cond}) @dots{} else @dots{} endif
@deftypefnx {} {} if (@var{cond}) @dots{} elseif (@var{cond}) @dots{} endif
@deftypefnx {} {} if (@var{cond}) @dots{} elseif (@var{cond}) @dots{} else @dots{} endif
Begin an if block.

The conditional @var{cond} is true if it is not empty and if @emph{all} values
are nonzero.

@example
@group
x = 1;
if (x == 1)
  disp ("one");
elseif (x == 2)
  disp ("two");
else
  disp ("not one or two");
endif
@end group
@end example
@xseealso{@ref{XREFswitch,,switch}}
@end deftypefn
@c ## FIXME: Can't have duplicate DOCSTRING entries.  The function methods()
@c ##        already has a docstring which overrides this keyword definition.
@c ##        If this is fixed, place \x1d char before keyword "methods".
@c ## methods
@c ## @c libinterp/parse-tree/oct-parse.yy
@c ## -*- texinfo -*-
@c ## @deftypefn {} {} methods
@c ## Begin a methods block in a classdef definition.
@c ## @end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFelse}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} else
Alternate action for an if block.

See @code{if} for an example.
@xseealso{@ref{XREFif,,if}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFelseif}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} elseif (@var{cond})
Alternate conditional test for an if block.

The conditional @var{cond} is true if it is not empty and if @emph{all} values
are nonzero.

See @code{if} for an example.
@xseealso{@ref{XREFif,,if}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFendif}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} endif
Mark the end of an if block.

See @code{if} for an example.
@xseealso{@ref{XREFif,,if}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFswitch}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} switch @var{statement}
Begin a switch block.

@example
@group
yesno = "yes";

switch (yesno)
  case @{"Yes" "yes" "YES" "y" "Y"@}
    value = 1;
  case @{"No" "no" "NO" "n" "N"@}
    value = 0;
  otherwise
    error ("invalid value");
endswitch
@end group
@end example
@xseealso{@ref{XREFif,,if}, @ref{XREFcase,,case}, @ref{XREFotherwise,,otherwise}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFcase}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn  {} {} case @var{value}
@deftypefnx {} {} case @{@var{value}, @dots{}@}
A case statement in a switch block.

Octave cases are exclusive and do not fall-through as do C-language cases.  A
switch statement must have at least one case.  See @code{switch} for an
example.
@xseealso{@ref{XREFswitch,,switch}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFotherwise}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} otherwise
The default statement in a switch block which is executed when no other
case statements match the input.
@xseealso{@ref{XREFswitch,,switch}, @ref{XREFcase,,case}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFendswitch}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} endswitch
Mark the end of a switch block.

See @code{switch} for an example.
@xseealso{@ref{XREFswitch,,switch}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFtry}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} try
Begin a try-catch block.

If an error occurs within a try block, then the catch code will be run and
execution will proceed after the catch block (though it is often recommended to
use the @code{lasterr} function to re-throw the error after cleanup is
completed).
@xseealso{@ref{XREFcatch,,catch}, @ref{XREFunwind_protect,,unwind_protect}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFcatch}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn  {} {} catch
@deftypefnx {} {} catch @var{value}
Begin the cleanup part of a try-catch block.
@xseealso{@ref{XREFtry,,try}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFend_try_catch}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} end_try_catch
Mark the end of a @code{try-catch} block.
@xseealso{@ref{XREFtry,,try}, @ref{XREFcatch,,catch}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFunwind_protect}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} unwind_protect
Begin an unwind_protect block.

If an error occurs within the first part of an unwind_protect block the
commands within the unwind_protect_cleanup block are executed before the error
is thrown.  If an error is not thrown, then the unwind_protect_cleanup block is
still executed.  In other words, the unwind_protect_cleanup code is guaranteed
to execute regardless of success or failure in the unwind_protect block.
@xseealso{@ref{XREFunwind_protect_cleanup,,unwind_protect_cleanup}, @ref{XREFtry,,try}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFunwind_protect_cleanup}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} unwind_protect_cleanup
Begin the cleanup section of an unwind_protect block.
@xseealso{@ref{XREFunwind_protect,,unwind_protect}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFend_unwind_protect}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} end_unwind_protect
Mark the end of an unwind_protect block.
@xseealso{@ref{XREFunwind_protect,,unwind_protect}}
@end deftypefn


@anchor{XREFkwcategoryIteratingStructures}
@subheading Iterating Structures:

@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFfor}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} for @var{i} = @var{range}
Begin a for loop.

@example
@group
for i = 1:10
  i
endfor
@end group
@end example
@xseealso{@ref{XREFparfor,,parfor}, @ref{XREFdo,,do}, @ref{XREFwhile,,while}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFendfor}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} endfor
Mark the end of a for loop.

See @code{for} for an example.
@xseealso{@ref{XREFfor,,for}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFwhile}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} while (@var{cond})
Begin a while loop.

The conditional @var{cond} is true if it is not empty and if @emph{all} values
are nonzero.

@example
@group
i = 0;
while (i < 10)
  i++
endwhile
@end group
@end example
@xseealso{@ref{XREFdo,,do}, @ref{XREFendwhile,,endwhile}, @ref{XREFfor,,for}, @ref{XREFuntil,,until}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFendwhile}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} endwhile
Mark the end of a while loop.

See @code{while} for an example.
@xseealso{@ref{XREFdo,,do}, @ref{XREFwhile,,while}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFdo}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} do
Begin a do-until loop.

This differs from a while loop in that the body of the loop is executed at
least once.

@example
@group
i = 0;
do
  i++
until (i == 10)
@end group
@end example
@xseealso{@ref{XREFfor,,for}, @ref{XREFuntil,,until}, @ref{XREFwhile,,while}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFuntil}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} until (@var{cond})
End a do-until loop.

The conditional @var{cond} is true if it is not empty and if @emph{all} values
are nonzero.

See @code{do} for an example.
@xseealso{@ref{XREFdo,,do}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFparfor}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn  {} {} parfor @var{i} = @var{range}
@deftypefnx {} {} parfor (@var{i} = @var{range}, @var{maxproc})
Begin a for loop that may execute in parallel.

A @code{parfor} loop has the same syntax as a @code{for} loop.  If your Octave
session has a parallel processing pool enabled, the iterations of the
@code{parfor} loop will be executed in parallel across the pool's workers.
Otherwise, @code{parfor} will behave exactly as @code{for}.

When operating in parallel mode, a @code{parfor} loop's iterations are not
guaranteed to occur sequentially, and there are additional restrictions about
the data access operations you can do inside the loop body.

@strong{Warning:} parallel processing pools are currently unimplemented in
Octave; @code{parfor} currently behaves exactly as a normal @code{for} loop.

@example
@group
parfor i = 1:10
  i
endparfor
@end group
@end example
@xseealso{@ref{XREFfor,,for}, @ref{XREFdo,,do}, @ref{XREFwhile,,while}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFendparfor}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} endparfor
Mark the end of a parfor loop.

See @code{parfor} for an example.
@xseealso{@ref{XREFparfor,,parfor}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFbreak}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} break
Exit the innermost enclosing do, while, or for loop.
@xseealso{@ref{XREFdo,,do}, @ref{XREFwhile,,while}, @ref{XREFfor,,for}, @ref{XREFparfor,,parfor}, @ref{XREFcontinue,,continue}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFcontinue}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} continue
Jump to the end of the innermost enclosing do, while, or for loop.
@xseealso{@ref{XREFbreak,,break}, @ref{XREFdo,,do}, @ref{XREFwhile,,while}, @ref{XREFfor,,for}, @ref{XREFparfor,,parfor}}
@end deftypefn


@anchor{XREFkwcategoryClassdefStructures}
@subheading Classdef Structures:

@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFclassdef}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} classdef
Begin a classdef block.
@xseealso{@ref{XREFproperties,,properties}, @ref{XREFmethods,,methods}, @ref{XREFevents,,events}, @ref{XREFenumeration,,enumeration}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFendclassdef}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} endclassdef
Mark the end of a classdef definition.
@xseealso{@ref{XREFclassdef,,classdef}}
@end deftypefn


@c properties definition must be manually created to avoid
@c collision with function of the same name.
@anchor{XREFkwpropertyproperties}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html

@deftypefn {} {} properties
Mark the beginning of a block of properties in a classdef definition.  Note
that the @ref{XREFproperties,,function @qcode{"properties"}} is a function
that lists the properties of a classdef class or object.
@xseealso{@ref{XREFendproperties,,endproperties}}
@end deftypefn

@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFendproperties}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} endproperties
Mark the end of a properties block in a classdef definition.
@xseealso{@ref{XREFproperties,,properties}}
@end deftypefn


@c methods definition must be manually created to avoid
@c collision with function of the same name.
@anchor{XREFkwpropertymethods}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html

@deftypefn {} {} methods
Mark the beginning of a block of methods in a classdef definition.  Note that
the @ref{XREFmethods,,function @qcode{"methods"}} is a function that lists
the methods of a class or object.
@xseealso{@ref{XREFendmethods,,endmethods}}
@end deftypefn

@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFendmethods}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} endmethods
Mark the end of a methods block in a classdef definition.
@xseealso{@ref{XREFmethods,,methods}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFevents}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} events
Begin an events block in a classdef definition.
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFendevents}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} endevents
Mark the end of an events block in a classdef definition.
@xseealso{@ref{XREFevents,,events}}
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFenumeration}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} enumeration
Begin an enumeration block in a classdef definition.
@end deftypefn


@c libinterp/parse-tree/oct-parse.yy
@anchor{XREFendenumeration}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} endenumeration
Mark the end of an enumeration block in a classdef definition.
@xseealso{@ref{XREFenumeration,,enumeration}}
@end deftypefn


@anchor{XREFkwcategoryExecutionEnvironment}
@subheading Execution Environment:

@c libinterp/parse-tree/lex.ll
@anchor{XREF__FILE__}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} __FILE__
When the lexer recognizes the @qcode{"__FILE__"} keyword it returns a character
array containing the full name and path of the file that is being executed.
@qcode{"__FILE__"} will return @qcode{"stdin"} if called from the command line.
@xseealso{@ref{XREF__LINE__,,__LINE__}}
@end deftypefn


@c libinterp/parse-tree/lex.ll
@anchor{XREF__LINE__}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn {} {} __LINE__
When the lexer recognizes the @qcode{"__LINE__"} keyword it returns a numeric
value containing the current input line number of the function or file being
executed.  @qcode{"__LINE__"} will return @code{1} if called from the command
line.
@xseealso{@ref{XREF__FILE__,,__FILE__}}
@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.

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}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn  {} {@var{id} =} add_input_event_hook (@var{fcn})
@deftypefnx {} {@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.
@xseealso{@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}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn  {} {} remove_input_event_hook (@var{name})
@deftypefnx {} {} 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.
@xseealso{@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}
@html
<span style="display:block; margin-top:-4.5ex;">&nbsp;</span>
@end html


@deftypefn  {} {@var{val} =} missing_function_hook ()
@deftypefnx {} {@var{old_val} =} missing_function_hook (@var{new_val})
@deftypefnx {} {@var{old_val} =} missing_function_hook (@var{new_val}, "local")
Query or set the internal variable that specifies the function to call
to provide extra information when an unknown identifier is referenced.

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.
@xseealso{@ref{XREFmissing_component_hook,,missing_component_hook}}
@end deftypefn

