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 .
20 #ifndef INCLUDED_BASIC_SOURCE_INC_TOKEN_HXX
21 #define INCLUDED_BASIC_SOURCE_INC_TOKEN_HXX
23 #include "scanner.hxx"
24 #include <basic/sbdef.hxx>
27 #define SbiTokenSHAREDTMPUNDEF
31 #if defined( EXPLICIT )
35 // The tokenizer is stand-alone, i. e. he can be used from everywhere.
36 // A BASIC-instance is necessary for error messages. Without BASIC the
37 // errors are only counted. The BASIC is also necessary when an advanced
38 // SBX-variable shall be used for recognition of data types etc.
43 // tokens between 0x20 and 0x3F are literals:
44 LPAREN
= '(', RPAREN
= ')', COMMA
= ',', DOT
= '.', EXCLAM
= '!',
45 HASH
= '#', SEMICOLON
= ';',
49 AS
= FIRSTKWD
, ALIAS
, ASSIGN
,
50 CALL
, CASE
, CLOSE
, COMPARE
, _CONST_
,
53 // in the order of the data type enums!
54 DEFINT
, DEFLNG
, DEFSNG
, DEFDBL
, DEFCUR
, DEFDATE
, DEFSTR
, DEFOBJ
,
55 DEFERR
, DEFBOOL
, DEFVAR
,
56 // in the order of the data type enums!
59 TLONG
, TSINGLE
, TDOUBLE
, TCURRENCY
, TDATE
, TSTRING
, TOBJECT
,
60 _ERROR_
, TBOOLEAN
, TVARIANT
, TBYTE
,
63 EACH
, ELSE
, ELSEIF
, END
, ERASE
, EXIT
,
65 GET
, GLOBAL
, GOSUB
, GOTO
,
67 LET
, LINE
, LINEINPUT
, LOCAL
, LOOP
, LPRINT
, LSET
,
69 ON
, OPEN
, OPTION
, ATTRIBUTE
, IMPLEMENTS
,
70 PRINT
, PRIVATE
, PROPERTY
, PUBLIC
,
71 REDIM
, REM
, RESUME
, RETURN
, RSET
,
72 SELECT
, SET
, SHARED
, STATIC
, STEP
, STOP
, SUB
,
73 TEXT
, THEN
, TO
, TYPE
, ENUM
,
75 WEND
, WHILE
, WITH
, WRITE
,
76 ENDENUM
, ENDIF
, ENDFUNC
, ENDPROPERTY
, ENDSUB
, ENDTYPE
, ENDSELECT
, ENDWITH
,
77 // end of all keywords
83 DIV
, IDIV
, MOD
, PLUS
, MINUS
,
84 EQ
, NE
, LT
, GT
, LE
, GE
,
85 NOT
, AND
, OR
, XOR
, EQV
,
86 IMP
, CAT
, LIKE
, IS
, TYPEOF
,
89 NUMBER
=FIRSTEXTRA
, FIXSTRING
, SYMBOL
, _CDECL_
, BYVAL
, BYREF
,
90 OUTPUT
, RANDOM
, APPEND
, BINARY
, ACCESS
,
91 LOCK
, READ
, PRESERVE
, BASE
, ANY
, LIB
, _OPTIONAL_
,
92 BASIC_EXPLICIT
, COMPATIBLE
, CLASSMODULE
, PARAMARRAY
, WITHEVENTS
,
94 // from here there are JavaScript-tokens (same enum so that same type)
96 JS_BREAK
=FIRSTJAVA
, JS_CONTINUE
, JS_FOR
, JS_FUNCTION
, JS_IF
, JS_NEW
,
97 JS_RETURN
, JS_THIS
, JS_VAR
, JS_WHILE
, JS_WITH
,
99 // JavaScript-operators
100 // _ASS_ = Assignment
101 JS_COMMA
, JS_ASSIGNMENT
, JS_ASS_PLUS
, JS_ASS_MINUS
, JS_ASS_MUL
,
102 JS_ASS_DIV
, JS_ASS_MOD
, JS_ASS_LSHIFT
, JS_ASS_RSHIFT
, JS_ASS_RSHIFT_Z
,
103 JS_ASS_AND
, JS_ASS_XOR
, JS_ASS_OR
,
104 JS_COND_QUEST
, JS_COND_SEL
, JS_LOG_OR
, JS_LOG_AND
, JS_BIT_OR
,
105 JS_BIT_XOR
, JS_BIT_AND
, JS_EQ
, JS_NE
, JS_LT
, JS_LE
,
106 JS_GT
, JS_GE
, JS_LSHIFT
, JS_RSHIFT
, JS_RSHIFT_Z
,
107 JS_PLUS
, JS_MINUS
, JS_MUL
, JS_DIV
, JS_MOD
, JS_LOG_NOT
, JS_BIT_NOT
,
108 JS_INC
, JS_DEC
, JS_LPAREN
, JS_RPAREN
, JS_LINDEX
, JS_RINDEX
112 #ifdef SbiTokenSHAREDTMPUNDEF
114 #undef SbiTokenSHAREDTMPUNDEF
120 bool* m_pTokenCanBeLabelTab
;
124 TokenLabelInfo( const TokenLabelInfo
& rInfo
)
125 : m_pTokenCanBeLabelTab( NULL
)
129 bool canTokenBeLabel( SbiToken eTok
)
130 { return m_pTokenCanBeLabelTab
[eTok
]; }
133 class SbiTokenizer
: public SbiScanner
{
134 TokenLabelInfo m_aTokenLabelInfo
;
139 sal_uInt16 nPLine
, nPCol1
, nPCol2
; // pushback location
142 bool bKeywords
; // true, if keywords are parsed
143 bool bAs
; // last keyword was AS
144 bool bErrorIsSymbol
; // Handle Error token as Symbol, not keyword
146 SbiTokenizer( const OUString
&, StarBASIC
* = NULL
);
149 inline bool IsEof() { return bEof
; }
150 inline bool IsEos() { return bEos
; }
152 void Push( SbiToken
);
153 const OUString
& Symbol( SbiToken
); // reconversion
155 SbiToken
Peek(); // read the next token
156 SbiToken
Next(); // read a token
157 bool MayBeLabel( bool= false );
159 void Error( SbError c
) { GenError( c
); }
160 void Error( SbError
, SbiToken
);
161 void Error( SbError
, const char* );
162 void Error( SbError
, const OUString
&);
164 static bool IsEoln( SbiToken t
)
165 { return t
== EOS
|| t
== EOLN
|| t
== REM
; }
166 static bool IsKwd( SbiToken t
)
167 { return t
>= FIRSTKWD
&& t
<= LASTKWD
; }
168 static bool IsExtra( SbiToken t
)
169 { return t
>= FIRSTEXTRA
; }
170 static OUString
GetKeywordCase( const OUString
& sKeyword
);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */