| 12
 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
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 
 | @c DO NOT EDIT!  Generated automatically by munge-texi.pl.
@c Copyright (C) 1996-2024 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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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)
 @result{} 3
@var{x}(end,1)
 @result{} 4
@var{x}(end,end)
 @result{} 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 see
@ref{Object Oriented Programming, , 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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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;"> </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 @code{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;"> </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;"> </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;"> </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;"> </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
 |