annotate libinterp/parse-tree/lex.h @ 17787:175b392e91fe

Use GNU style coding conventions for code in libinterp/ * libinterp/corefcn/Cell.h, libinterp/corefcn/__contourc__.cc, libinterp/corefcn/__dispatch__.cc, libinterp/corefcn/__lin_interpn__.cc, libinterp/corefcn/__pchip_deriv__.cc, libinterp/corefcn/__qp__.cc, libinterp/corefcn/balance.cc, libinterp/corefcn/besselj.cc, libinterp/corefcn/betainc.cc, libinterp/corefcn/bitfcns.cc, libinterp/corefcn/bsxfun.cc, libinterp/corefcn/c-file-ptr-stream.cc, libinterp/corefcn/c-file-ptr-stream.h, libinterp/corefcn/cellfun.cc, libinterp/corefcn/colloc.cc, libinterp/corefcn/comment-list.h, libinterp/corefcn/conv2.cc, libinterp/corefcn/daspk.cc, libinterp/corefcn/dasrt.cc, libinterp/corefcn/dassl.cc, libinterp/corefcn/data.cc, libinterp/corefcn/debug.cc, libinterp/corefcn/defaults.cc, libinterp/corefcn/defaults.in.h, libinterp/corefcn/defun-int.h, libinterp/corefcn/defun.cc, libinterp/corefcn/det.cc, libinterp/corefcn/dirfns.cc, libinterp/corefcn/display.cc, libinterp/corefcn/dlmread.cc, libinterp/corefcn/dot.cc, libinterp/corefcn/dynamic-ld.cc, libinterp/corefcn/dynamic-ld.h, libinterp/corefcn/eig.cc, libinterp/corefcn/ellipj.cc, libinterp/corefcn/error.cc, libinterp/corefcn/error.h, libinterp/corefcn/event-queue.h, libinterp/corefcn/fft.cc, libinterp/corefcn/fft2.cc, libinterp/corefcn/fftn.cc, libinterp/corefcn/file-io.cc, libinterp/corefcn/filter.cc, libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc, libinterp/corefcn/gcd.cc, libinterp/corefcn/getgrent.cc, libinterp/corefcn/getpwent.cc, libinterp/corefcn/getrusage.cc, libinterp/corefcn/givens.cc, libinterp/corefcn/gl-render.cc, libinterp/corefcn/gl2ps-renderer.cc, libinterp/corefcn/gl2ps-renderer.h, libinterp/corefcn/graphics.cc, libinterp/corefcn/graphics.in.h, libinterp/corefcn/gripes.cc, libinterp/corefcn/gripes.h, libinterp/corefcn/help.cc, libinterp/corefcn/hess.cc, libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc, libinterp/corefcn/input.h, libinterp/corefcn/inv.cc, libinterp/corefcn/jit-ir.h, libinterp/corefcn/jit-typeinfo.cc, libinterp/corefcn/jit-typeinfo.h, libinterp/corefcn/jit-util.h, libinterp/corefcn/kron.cc, libinterp/corefcn/load-path.cc, libinterp/corefcn/load-path.h, libinterp/corefcn/load-save.cc, libinterp/corefcn/load-save.h, libinterp/corefcn/lookup.cc, libinterp/corefcn/ls-ascii-helper.cc, libinterp/corefcn/ls-hdf5.cc, libinterp/corefcn/ls-hdf5.h, libinterp/corefcn/ls-mat-ascii.cc, libinterp/corefcn/ls-mat-ascii.h, libinterp/corefcn/ls-mat4.cc, libinterp/corefcn/ls-mat5.cc, libinterp/corefcn/ls-mat5.h, libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lsode.cc, libinterp/corefcn/lu.cc, libinterp/corefcn/luinc.cc, libinterp/corefcn/mappers.cc, libinterp/corefcn/matrix_type.cc, libinterp/corefcn/max.cc, libinterp/corefcn/md5sum.cc, libinterp/corefcn/mex.cc, libinterp/corefcn/mexproto.h, libinterp/corefcn/mgorth.cc, libinterp/corefcn/mxarray.in.h, libinterp/corefcn/nproc.cc, libinterp/corefcn/oct-hist.cc, libinterp/corefcn/oct-lvalue.h, libinterp/corefcn/oct-map.cc, libinterp/corefcn/oct-map.h, libinterp/corefcn/oct-obj.h, libinterp/corefcn/oct-prcstrm.h, libinterp/corefcn/oct-stdstrm.h, libinterp/corefcn/oct-stream.cc, libinterp/corefcn/oct-stream.h, libinterp/corefcn/octave-link.cc, libinterp/corefcn/octave-link.h, libinterp/corefcn/pager.cc, libinterp/corefcn/pinv.cc, libinterp/corefcn/pr-output.cc, libinterp/corefcn/procstream.h, libinterp/corefcn/profiler.cc, libinterp/corefcn/pt-jit.cc, libinterp/corefcn/pt-jit.h, libinterp/corefcn/quad.cc, libinterp/corefcn/quadcc.cc, libinterp/corefcn/qz.cc, libinterp/corefcn/rand.cc, libinterp/corefcn/rcond.cc, libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc, libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sighandlers.h, libinterp/corefcn/sparse-xdiv.cc, libinterp/corefcn/sparse-xdiv.h, libinterp/corefcn/sparse-xpow.cc, libinterp/corefcn/sparse.cc, libinterp/corefcn/spparms.cc, libinterp/corefcn/sqrtm.cc, libinterp/corefcn/str2double.cc, libinterp/corefcn/strfind.cc, libinterp/corefcn/strfns.cc, libinterp/corefcn/sub2ind.cc, libinterp/corefcn/svd.cc, libinterp/corefcn/syl.cc, libinterp/corefcn/symtab.cc, libinterp/corefcn/symtab.h, libinterp/corefcn/syscalls.cc, libinterp/corefcn/sysdep.cc, libinterp/corefcn/sysdep.h, libinterp/corefcn/time.cc, libinterp/corefcn/toplev.cc, libinterp/corefcn/toplev.h, libinterp/corefcn/tril.cc, libinterp/corefcn/txt-eng-ft.cc, libinterp/corefcn/txt-eng-ft.h, libinterp/corefcn/txt-eng.h, libinterp/corefcn/typecast.cc, libinterp/corefcn/urlwrite.cc, libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc, libinterp/corefcn/variables.h, libinterp/corefcn/xdiv.cc, libinterp/corefcn/xdiv.h, libinterp/corefcn/xnorm.h, libinterp/corefcn/xpow.cc, libinterp/corefcn/xpow.h, libinterp/corefcn/zfstream.cc, libinterp/corefcn/zfstream.h, libinterp/dldfcn/__delaunayn__.cc, libinterp/dldfcn/__dsearchn__.cc, libinterp/dldfcn/__eigs__.cc, libinterp/dldfcn/__fltk_uigetfile__.cc, libinterp/dldfcn/__glpk__.cc, libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/__init_gnuplot__.cc, libinterp/dldfcn/__magick_read__.cc, libinterp/dldfcn/__voronoi__.cc, libinterp/dldfcn/amd.cc, libinterp/dldfcn/ccolamd.cc, libinterp/dldfcn/chol.cc, libinterp/dldfcn/colamd.cc, libinterp/dldfcn/convhulln.cc, libinterp/dldfcn/dmperm.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc, libinterp/dldfcn/symbfact.cc, libinterp/dldfcn/symrcm.cc, libinterp/dldfcn/tsearch.cc, libinterp/octave-value/ov-base-diag.cc, libinterp/octave-value/ov-base-diag.h, libinterp/octave-value/ov-base-int.cc, libinterp/octave-value/ov-base-int.h, libinterp/octave-value/ov-base-mat.h, libinterp/octave-value/ov-base-scalar.cc, libinterp/octave-value/ov-base-scalar.h, libinterp/octave-value/ov-base-sparse.cc, libinterp/octave-value/ov-base-sparse.h, libinterp/octave-value/ov-base.cc, libinterp/octave-value/ov-base.h, libinterp/octave-value/ov-bool-mat.cc, libinterp/octave-value/ov-bool-mat.h, libinterp/octave-value/ov-bool-sparse.cc, libinterp/octave-value/ov-bool-sparse.h, libinterp/octave-value/ov-bool.cc, libinterp/octave-value/ov-bool.h, libinterp/octave-value/ov-builtin.cc, libinterp/octave-value/ov-builtin.h, libinterp/octave-value/ov-cell.cc, libinterp/octave-value/ov-cell.h, libinterp/octave-value/ov-ch-mat.cc, libinterp/octave-value/ov-ch-mat.h, libinterp/octave-value/ov-class.cc, libinterp/octave-value/ov-class.h, libinterp/octave-value/ov-colon.h, libinterp/octave-value/ov-complex.cc, libinterp/octave-value/ov-complex.h, libinterp/octave-value/ov-cx-diag.cc, libinterp/octave-value/ov-cx-diag.h, libinterp/octave-value/ov-cx-mat.cc, libinterp/octave-value/ov-cx-mat.h, libinterp/octave-value/ov-cx-sparse.cc, libinterp/octave-value/ov-cx-sparse.h, libinterp/octave-value/ov-dld-fcn.h, libinterp/octave-value/ov-fcn-handle.cc, libinterp/octave-value/ov-fcn-handle.h, libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-fcn-inline.h, libinterp/octave-value/ov-fcn.h, libinterp/octave-value/ov-float.cc, libinterp/octave-value/ov-float.h, libinterp/octave-value/ov-flt-complex.cc, libinterp/octave-value/ov-flt-complex.h, libinterp/octave-value/ov-flt-cx-diag.cc, libinterp/octave-value/ov-flt-cx-diag.h, libinterp/octave-value/ov-flt-cx-mat.cc, libinterp/octave-value/ov-flt-cx-mat.h, libinterp/octave-value/ov-flt-re-diag.cc, libinterp/octave-value/ov-flt-re-diag.h, libinterp/octave-value/ov-flt-re-mat.cc, libinterp/octave-value/ov-flt-re-mat.h, libinterp/octave-value/ov-int16.cc, libinterp/octave-value/ov-int32.cc, libinterp/octave-value/ov-int64.cc, libinterp/octave-value/ov-int8.cc, libinterp/octave-value/ov-intx.h, libinterp/octave-value/ov-java.cc, libinterp/octave-value/ov-lazy-idx.h, libinterp/octave-value/ov-mex-fcn.cc, libinterp/octave-value/ov-mex-fcn.h, libinterp/octave-value/ov-null-mat.cc, libinterp/octave-value/ov-null-mat.h, libinterp/octave-value/ov-oncleanup.cc, libinterp/octave-value/ov-perm.cc, libinterp/octave-value/ov-perm.h, libinterp/octave-value/ov-range.cc, libinterp/octave-value/ov-range.h, libinterp/octave-value/ov-re-diag.cc, libinterp/octave-value/ov-re-diag.h, libinterp/octave-value/ov-re-mat.cc, libinterp/octave-value/ov-re-mat.h, libinterp/octave-value/ov-re-sparse.cc, libinterp/octave-value/ov-re-sparse.h, libinterp/octave-value/ov-scalar.cc, libinterp/octave-value/ov-scalar.h, libinterp/octave-value/ov-str-mat.cc, libinterp/octave-value/ov-str-mat.h, libinterp/octave-value/ov-struct.cc, libinterp/octave-value/ov-struct.h, libinterp/octave-value/ov-type-conv.h, libinterp/octave-value/ov-typeinfo.cc, libinterp/octave-value/ov-typeinfo.h, libinterp/octave-value/ov-uint16.cc, libinterp/octave-value/ov-uint32.cc, libinterp/octave-value/ov-uint64.cc, libinterp/octave-value/ov-uint8.cc, libinterp/octave-value/ov-usr-fcn.cc, libinterp/octave-value/ov-usr-fcn.h, libinterp/octave-value/ov.cc, libinterp/octave-value/ov.h, libinterp/octave.cc, libinterp/operators/op-b-bm.cc, libinterp/operators/op-b-sbm.cc, libinterp/operators/op-bm-b.cc, libinterp/operators/op-bm-bm.cc, libinterp/operators/op-cdm-cdm.cc, libinterp/operators/op-chm.cc, libinterp/operators/op-class.cc, libinterp/operators/op-cm-cm.cc, libinterp/operators/op-cm-cs.cc, libinterp/operators/op-cm-s.cc, libinterp/operators/op-cm-scm.cc, libinterp/operators/op-cm-sm.cc, libinterp/operators/op-cs-cm.cc, libinterp/operators/op-cs-cs.cc, libinterp/operators/op-cs-scm.cc, libinterp/operators/op-cs-sm.cc, libinterp/operators/op-dm-dm.cc, libinterp/operators/op-dm-scm.cc, libinterp/operators/op-double-conv.cc, libinterp/operators/op-fcdm-fcdm.cc, libinterp/operators/op-fcm-fcm.cc, libinterp/operators/op-fcm-fcs.cc, libinterp/operators/op-fcm-fm.cc, libinterp/operators/op-fcm-fs.cc, libinterp/operators/op-fcs-fcm.cc, libinterp/operators/op-fcs-fcs.cc, libinterp/operators/op-fcs-fm.cc, libinterp/operators/op-fcs-fs.cc, libinterp/operators/op-fdm-fdm.cc, libinterp/operators/op-float-conv.cc, libinterp/operators/op-fm-fcm.cc, libinterp/operators/op-fm-fcs.cc, libinterp/operators/op-fm-fm.cc, libinterp/operators/op-fm-fs.cc, libinterp/operators/op-fs-fcm.cc, libinterp/operators/op-fs-fcs.cc, libinterp/operators/op-fs-fm.cc, libinterp/operators/op-fs-fs.cc, libinterp/operators/op-m-cm.cc, libinterp/operators/op-m-cs.cc, libinterp/operators/op-m-m.cc, libinterp/operators/op-m-s.cc, libinterp/operators/op-m-scm.cc, libinterp/operators/op-m-sm.cc, libinterp/operators/op-pm-scm.cc, libinterp/operators/op-range.cc, libinterp/operators/op-s-cm.cc, libinterp/operators/op-s-cs.cc, libinterp/operators/op-s-scm.cc, libinterp/operators/op-sbm-b.cc, libinterp/operators/op-sbm-bm.cc, libinterp/operators/op-sbm-sbm.cc, libinterp/operators/op-scm-cm.cc, libinterp/operators/op-scm-cs.cc, libinterp/operators/op-scm-m.cc, libinterp/operators/op-scm-s.cc, libinterp/operators/op-scm-scm.cc, libinterp/operators/op-scm-sm.cc, libinterp/operators/op-sm-cm.cc, libinterp/operators/op-sm-m.cc, libinterp/operators/op-sm-s.cc, libinterp/operators/op-sm-scm.cc, libinterp/operators/op-sm-sm.cc, libinterp/operators/op-str-m.cc, libinterp/operators/op-str-s.cc, libinterp/operators/op-str-str.cc, libinterp/operators/ops.h, libinterp/parse-tree/lex.h, libinterp/parse-tree/parse.h, libinterp/parse-tree/pt-arg-list.cc, libinterp/parse-tree/pt-arg-list.h, libinterp/parse-tree/pt-assign.cc, libinterp/parse-tree/pt-assign.h, libinterp/parse-tree/pt-binop.cc, libinterp/parse-tree/pt-binop.h, libinterp/parse-tree/pt-bp.h, libinterp/parse-tree/pt-cbinop.cc, libinterp/parse-tree/pt-check.cc, libinterp/parse-tree/pt-colon.cc, libinterp/parse-tree/pt-colon.h, libinterp/parse-tree/pt-const.cc, libinterp/parse-tree/pt-decl.cc, libinterp/parse-tree/pt-decl.h, libinterp/parse-tree/pt-eval.cc, libinterp/parse-tree/pt-except.h, libinterp/parse-tree/pt-exp.h, libinterp/parse-tree/pt-fcn-handle.cc, libinterp/parse-tree/pt-id.cc, libinterp/parse-tree/pt-id.h, libinterp/parse-tree/pt-idx.cc, libinterp/parse-tree/pt-idx.h, libinterp/parse-tree/pt-loop.h, libinterp/parse-tree/pt-mat.cc, libinterp/parse-tree/pt-misc.cc, libinterp/parse-tree/pt-misc.h, libinterp/parse-tree/pt-pr-code.cc, libinterp/parse-tree/pt-select.h, libinterp/parse-tree/pt-stmt.h, libinterp/parse-tree/token.h, libinterp/version.cc: Use GNU style coding conventions for code in libinterp/
author Rik <rik@octave.org>
date Mon, 28 Oct 2013 19:51:46 -0700
parents d63878346099
children 6b51f5f44aea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17733
diff changeset
3 Copyright (C) 1993-2013 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
10 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
11
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
19 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22
383
0b52c68ec81f [project @ 1994-03-09 21:19:44 by jwe]
jwe
parents: 247
diff changeset
23 #if !defined (octave_lex_h)
0b52c68ec81f [project @ 1994-03-09 21:19:44 by jwe]
jwe
parents: 247
diff changeset
24 #define octave_lex_h 1
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25
16230
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
26 #include <deque>
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
27 #include <limits>
8745
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
28 #include <list>
16101
8d19626b38ae provide copy contructor and operator = for lexical_feedback class.
John W. Eaton <jwe@octave.org>
parents: 16100
diff changeset
29 #include <set>
11464
21b5284fa78d avoid error when parsing nested functions
John W. Eaton <jwe@octave.org>
parents: 11367
diff changeset
30 #include <stack>
8745
6dc61981d18b better handling of object indexing in lexer
John W. Eaton <jwe@octave.org>
parents: 8701
diff changeset
31
16228
e19b1632d7c1 revamp most comment handling
John W. Eaton <jwe@octave.org>
parents: 16224
diff changeset
32 #include "comment-list.h"
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16194
diff changeset
33 #include "input.h"
16230
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
34 #include "token.h"
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16194
diff changeset
35
4867
c7f9ea142fda [project @ 2004-04-20 19:41:11 by jwe]
jwe
parents: 4753
diff changeset
36 // Is the given string a keyword?
c7f9ea142fda [project @ 2004-04-20 19:41:11 by jwe]
jwe
parents: 4753
diff changeset
37 extern bool is_keyword (const std::string& s);
c7f9ea142fda [project @ 2004-04-20 19:41:11 by jwe]
jwe
parents: 4753
diff changeset
38
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
39 // For communication between the lexer and parser.
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
40
3585
d9803711e047 [project @ 2000-02-08 04:35:39 by jwe]
jwe
parents: 3351
diff changeset
41 class
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
42 lexical_feedback
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
43 {
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
44 public:
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
45
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
46 // Track symbol table information when parsing functions.
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
47
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
48 class symbol_table_context
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
49 {
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
50 public:
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
51
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
52 symbol_table_context (void)
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
53 : frame_stack (), init_scope (symbol_table::current_scope ())
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
54 {
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
55 push (init_scope);
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
56 }
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
57
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
58 void clear (void)
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
59 {
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
60 while (! frame_stack.empty ())
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
61 frame_stack.pop ();
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
62
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
63 push (init_scope);
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
64 }
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
65
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
66 bool empty (void) const { return frame_stack.empty (); }
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
67
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
68 void pop (void)
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
69 {
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
70 frame_stack.pop ();
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
71 }
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
72
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
73 void push (symbol_table::scope_id scope)
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
74 {
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
75 frame_stack.push (scope);
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
76 }
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
77
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
78 void push (void)
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
79 {
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
80 push (symbol_table::current_scope ());
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
81 }
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
82
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
83 symbol_table::scope_id curr_scope (void) const
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
84 {
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
85 return frame_stack.top ();
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
86 }
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
87
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
88 private:
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
89
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
90 std::stack<symbol_table::scope_id> frame_stack;
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
91
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
92 symbol_table::scope_id init_scope;
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
93 };
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
94
16104
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
95 // Track nesting of square brackets, curly braces, and parentheses.
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
96
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
97 class bbp_nesting_level
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
98 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
99 private:
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
100
16107
3b791008b88e give name to anonymous enum
John W. Eaton <jwe@octave.org>
parents: 16106
diff changeset
101 enum bracket_type
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
102 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
103 BRACKET = 1,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
104 BRACE = 2,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
105 PAREN = 3,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
106 ANON_FCN_BODY = 4
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
107 };
16104
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
108
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
109 public:
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
110
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
111 bbp_nesting_level (void) : context () { }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
112
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
113 bbp_nesting_level (const bbp_nesting_level& nl) : context (nl.context) { }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
114
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
115 bbp_nesting_level& operator = (const bbp_nesting_level& nl)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
116 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
117 if (&nl != this)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
118 context = nl.context;
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
119
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
120 return *this;
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
121 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
122
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
123 ~bbp_nesting_level (void) { }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
124
16194
b7ca669af528 reset lexical_feedback state before starting a new parse
John W. Eaton <jwe@octave.org>
parents: 16193
diff changeset
125 void reset (void)
b7ca669af528 reset lexical_feedback state before starting a new parse
John W. Eaton <jwe@octave.org>
parents: 16193
diff changeset
126 {
b7ca669af528 reset lexical_feedback state before starting a new parse
John W. Eaton <jwe@octave.org>
parents: 16193
diff changeset
127 while (! context.empty ())
b7ca669af528 reset lexical_feedback state before starting a new parse
John W. Eaton <jwe@octave.org>
parents: 16193
diff changeset
128 context.pop ();
b7ca669af528 reset lexical_feedback state before starting a new parse
John W. Eaton <jwe@octave.org>
parents: 16193
diff changeset
129 }
b7ca669af528 reset lexical_feedback state before starting a new parse
John W. Eaton <jwe@octave.org>
parents: 16193
diff changeset
130
16104
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
131 void bracket (void) { context.push (BRACKET); }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
132
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
133 bool is_bracket (void)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
134 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
135 return ! context.empty () && context.top () == BRACKET;
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
136 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
137
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
138 void brace (void) { context.push (BRACE); }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
139
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
140 bool is_brace (void)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
141 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
142 return ! context.empty () && context.top () == BRACE;
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
143 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
144
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
145 void paren (void) { context.push (PAREN); }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
146
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
147 bool is_paren (void)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
148 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
149 return ! context.empty () && context.top () == PAREN;
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
150 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
151
16265
71ee3afedb69 5/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16263
diff changeset
152 void anon_fcn_body (void) { context.push (ANON_FCN_BODY); }
71ee3afedb69 5/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16263
diff changeset
153
71ee3afedb69 5/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16263
diff changeset
154 bool is_anon_fcn_body (void)
71ee3afedb69 5/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16263
diff changeset
155 {
71ee3afedb69 5/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16263
diff changeset
156 return ! context.empty () && context.top () == ANON_FCN_BODY;
71ee3afedb69 5/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16263
diff changeset
157 }
71ee3afedb69 5/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16263
diff changeset
158
16104
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
159 bool is_bracket_or_brace (void)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
160 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
161 return (! context.empty ()
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
162 && (context.top () == BRACKET || context.top () == BRACE));
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
163 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
164
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
165 bool none (void) { return context.empty (); }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
166
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
167 void remove (void)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
168 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
169 if (! context.empty ())
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
170 context.pop ();
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
171 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
172
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
173 void clear (void)
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
174 {
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
175 while (! context.empty ())
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
176 context.pop ();
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
177 }
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
178
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
179 private:
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
180
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
181 std::stack<int> context;
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
182 };
16230
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
183
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
184 class token_cache
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
185 {
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
186 public:
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
187
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
188 // Store an "unlimited" number of tokens.
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
189 token_cache (size_t sz_arg = std::numeric_limits<size_t>::max ())
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
190 : buffer (), sz (sz_arg)
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
191 { }
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
192
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
193 void push (token *tok)
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
194 {
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
195 if (buffer.size () == sz)
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
196 pop ();
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
197
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
198 buffer.push_front (tok);
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
199 }
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
200
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
201 void pop (void)
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
202 {
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
203 if (! empty ())
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
204 {
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
205 delete buffer.back ();
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
206 buffer.pop_back ();
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
207 }
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
208 }
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
209
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
210 // Direct access.
16255
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
211 token *at (size_t n)
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
212 {
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
213 return empty () ? 0 : buffer.at (n);
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
214 }
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
215
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
216 const token *at (size_t n) const
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
217 {
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
218 return empty () ? 0 : buffer.at (n);
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
219 }
16230
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
220
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
221 // Most recently pushed.
16255
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
222 token *front (void)
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
223 {
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
224 return empty () ? 0 : buffer.front ();
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
225 }
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
226
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
227 const token *front (void) const
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
228 {
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
229 return empty () ? 0 : buffer.front ();
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
230 }
16230
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
231
16255
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
232 token *back (void)
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
233 {
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
234 return empty () ? 0 : buffer.back ();
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
235 }
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
236
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
237 const token *back (void) const
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
238 {
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
239 return empty () ? 0 : buffer.back ();
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
240 }
16230
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
241
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
242 // Number of elements currently in the buffer, max of sz.
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
243 size_t size (void) const { return buffer.size (); }
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
244
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
245 bool empty (void) const { return buffer.empty (); }
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
246
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
247 void clear (void)
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
248 {
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
249 while (! empty ())
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
250 pop ();
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
251 }
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
252
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
253 private:
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
254
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
255 std::deque<token *> buffer;
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
256
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
257 size_t sz;
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
258
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
259 // No copying!
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
260
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
261 token_cache (const token_cache&);
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
262
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
263 token_cache& operator = (const token_cache&);
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
264 };
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
265
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
266 lexical_feedback (void)
16259
0b5ab09dfce4 2/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16257
diff changeset
267 : end_of_input (false), at_beginning_of_statement (true),
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
268 looking_at_anon_fcn_args (false), looking_at_return_list (false),
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
269 looking_at_parameter_list (false), looking_at_decl_list (false),
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
270 looking_at_initializer_expression (false),
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
271 looking_at_matrix_or_assign_lhs (false),
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
272 looking_for_object_index (false),
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
273 looking_at_indirect_ref (false), parsing_class_method (false),
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
274 maybe_classdef_get_set_method (false), parsing_classdef (false),
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
275 quote_is_transpose (false), force_script (false),
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
276 reading_fcn_file (false), reading_script_file (false),
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
277 reading_classdef_file (false),
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
278 input_line_number (1), current_input_column (1),
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
279 bracketflag (0), braceflag (0),
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
280 looping (0), defining_func (0), looking_at_function_handle (0),
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
281 block_comment_nesting_level (0), token_count (0),
16228
e19b1632d7c1 revamp most comment handling
John W. Eaton <jwe@octave.org>
parents: 16224
diff changeset
282 current_input_line (), comment_text (), help_text (),
16898
531473481084 rewrite string parsing to avoid unlimited lookahead
John W. Eaton <jwe@octave.org>
parents: 16360
diff changeset
283 string_text (), string_line (0), string_column (0),
16228
e19b1632d7c1 revamp most comment handling
John W. Eaton <jwe@octave.org>
parents: 16224
diff changeset
284 fcn_file_name (), fcn_file_full_name (), looking_at_object_index (),
16207
0467d68ca891 move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16203
diff changeset
285 parsed_function_name (), pending_local_variables (),
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
286 symtab_context (), nesting_level (), tokens ()
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
287 {
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
288 init ();
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
289 }
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
290
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
291 ~lexical_feedback (void);
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
292
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
293 void init (void);
16194
b7ca669af528 reset lexical_feedback state before starting a new parse
John W. Eaton <jwe@octave.org>
parents: 16193
diff changeset
294
b7ca669af528 reset lexical_feedback state before starting a new parse
John W. Eaton <jwe@octave.org>
parents: 16193
diff changeset
295 void reset (void);
b7ca669af528 reset lexical_feedback state before starting a new parse
John W. Eaton <jwe@octave.org>
parents: 16193
diff changeset
296
16255
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
297 int previous_token_value (void) const;
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
298
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
299 bool previous_token_value_is (int tok_val) const;
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
300
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
301 void mark_previous_token_trailing_space (void);
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
302
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
303 bool space_follows_previous_token (void) const;
12bf6a3f8c45 store more info in token value class
John W. Eaton <jwe@octave.org>
parents: 16253
diff changeset
304
16257
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16255
diff changeset
305 bool previous_token_is_binop (void) const;
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16255
diff changeset
306
16267
15f55df088e7 6/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
307 bool previous_token_is_keyword (void) const;
15f55df088e7 6/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16265
diff changeset
308
16257
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16255
diff changeset
309 bool previous_token_may_be_command (void) const;
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16255
diff changeset
310
16360
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16337
diff changeset
311 void maybe_mark_previous_token_as_variable (void);
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16337
diff changeset
312
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16337
diff changeset
313 void mark_as_variable (const std::string& nm);
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16337
diff changeset
314 void mark_as_variables (const std::list<std::string>& lst);
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16337
diff changeset
315
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
316 // true means that we have encountered eof on the input stream.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
317 bool end_of_input;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
318
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
319 // true means we are at the beginning of a statement, where a
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
320 // command name is possible.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
321 bool at_beginning_of_statement;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
322
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
323 // true means we are parsing an anonymous function argument list.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
324 bool looking_at_anon_fcn_args;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
325
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
326 // true means we're parsing the return list for a function.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
327 bool looking_at_return_list;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
328
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
329 // true means we're parsing the parameter list for a function.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
330 bool looking_at_parameter_list;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
331
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
332 // true means we're parsing a declaration list (global or
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
333 // persistent).
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
334 bool looking_at_decl_list;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
335
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
336 // true means we are looking at the initializer expression for a
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
337 // parameter list element.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
338 bool looking_at_initializer_expression;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
339
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
340 // true means we're parsing a matrix or the left hand side of
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
341 // multi-value assignment statement.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
342 bool looking_at_matrix_or_assign_lhs;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
343
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
344 // object index not possible until we've seen something.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
345 bool looking_for_object_index;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
346
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
347 // true means we're looking at an indirect reference to a
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
348 // structure element.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
349 bool looking_at_indirect_ref;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
350
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
351 // true means we are parsing a class method in function or classdef file.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
352 bool parsing_class_method;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
353
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
354 // true means we are parsing a class method declaration line in a
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
355 // classdef file and can accept a property get or set method name.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
356 // for example, "get.propertyname" is recognized as a function name.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
357 bool maybe_classdef_get_set_method;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
358
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
359 // true means we are parsing a classdef file
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
360 bool parsing_classdef;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
361
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
362 // return transpose or start a string?
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
363 bool quote_is_transpose;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
364
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
365 // TRUE means treat the current file as a script even if the first
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
366 // token is "function" or "classdef".
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
367 bool force_script;
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
368
16199
810a71122c25 move more global variables to octave_lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
369 // TRUE means we're parsing a function file.
810a71122c25 move more global variables to octave_lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
370 bool reading_fcn_file;
810a71122c25 move more global variables to octave_lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
371
810a71122c25 move more global variables to octave_lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
372 // TRUE means we're parsing a script file.
810a71122c25 move more global variables to octave_lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
373 bool reading_script_file;
810a71122c25 move more global variables to octave_lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
374
810a71122c25 move more global variables to octave_lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
375 // TRUE means we're parsing a classdef file.
810a71122c25 move more global variables to octave_lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
376 bool reading_classdef_file;
810a71122c25 move more global variables to octave_lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16195
diff changeset
377
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
378 // the current input line number.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
379 int input_line_number;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
380
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
381 // the column of the current token.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
382 int current_input_column;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
383
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
384 // square bracket level count.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
385 int bracketflag;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
386
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
387 // curly brace level count.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
388 int braceflag;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
389
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
390 // true means we're in the middle of defining a loop.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
391 int looping;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
392
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
393 // nonzero means we're in the middle of defining a function.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
394 int defining_func;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
395
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
396 // nonzero means we are parsing a function handle.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
397 int looking_at_function_handle;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
398
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
399 // nestng level for blcok comments.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
400 int block_comment_nesting_level;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
401
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
402 // Count of tokens recognized by this lexer since initialized or
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
403 // since the last reset.
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
404 size_t token_count;
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
405
16207
0467d68ca891 move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16203
diff changeset
406 // The current line of input.
0467d68ca891 move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16203
diff changeset
407 std::string current_input_line;
0467d68ca891 move current_input_line to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16203
diff changeset
408
16228
e19b1632d7c1 revamp most comment handling
John W. Eaton <jwe@octave.org>
parents: 16224
diff changeset
409 // The current comment text.
e19b1632d7c1 revamp most comment handling
John W. Eaton <jwe@octave.org>
parents: 16224
diff changeset
410 std::string comment_text;
e19b1632d7c1 revamp most comment handling
John W. Eaton <jwe@octave.org>
parents: 16224
diff changeset
411
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
412 // The current help text.
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
413 std::string help_text;
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
414
16898
531473481084 rewrite string parsing to avoid unlimited lookahead
John W. Eaton <jwe@octave.org>
parents: 16360
diff changeset
415 // The current character string text.
531473481084 rewrite string parsing to avoid unlimited lookahead
John W. Eaton <jwe@octave.org>
parents: 16360
diff changeset
416 std::string string_text;
531473481084 rewrite string parsing to avoid unlimited lookahead
John W. Eaton <jwe@octave.org>
parents: 16360
diff changeset
417
531473481084 rewrite string parsing to avoid unlimited lookahead
John W. Eaton <jwe@octave.org>
parents: 16360
diff changeset
418 // The position of the beginning of the current character string.
531473481084 rewrite string parsing to avoid unlimited lookahead
John W. Eaton <jwe@octave.org>
parents: 16360
diff changeset
419 int string_line;
531473481084 rewrite string parsing to avoid unlimited lookahead
John W. Eaton <jwe@octave.org>
parents: 16360
diff changeset
420 int string_column;
531473481084 rewrite string parsing to avoid unlimited lookahead
John W. Eaton <jwe@octave.org>
parents: 16360
diff changeset
421
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
422 // Simple name of function file we are reading.
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
423 std::string fcn_file_name;
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
424
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
425 // Full name of file we are reading.
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
426 std::string fcn_file_full_name;
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
427
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
428 // if the front of the list is true, the closest paren, brace, or
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
429 // bracket nesting is an index for an object.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
430 std::list<bool> looking_at_object_index;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
431
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
432 // if the top of the stack is true, then we've already seen the name
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
433 // of the current function. should only matter if
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
434 // current_function_level > 0
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
435 std::stack<bool> parsed_function_name;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
436
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
437 // set of identifiers that might be local variable names.
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
438 std::set<std::string> pending_local_variables;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
439
16320
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
440 // Track current symbol table scope and context.
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
441 symbol_table_context symtab_context;
09f0cb9cac7d don't modify symbol table scope in the parser
John W. Eaton <jwe@octave.org>
parents: 16294
diff changeset
442
16265
71ee3afedb69 5/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16263
diff changeset
443 // is the closest nesting level a square bracket, squiggly brace,
71ee3afedb69 5/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16263
diff changeset
444 // a paren, or an anonymous function body?
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
445 bbp_nesting_level nesting_level;
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
446
16230
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
447 // Tokens generated by the lexer.
4bf907906134 use a queue to hold tokens in the lexer
John W. Eaton <jwe@octave.org>
parents: 16229
diff changeset
448 token_cache tokens;
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
449
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
450 private:
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
451
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
452 // No copying!
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
453
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
454 lexical_feedback (const lexical_feedback&);
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
455
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
456 lexical_feedback& operator = (const lexical_feedback&);
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
457 };
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
458
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
459 // octave_base_lexer inherits from lexical_feedback because we will
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
460 // eventually have several different constructors and it is easier to
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
461 // intialize if everything is grouped in a parent class rather than
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
462 // listing all the members in the octave_base_lexer class.
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
463
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
464 class
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
465 octave_base_lexer : public lexical_feedback
16193
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
466 {
d7392bf42fd1 use inheritance to simplify initialization in octave_lexer constructor
John W. Eaton <jwe@octave.org>
parents: 16185
diff changeset
467 public:
16104
c8974e28da59 move nesting_level to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16103
diff changeset
468
16183
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
469 // Handle buffering of input for lexer.
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
470
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
471 class input_buffer
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
472 {
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
473 public:
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
474
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
475 input_buffer (void)
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
476 : buffer (), pos (0), chars_left (0), eof (false)
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
477 { }
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
478
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16194
diff changeset
479 void fill (const std::string& input, bool eof_arg);
16183
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
480
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
481 // Copy at most max_size characters to buf.
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
482 int copy_chunk (char *buf, size_t max_size);
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
483
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
484 bool empty (void) const { return chars_left == 0; }
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
485
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
486 bool at_eof (void) const { return eof; }
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
487
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
488 private:
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
489
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
490 std::string buffer;
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
491 const char *pos;
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
492 size_t chars_left;
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
493 bool eof;
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
494 };
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
495
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
496 // Collect comment text.
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
497
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
498 class
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
499 comment_buffer
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
500 {
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
501 public:
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
502
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
503 comment_buffer (void) : comment_list (0) { }
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
504
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
505 ~comment_buffer (void) { delete comment_list; }
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
506
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
507 void append (const std::string& s, octave_comment_elt::comment_type t)
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
508 {
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
509 if (! comment_list)
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
510 comment_list = new octave_comment_list ();
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
511
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
512 comment_list->append (s, t);
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
513 }
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
514
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
515 // Caller is expected to delete the returned value.
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
516
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
517 octave_comment_list *get_comment (void)
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
518 {
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
519 octave_comment_list *retval = comment_list;
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
520
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
521 comment_list = 0;
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
522
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
523 return retval;
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
524 }
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
525
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
526 void reset (void)
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
527 {
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
528 delete comment_list;
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
529
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
530 comment_list = 0;
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
531 }
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
532
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
533 private:
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
534
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
535 octave_comment_list *comment_list;
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
536 };
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
537
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
538 octave_base_lexer (void)
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
539 : lexical_feedback (), scanner (0), input_buf (), comment_buf ()
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16194
diff changeset
540 {
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16194
diff changeset
541 init ();
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16194
diff changeset
542 }
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16194
diff changeset
543
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
544 virtual ~octave_base_lexer (void);
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
545
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16139
diff changeset
546 void init (void);
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
547
16294
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
548 virtual bool is_push_lexer (void) const { return false; }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
549
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
550 virtual void reset (void);
16122
6884401b2fbb move reset_parser lexer helper function to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16120
diff changeset
551
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
552 void prep_for_file (void);
16124
3be725cd195b move more lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16122
diff changeset
553
16898
531473481084 rewrite string parsing to avoid unlimited lookahead
John W. Eaton <jwe@octave.org>
parents: 16360
diff changeset
554 void begin_string (int state);
531473481084 rewrite string parsing to avoid unlimited lookahead
John W. Eaton <jwe@octave.org>
parents: 16360
diff changeset
555
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
556 virtual int fill_flex_buffer (char *buf, unsigned int max_size) = 0;
16120
4b68eb9b98b0 move octave_read lexer helper function to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16118
diff changeset
557
16294
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
558 bool at_end_of_buffer (void) const { return input_buf.empty (); }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
559
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
560 bool at_end_of_file (void) const { return input_buf.at_eof (); }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
561
16164
c5bfdc4c0963 move end_of_input flag from octve_parser class to octave_lexer class
John W. Eaton <jwe@octave.org>
parents: 16158
diff changeset
562 int handle_end_of_input (void);
c5bfdc4c0963 move end_of_input flag from octve_parser class to octave_lexer class
John W. Eaton <jwe@octave.org>
parents: 16158
diff changeset
563
16128
210039e91ad6 localize use of yytext with lexical_feedback member function
John W. Eaton <jwe@octave.org>
parents: 16126
diff changeset
564 char *flex_yytext (void);
210039e91ad6 localize use of yytext with lexical_feedback member function
John W. Eaton <jwe@octave.org>
parents: 16126
diff changeset
565
16130
421dea028bbf localize use of yyleng with lexical_feedback member function
John W. Eaton <jwe@octave.org>
parents: 16129
diff changeset
566 int flex_yyleng (void);
421dea028bbf localize use of yyleng with lexical_feedback member function
John W. Eaton <jwe@octave.org>
parents: 16129
diff changeset
567
16113
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
568 int text_yyinput (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
569
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
570 void xunput (char c, char *buf);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
571
16125
96a58f197f93 allow xunput to be called without buffer argument
John W. Eaton <jwe@octave.org>
parents: 16124
diff changeset
572 void xunput (char c);
96a58f197f93 allow xunput to be called without buffer argument
John W. Eaton <jwe@octave.org>
parents: 16124
diff changeset
573
16275
dd7de0345124 10/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16267
diff changeset
574 bool looking_at_space (void);
dd7de0345124 10/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16267
diff changeset
575
16113
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
576 bool inside_any_object_index (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
577
16360
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16337
diff changeset
578 bool is_variable (const std::string& name);
11115c237231 recognize variables when parsing (bug #38576)
John W. Eaton <jwe@octave.org>
parents: 16337
diff changeset
579
16113
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
580 int is_keyword_token (const std::string& s);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
581
16257
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16255
diff changeset
582 bool whitespace_is_significant (void);
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16255
diff changeset
583
16113
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
584 void handle_number (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
585
16253
a89cf57ba3a5 partial cleanup of continuation handling in lexer
John W. Eaton <jwe@octave.org>
parents: 16231
diff changeset
586 void handle_continuation (void);
a89cf57ba3a5 partial cleanup of continuation handling in lexer
John W. Eaton <jwe@octave.org>
parents: 16231
diff changeset
587
16337
6bfd8dbd7d3c don't swallow statements that follow comment lines (bug #38549)
John W. Eaton <jwe@octave.org>
parents: 16320
diff changeset
588 void finish_comment (octave_comment_elt::comment_type typ);
16253
a89cf57ba3a5 partial cleanup of continuation handling in lexer
John W. Eaton <jwe@octave.org>
parents: 16231
diff changeset
589
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
590 octave_comment_list *get_comment (void) { return comment_buf.get_comment (); }
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
591
16259
0b5ab09dfce4 2/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16257
diff changeset
592 int handle_close_bracket (int bracket_type);
16113
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
593
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
594 bool looks_like_command_arg (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
595
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
596 int handle_superclass_identifier (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
597
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
598 int handle_meta_identifier (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
599
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
600 int handle_identifier (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
601
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
602 void maybe_warn_separator_insert (char sep);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
603
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
604 void gripe_single_quote_string (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
605
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
606 void gripe_matlab_incompatible (const std::string& msg);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
607
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
608 void maybe_gripe_matlab_incompatible_comment (char c);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
609
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
610 void gripe_matlab_incompatible_continuation (void);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
611
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
612 void gripe_matlab_incompatible_operator (const std::string& op);
7c5e5e97a3bc move static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16111
diff changeset
613
16126
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
614 void push_token (token *);
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
615
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
616 token *current_token (void);
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
617
16118
f8e463523229 move more static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16115
diff changeset
618 void display_token (int tok);
f8e463523229 move more static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16115
diff changeset
619
16129
053b0364b507 localize use of yy_fatal_error with lexical_feedback member function
John W. Eaton <jwe@octave.org>
parents: 16128
diff changeset
620 void fatal_error (const char *msg);
053b0364b507 localize use of yy_fatal_error with lexical_feedback member function
John W. Eaton <jwe@octave.org>
parents: 16128
diff changeset
621
16229
7b7b1e4968e8 use functions instead of token return macros in lexer
John W. Eaton <jwe@octave.org>
parents: 16228
diff changeset
622 void lexer_debug (const char *pattern);
16118
f8e463523229 move more static lexer helper functions to lexical_feedback class
John W. Eaton <jwe@octave.org>
parents: 16115
diff changeset
623
16149
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16139
diff changeset
624 // Internal state of the flex-generated lexer.
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16139
diff changeset
625 void *scanner;
49dfba4fd3c5 use pure parser and reentrant lexer interfaces
John W. Eaton <jwe@octave.org>
parents: 16139
diff changeset
626
16183
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
627 // Object that reads and buffers input.
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
628 input_buffer input_buf;
359d56094efa handle lexer input buffering with class
John W. Eaton <jwe@octave.org>
parents: 16164
diff changeset
629
17693
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
630 // Object that collects comment text.
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
631 comment_buffer comment_buf;
efbe746f8fa8 eliminate octave_comment_buffer singleton
John W. Eaton <jwe@octave.org>
parents: 16898
diff changeset
632
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
633 virtual void increment_promptflag (void) = 0;
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16194
diff changeset
634
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
635 virtual void decrement_promptflag (void) = 0;
16209
e7ff32e7cf82 move global promptflag variable to octave_reader class
John W. Eaton <jwe@octave.org>
parents: 16207
diff changeset
636
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
637 virtual int promptflag (void) const = 0;
16209
e7ff32e7cf82 move global promptflag variable to octave_reader class
John W. Eaton <jwe@octave.org>
parents: 16207
diff changeset
638
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
639 virtual int promptflag (int) = 0;
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16194
diff changeset
640
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
641 virtual std::string input_source (void) const { return "unknown"; }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
642
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
643 virtual bool input_from_terminal (void) const { return false; }
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
644
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
645 virtual bool input_from_file (void) const { return false; }
16203
127cccb037bf move more global parser and lexer variables to classes
John W. Eaton <jwe@octave.org>
parents: 16199
diff changeset
646
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
647 virtual bool input_from_eval_string (void) const { return false; }
16195
b52d2f9294b6 use class for reading lexer input
John W. Eaton <jwe@octave.org>
parents: 16194
diff changeset
648
16224
4a848eb52de2 use stack for tracking lexer start states
John W. Eaton <jwe@octave.org>
parents: 16209
diff changeset
649 void push_start_state (int state);
4a848eb52de2 use stack for tracking lexer start states
John W. Eaton <jwe@octave.org>
parents: 16209
diff changeset
650
4a848eb52de2 use stack for tracking lexer start states
John W. Eaton <jwe@octave.org>
parents: 16209
diff changeset
651 void pop_start_state (void);
4a848eb52de2 use stack for tracking lexer start states
John W. Eaton <jwe@octave.org>
parents: 16209
diff changeset
652
4a848eb52de2 use stack for tracking lexer start states
John W. Eaton <jwe@octave.org>
parents: 16209
diff changeset
653 void clear_start_state (void);
4a848eb52de2 use stack for tracking lexer start states
John W. Eaton <jwe@octave.org>
parents: 16209
diff changeset
654
4a848eb52de2 use stack for tracking lexer start states
John W. Eaton <jwe@octave.org>
parents: 16209
diff changeset
655 int start_state (void) const { return start_state_stack.top (); }
4a848eb52de2 use stack for tracking lexer start states
John W. Eaton <jwe@octave.org>
parents: 16209
diff changeset
656
4a848eb52de2 use stack for tracking lexer start states
John W. Eaton <jwe@octave.org>
parents: 16209
diff changeset
657 void display_start_state (void) const;
4a848eb52de2 use stack for tracking lexer start states
John W. Eaton <jwe@octave.org>
parents: 16209
diff changeset
658
16275
dd7de0345124 10/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16267
diff changeset
659 int handle_op (const char *pattern, int tok, bool bos = false);
16229
7b7b1e4968e8 use functions instead of token return macros in lexer
John W. Eaton <jwe@octave.org>
parents: 16228
diff changeset
660
16275
dd7de0345124 10/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16267
diff changeset
661 int handle_incompatible_op (const char *pattern, int tok, bool bos = false);
16229
7b7b1e4968e8 use functions instead of token return macros in lexer
John W. Eaton <jwe@octave.org>
parents: 16228
diff changeset
662
16263
9acb86e6ac90 4/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16259
diff changeset
663 bool maybe_unput_comma_before_unary_op (int tok);
9acb86e6ac90 4/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16259
diff changeset
664
16275
dd7de0345124 10/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16267
diff changeset
665 int handle_unary_op (int tok, bool bos = false);
16263
9acb86e6ac90 4/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16259
diff changeset
666
16275
dd7de0345124 10/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16267
diff changeset
667 int handle_incompatible_unary_op (int tok, bool bos = false);
16263
9acb86e6ac90 4/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16259
diff changeset
668
16257
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16255
diff changeset
669 int handle_assign_op (const char *pattern, int tok);
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16255
diff changeset
670
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16255
diff changeset
671 int handle_incompatible_assign_op (const char *pattern, int tok);
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16255
diff changeset
672
16275
dd7de0345124 10/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16267
diff changeset
673 int handle_op_internal (int tok, bool bos, bool compat);
16229
7b7b1e4968e8 use functions instead of token return macros in lexer
John W. Eaton <jwe@octave.org>
parents: 16228
diff changeset
674
16231
2b15ae55c721 put all tokens in the token cache
John W. Eaton <jwe@octave.org>
parents: 16230
diff changeset
675 int handle_token (const std::string& name, int tok);
16229
7b7b1e4968e8 use functions instead of token return macros in lexer
John W. Eaton <jwe@octave.org>
parents: 16228
diff changeset
676
16231
2b15ae55c721 put all tokens in the token cache
John W. Eaton <jwe@octave.org>
parents: 16230
diff changeset
677 int handle_token (int tok, token *tok_val = 0);
16229
7b7b1e4968e8 use functions instead of token return macros in lexer
John W. Eaton <jwe@octave.org>
parents: 16228
diff changeset
678
7b7b1e4968e8 use functions instead of token return macros in lexer
John W. Eaton <jwe@octave.org>
parents: 16228
diff changeset
679 int count_token (int tok);
7b7b1e4968e8 use functions instead of token return macros in lexer
John W. Eaton <jwe@octave.org>
parents: 16228
diff changeset
680
16257
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16255
diff changeset
681 int count_token_internal (int tok);
db7f07b22b9b 1/10 commits reworking the lexer
John W. Eaton <jwe@octave.org>
parents: 16255
diff changeset
682
16229
7b7b1e4968e8 use functions instead of token return macros in lexer
John W. Eaton <jwe@octave.org>
parents: 16228
diff changeset
683 int show_token (int tok);
7b7b1e4968e8 use functions instead of token return macros in lexer
John W. Eaton <jwe@octave.org>
parents: 16228
diff changeset
684
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
685 protected:
16126
5c885c13bfa3 localize use of yylval.tok_val in lexical_feedback member functions
John W. Eaton <jwe@octave.org>
parents: 16125
diff changeset
686
16224
4a848eb52de2 use stack for tracking lexer start states
John W. Eaton <jwe@octave.org>
parents: 16209
diff changeset
687 std::stack<int> start_state_stack;
4a848eb52de2 use stack for tracking lexer start states
John W. Eaton <jwe@octave.org>
parents: 16209
diff changeset
688
16110
7302f8a4df83 use pointer for global lexical_feedback structure
John W. Eaton <jwe@octave.org>
parents: 16107
diff changeset
689 // No copying!
7302f8a4df83 use pointer for global lexical_feedback structure
John W. Eaton <jwe@octave.org>
parents: 16107
diff changeset
690
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
691 octave_base_lexer (const octave_base_lexer&);
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
692
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
693 octave_base_lexer& operator = (const octave_base_lexer&);
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
694 };
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
695
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
696 class
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
697 octave_lexer : public octave_base_lexer
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
698 {
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
699 public:
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
700
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
701 octave_lexer (void)
17731
f79bf671a493 eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents: 17693
diff changeset
702 : octave_base_lexer (), input_reader (this)
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
703 { }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
704
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
705 octave_lexer (FILE *file)
17731
f79bf671a493 eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents: 17693
diff changeset
706 : octave_base_lexer (), input_reader (file, this)
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
707 { }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
708
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
709 octave_lexer (const std::string& eval_string)
17731
f79bf671a493 eliminate global LEXER variable
John W. Eaton <jwe@octave.org>
parents: 17693
diff changeset
710 : octave_base_lexer (), input_reader (eval_string, this)
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
711 { }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
712
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
713 void reset (void)
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
714 {
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
715 input_reader.reset ();
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
716
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
717 octave_base_lexer::reset ();
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
718 }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
719
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
720 void increment_promptflag (void) { input_reader.increment_promptflag (); }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
721
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
722 void decrement_promptflag (void) { input_reader.decrement_promptflag (); }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
723
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
724 int promptflag (void) const { return input_reader.promptflag (); }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
725
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
726 int promptflag (int n) { return input_reader.promptflag (n); }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
727
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
728 std::string input_source (void) const
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
729 {
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
730 return input_reader.input_source ();
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
731 }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
732
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
733 bool input_from_terminal (void) const
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
734 {
17733
8ad59bef27b5 use more direct method for checking input source for lexer
John W. Eaton <jwe@octave.org>
parents: 17731
diff changeset
735 return input_reader.input_from_terminal ();
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
736 }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
737
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
738 bool input_from_file (void) const
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
739 {
17733
8ad59bef27b5 use more direct method for checking input source for lexer
John W. Eaton <jwe@octave.org>
parents: 17731
diff changeset
740 return input_reader.input_from_file ();
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
741 }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
742
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
743 bool input_from_eval_string (void) const
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
744 {
17733
8ad59bef27b5 use more direct method for checking input source for lexer
John W. Eaton <jwe@octave.org>
parents: 17731
diff changeset
745 return input_reader.input_from_eval_string ();
16293
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
746 }
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
747
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
748 int fill_flex_buffer (char *buf, unsigned int max_size);
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
749
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
750 octave_input_reader input_reader;
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
751
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
752 protected:
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
753
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
754 // No copying!
57e87ddfee14 create base class for lexer
John W. Eaton <jwe@octave.org>
parents: 16292
diff changeset
755
16158
7eb614760ddb rename lexical_feedback to octave_lexer
John W. Eaton <jwe@octave.org>
parents: 16149
diff changeset
756 octave_lexer (const octave_lexer&);
16110
7302f8a4df83 use pointer for global lexical_feedback structure
John W. Eaton <jwe@octave.org>
parents: 16107
diff changeset
757
16158
7eb614760ddb rename lexical_feedback to octave_lexer
John W. Eaton <jwe@octave.org>
parents: 16149
diff changeset
758 octave_lexer& operator = (const octave_lexer&);
1826
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
759 };
b14829582cc4 [project @ 1996-02-02 03:05:07 by jwe]
jwe
parents: 1315
diff changeset
760
16294
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
761 class
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
762 octave_push_lexer : public octave_base_lexer
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
763 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
764 public:
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
765
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
766 octave_push_lexer (const std::string& input = std::string (),
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
767 bool eof = false)
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
768 : octave_base_lexer (), pflag (1)
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
769 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
770 append_input (input, eof);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
771 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
772
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
773 bool is_push_lexer (void) const { return true; }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
774
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
775 void reset (void)
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
776 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
777 promptflag (1);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
778
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
779 octave_base_lexer::reset ();
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
780 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
781
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
782 void append_input (const std::string& input, bool eof)
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
783 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
784 input_buf.fill (input, eof);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
785 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
786
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
787 void increment_promptflag (void) { pflag++; }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
788
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
789 void decrement_promptflag (void) { pflag--; }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
790
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
791 int promptflag (void) const { return pflag; }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
792
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
793 int promptflag (int n)
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
794 {
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
795 int retval = pflag;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
796 pflag = n;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
797 return retval;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
798 }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
799
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
800 std::string input_source (void) const { return "push buffer"; }
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
801
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
802 int fill_flex_buffer (char *buf, unsigned int max_size);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
803
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
804 protected:
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
805
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
806 int pflag;
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
807
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
808 // No copying!
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
809
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
810 octave_push_lexer (const octave_push_lexer&);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
811
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
812 octave_push_lexer& operator = (const octave_push_lexer&);
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
813 };
0925d1f6875e push parser/lexer interface
John W. Eaton <jwe@octave.org>
parents: 16293
diff changeset
814
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
815 #endif