1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include "scanner.hxx"
24 // The tokenizer is stand-alone, i. e. he can be used from everywhere.
25 // A BASIC-instance is necessary for error messages. Without BASIC the
26 // errors are only counted. The BASIC is also necessary when an advanced
27 // SBX-variable shall be used for recognition of data types etc.
32 // tokens between 0x20 and 0x3F are literals:
33 LPAREN
= '(', RPAREN
= ')', COMMA
= ',', DOT
= '.', EXCLAM
= '!',
34 HASH
= '#', SEMICOLON
= ';',
38 AS
= FIRSTKWD
, ALIAS
, ASSIGN
,
39 CALL
, CASE
, CLOSE
, COMPARE
, CONST_
,
42 // in the order of the data type enums!
43 DEFINT
, DEFLNG
, DEFSNG
, DEFDBL
, DEFCUR
, DEFDATE
, DEFSTR
, DEFOBJ
,
44 DEFERR
, DEFBOOL
, DEFVAR
,
45 // in the order of the data type enums!
48 TLONG
, TSINGLE
, TDOUBLE
, TCURRENCY
, TDATE
, TSTRING
, TOBJECT
,
49 ERROR_
, TBOOLEAN
, TVARIANT
, TBYTE
,
52 EACH
, ELSE
, ELSEIF
, END
, ERASE
, EXIT
,
54 GET
, GLOBAL
, GOSUB
, GOTO
,
56 LET
, LINE
, LINEINPUT
, LOCAL
, LOOP
, LPRINT
, LSET
,
58 ON
, OPEN
, OPTION
, ATTRIBUTE
, IMPLEMENTS
,
59 PRINT
, PRIVATE
, PROPERTY
, PUBLIC
,
60 REDIM
, REM
, RESUME
, RETURN
, RSET
,
61 SELECT
, SET
, SHARED
, STATIC
, STEP
, STOP
, SUB
,
62 TEXT
, THEN
, TO
, TYPE
, ENUM
,
64 WEND
, WHILE
, WITH
, WRITE
,
65 ENDENUM
, ENDIF
, ENDFUNC
, ENDPROPERTY
, ENDSUB
, ENDTYPE
, ENDSELECT
, ENDWITH
,
66 // end of all keywords
72 DIV
, IDIV
, MOD
, PLUS
, MINUS
,
73 EQ
, NE
, LT
, GT
, LE
, GE
,
74 NOT
, AND
, OR
, XOR
, EQV
,
75 IMP
, CAT
, LIKE
, IS
, TYPEOF
,
78 NUMBER
=FIRSTEXTRA
, FIXSTRING
, SYMBOL
, CDECL_
, BYVAL
, BYREF
,
79 OUTPUT
, RANDOM
, APPEND
, BINARY
, ACCESS
,
80 LOCK
, READ
, PRESERVE
, BASE
, ANY
, LIB
, OPTIONAL_
, PTRSAFE
,
81 BASIC_EXPLICIT
, COMPATIBLE
, CLASSMODULE
, PARAMARRAY
, WITHEVENTS
,
83 // from here there are JavaScript-tokens (same enum so that same type)
85 JS_BREAK
=FIRSTJAVA
, JS_CONTINUE
, JS_FOR
, JS_FUNCTION
, JS_IF
, JS_NEW
,
86 JS_RETURN
, JS_THIS
, JS_VAR
, JS_WHILE
, JS_WITH
,
88 // JavaScript-operators
90 JS_COMMA
, JS_ASSIGNMENT
, JS_ASS_PLUS
, JS_ASS_MINUS
, JS_ASS_MUL
,
91 JS_ASS_DIV
, JS_ASS_MOD
, JS_ASS_LSHIFT
, JS_ASS_RSHIFT
, JS_ASS_RSHIFT_Z
,
92 JS_ASS_AND
, JS_ASS_XOR
, JS_ASS_OR
,
93 JS_COND_QUEST
, JS_COND_SEL
, JS_LOG_OR
, JS_LOG_AND
, JS_BIT_OR
,
94 JS_BIT_XOR
, JS_BIT_AND
, JS_EQ
, JS_NE
, JS_LT
, JS_LE
,
95 JS_GT
, JS_GE
, JS_LSHIFT
, JS_RSHIFT
, JS_RSHIFT_Z
,
96 JS_PLUS
, JS_MINUS
, JS_MUL
, JS_DIV
, JS_MOD
, JS_LOG_NOT
, JS_BIT_NOT
,
97 JS_INC
, JS_DEC
, JS_LPAREN
, JS_RPAREN
, JS_LINDEX
, JS_RINDEX
101 class SbiTokenizer
: public SbiScanner
{
105 sal_uInt16 nPLine
, nPCol1
, nPCol2
; // pushback location
108 bool bAs
; // last keyword was AS
109 bool bErrorIsSymbol
; // Handle Error token as Symbol, not keyword
111 SbiTokenizer( const OUString
&, StarBASIC
* = nullptr );
113 bool IsEof() const { return bEof
; }
114 bool IsEos() const { return bEos
; }
116 void Push( SbiToken
);
117 const OUString
& Symbol( SbiToken
); // reconversion
119 SbiToken
Peek(); // read the next token
120 SbiToken
Next(); // read a token
121 bool MayBeLabel( bool= false );
123 void Error( ErrCode c
) { GenError( c
); }
124 void Error( ErrCode
, SbiToken
);
125 void Error( ErrCode
, const OUString
&);
127 static bool IsEoln( SbiToken t
)
128 { return t
== EOS
|| t
== EOLN
|| t
== REM
; }
129 static bool IsKwd( SbiToken t
)
130 { return t
>= FIRSTKWD
&& t
<= LASTKWD
; }
131 static bool IsExtra( SbiToken t
)
132 { return t
>= FIRSTEXTRA
; }
133 static OUString
GetKeywordCase( const OUString
& sKeyword
);
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */