1*e1f63238SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e1f63238SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e1f63238SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e1f63238SAndrew Rist * distributed with this work for additional information 6*e1f63238SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e1f63238SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e1f63238SAndrew Rist * "License"); you may not use this file except in compliance 9*e1f63238SAndrew Rist * with the License. You may obtain a copy of the License at 10*e1f63238SAndrew Rist * 11*e1f63238SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*e1f63238SAndrew Rist * 13*e1f63238SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e1f63238SAndrew Rist * software distributed under the License is distributed on an 15*e1f63238SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e1f63238SAndrew Rist * KIND, either express or implied. See the License for the 17*e1f63238SAndrew Rist * specific language governing permissions and limitations 18*e1f63238SAndrew Rist * under the License. 19*e1f63238SAndrew Rist * 20*e1f63238SAndrew Rist *************************************************************/ 21*e1f63238SAndrew Rist 22*e1f63238SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_basic.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <ctype.h> 28cdf0e10cSrcweir #include "sbcomp.hxx" 29cdf0e10cSrcweir 30cdf0e10cSrcweir struct TokenTable { SbiToken t; const char *s; }; 31cdf0e10cSrcweir 32cdf0e10cSrcweir static short nToken; // Anzahl der Tokens 33cdf0e10cSrcweir 34cdf0e10cSrcweir static TokenTable* pTokTable; 35cdf0e10cSrcweir 36cdf0e10cSrcweir static TokenTable aTokTable_Basic [] = { // Token-Tabelle: 37cdf0e10cSrcweir 38cdf0e10cSrcweir { CAT, "&" }, 39cdf0e10cSrcweir { MUL, "*" }, 40cdf0e10cSrcweir { PLUS, "+" }, 41cdf0e10cSrcweir { MINUS, "-" }, 42cdf0e10cSrcweir { DIV, "/" }, 43cdf0e10cSrcweir { EOS, ":" }, 44cdf0e10cSrcweir { ASSIGN, ":=" }, 45cdf0e10cSrcweir { LT, "<" }, 46cdf0e10cSrcweir { LE, "<=" }, 47cdf0e10cSrcweir { NE, "<>" }, 48cdf0e10cSrcweir { EQ, "=" }, 49cdf0e10cSrcweir { GT, ">" }, 50cdf0e10cSrcweir { GE, ">=" }, 51cdf0e10cSrcweir { ACCESS, "Access" }, 52cdf0e10cSrcweir { ALIAS, "Alias" }, 53cdf0e10cSrcweir { AND, "And" }, 54cdf0e10cSrcweir { ANY, "Any" }, 55cdf0e10cSrcweir { APPEND, "Append" }, 56cdf0e10cSrcweir { AS, "As" }, 57cdf0e10cSrcweir { BASE, "Base" }, 58cdf0e10cSrcweir { BINARY, "Binary" }, 59cdf0e10cSrcweir { TBOOLEAN, "Boolean" }, 60cdf0e10cSrcweir { BYREF, "ByRef", }, 61cdf0e10cSrcweir { TBYTE, "Byte", }, 62cdf0e10cSrcweir { BYVAL, "ByVal", }, 63cdf0e10cSrcweir { CALL, "Call" }, 64cdf0e10cSrcweir { CASE, "Case" }, 65cdf0e10cSrcweir { _CDECL_, "Cdecl" }, 66cdf0e10cSrcweir { CLASSMODULE, "ClassModule" }, 67cdf0e10cSrcweir { CLOSE, "Close" }, 68cdf0e10cSrcweir { COMPARE, "Compare" }, 69cdf0e10cSrcweir { COMPATIBLE,"Compatible" }, 70cdf0e10cSrcweir { _CONST_, "Const" }, 71cdf0e10cSrcweir { TCURRENCY,"Currency" }, 72cdf0e10cSrcweir { TDATE, "Date" }, 73cdf0e10cSrcweir { DECLARE, "Declare" }, 74cdf0e10cSrcweir { DEFBOOL, "DefBool" }, 75cdf0e10cSrcweir { DEFCUR, "DefCur" }, 76cdf0e10cSrcweir { DEFDATE, "DefDate" }, 77cdf0e10cSrcweir { DEFDBL, "DefDbl" }, 78cdf0e10cSrcweir { DEFERR, "DefErr" }, 79cdf0e10cSrcweir { DEFINT, "DefInt" }, 80cdf0e10cSrcweir { DEFLNG, "DefLng" }, 81cdf0e10cSrcweir { DEFOBJ, "DefObj" }, 82cdf0e10cSrcweir { DEFSNG, "DefSng" }, 83cdf0e10cSrcweir { DEFSTR, "DefStr" }, 84cdf0e10cSrcweir { DEFVAR, "DefVar" }, 85cdf0e10cSrcweir { DIM, "Dim" }, 86cdf0e10cSrcweir { DO, "Do" }, 87cdf0e10cSrcweir { TDOUBLE, "Double" }, 88cdf0e10cSrcweir { EACH, "Each" }, 89cdf0e10cSrcweir { ELSE, "Else" }, 90cdf0e10cSrcweir { ELSEIF, "ElseIf" }, 91cdf0e10cSrcweir { END, "End" }, 92cdf0e10cSrcweir { ENDENUM, "End Enum" }, 93cdf0e10cSrcweir { ENDFUNC, "End Function" }, 94cdf0e10cSrcweir { ENDIF, "End If" }, 95cdf0e10cSrcweir { ENDPROPERTY, "End Property" }, 96cdf0e10cSrcweir { ENDSELECT,"End Select" }, 97cdf0e10cSrcweir { ENDSUB, "End Sub" }, 98cdf0e10cSrcweir { ENDTYPE, "End Type" }, 99cdf0e10cSrcweir { ENDIF, "EndIf" }, 100cdf0e10cSrcweir { ENUM, "Enum" }, 101cdf0e10cSrcweir { EQV, "Eqv" }, 102cdf0e10cSrcweir { ERASE, "Erase" }, 103cdf0e10cSrcweir { _ERROR_, "Error" }, 104cdf0e10cSrcweir { EXIT, "Exit" }, 105cdf0e10cSrcweir { EXPLICIT, "Explicit" }, 106cdf0e10cSrcweir { FOR, "For" }, 107cdf0e10cSrcweir { FUNCTION, "Function" }, 108cdf0e10cSrcweir { GET, "Get" }, 109cdf0e10cSrcweir { GLOBAL, "Global" }, 110cdf0e10cSrcweir { GOSUB, "GoSub" }, 111cdf0e10cSrcweir { GOTO, "GoTo" }, 112cdf0e10cSrcweir { IF, "If" }, 113cdf0e10cSrcweir { IMP, "Imp" }, 114cdf0e10cSrcweir { IMPLEMENTS, "Implements" }, 115cdf0e10cSrcweir { _IN_, "In" }, 116cdf0e10cSrcweir { INPUT, "Input" }, // auch INPUT # 117cdf0e10cSrcweir { TINTEGER, "Integer" }, 118cdf0e10cSrcweir { IS, "Is" }, 119cdf0e10cSrcweir { LET, "Let" }, 120cdf0e10cSrcweir { LIB, "Lib" }, 121cdf0e10cSrcweir { LIKE, "Like" }, 122cdf0e10cSrcweir { LINE, "Line" }, 123cdf0e10cSrcweir { LINEINPUT,"Line Input" }, 124cdf0e10cSrcweir { LOCAL, "Local" }, 125cdf0e10cSrcweir { LOCK, "Lock" }, 126cdf0e10cSrcweir { TLONG, "Long" }, 127cdf0e10cSrcweir { LOOP, "Loop" }, 128cdf0e10cSrcweir { LPRINT, "LPrint" }, 129cdf0e10cSrcweir { LSET, "LSet" }, // JSM 130cdf0e10cSrcweir { MOD, "Mod" }, 131cdf0e10cSrcweir { NAME, "Name" }, 132cdf0e10cSrcweir { NEW, "New" }, 133cdf0e10cSrcweir { NEXT, "Next" }, 134cdf0e10cSrcweir { NOT, "Not" }, 135cdf0e10cSrcweir { TOBJECT, "Object" }, 136cdf0e10cSrcweir { ON, "On" }, 137cdf0e10cSrcweir { OPEN, "Open" }, 138cdf0e10cSrcweir { OPTION, "Option" }, 139cdf0e10cSrcweir { _OPTIONAL_, "Optional" }, 140cdf0e10cSrcweir { OR, "Or" }, 141cdf0e10cSrcweir { OUTPUT, "Output" }, 142cdf0e10cSrcweir { PARAMARRAY, "ParamArray" }, 143cdf0e10cSrcweir { PRESERVE, "Preserve" }, 144cdf0e10cSrcweir { PRINT, "Print" }, 145cdf0e10cSrcweir { PRIVATE, "Private" }, 146cdf0e10cSrcweir { PROPERTY, "Property" }, 147cdf0e10cSrcweir { PUBLIC, "Public" }, 148cdf0e10cSrcweir { RANDOM, "Random" }, 149cdf0e10cSrcweir { READ, "Read" }, 150cdf0e10cSrcweir { REDIM, "ReDim" }, 151cdf0e10cSrcweir { REM, "Rem" }, 152cdf0e10cSrcweir { RESUME, "Resume" }, 153cdf0e10cSrcweir { RETURN, "Return" }, 154cdf0e10cSrcweir { RSET, "RSet" }, // JSM 155cdf0e10cSrcweir { SELECT, "Select" }, 156cdf0e10cSrcweir { SET, "Set" }, 157cdf0e10cSrcweir #ifdef SHARED 158cdf0e10cSrcweir #undef SHARED 159cdf0e10cSrcweir #define tmpSHARED 160cdf0e10cSrcweir #endif 161cdf0e10cSrcweir { SHARED, "Shared" }, 162cdf0e10cSrcweir #ifdef tmpSHARED 163cdf0e10cSrcweir #define SHARED 164cdf0e10cSrcweir #undef tmpSHARED 165cdf0e10cSrcweir #endif 166cdf0e10cSrcweir { TSINGLE, "Single" }, 167cdf0e10cSrcweir { STATIC, "Static" }, 168cdf0e10cSrcweir { STEP, "Step" }, 169cdf0e10cSrcweir { STOP, "Stop" }, 170cdf0e10cSrcweir { TSTRING, "String" }, 171cdf0e10cSrcweir { SUB, "Sub" }, 172cdf0e10cSrcweir { STOP, "System" }, 173cdf0e10cSrcweir { TEXT, "Text" }, 174cdf0e10cSrcweir { THEN, "Then" }, 175cdf0e10cSrcweir { TO, "To", }, 176cdf0e10cSrcweir { TYPE, "Type" }, 177cdf0e10cSrcweir { TYPEOF, "TypeOf" }, 178cdf0e10cSrcweir { UNTIL, "Until" }, 179cdf0e10cSrcweir { TVARIANT, "Variant" }, 180cdf0e10cSrcweir { VBASUPPORT, "VbaSupport" }, 181cdf0e10cSrcweir { WEND, "Wend" }, 182cdf0e10cSrcweir { WHILE, "While" }, 183cdf0e10cSrcweir { WITH, "With" }, 184cdf0e10cSrcweir { WITHEVENTS, "WithEvents" }, 185cdf0e10cSrcweir { WRITE, "Write" }, // auch WRITE # 186cdf0e10cSrcweir { XOR, "Xor" }, 187cdf0e10cSrcweir { NIL, "" } 188cdf0e10cSrcweir }; 189cdf0e10cSrcweir 190cdf0e10cSrcweir /* 191cdf0e10cSrcweir TokenTable aTokTable_Java [] = { // Token-Tabelle: 192cdf0e10cSrcweir 193cdf0e10cSrcweir { JS_LOG_NOT, "!" }, 194cdf0e10cSrcweir { JS_NE, "!=" }, 195cdf0e10cSrcweir { JS_MOD, "%" }, 196cdf0e10cSrcweir { JS_ASS_MOD, "%=" }, 197cdf0e10cSrcweir { JS_BIT_AND, "&" }, 198cdf0e10cSrcweir { JS_LOG_AND, "&&" }, 199cdf0e10cSrcweir { JS_ASS_AND, "&=" }, 200cdf0e10cSrcweir { JS_LPAREN, "(" }, 201cdf0e10cSrcweir { JS_RPAREN, ")" }, 202cdf0e10cSrcweir { JS_MUL, "*" }, 203cdf0e10cSrcweir { JS_ASS_MUL, "*=" }, 204cdf0e10cSrcweir { JS_PLUS, "+" }, 205cdf0e10cSrcweir { JS_INC, "++" }, 206cdf0e10cSrcweir { JS_ASS_PLUS, "+=" }, 207cdf0e10cSrcweir { JS_COMMA, "," }, 208cdf0e10cSrcweir { JS_MINUS, "-" }, 209cdf0e10cSrcweir { JS_DEC, "--" }, 210cdf0e10cSrcweir { JS_ASS_MINUS, "-=" }, 211cdf0e10cSrcweir { JS_DIV, "/" }, 212cdf0e10cSrcweir { JS_ASS_DIV, "/=" }, 213cdf0e10cSrcweir { JS_COND_SEL, ":" }, 214cdf0e10cSrcweir { JS_LT, "<" }, 215cdf0e10cSrcweir { JS_LSHIFT, "<<" }, 216cdf0e10cSrcweir { JS_ASS_LSHIFT,"<<=" }, 217cdf0e10cSrcweir { JS_LE, "<=" }, 218cdf0e10cSrcweir { JS_NE, "<>" }, 219cdf0e10cSrcweir { JS_ASSIGNMENT,"=" }, 220cdf0e10cSrcweir { JS_EQ, "==" }, 221cdf0e10cSrcweir { JS_GT, ">" }, 222cdf0e10cSrcweir { JS_RSHIFT, ">>" }, 223cdf0e10cSrcweir { JS_ASS_RSHIFT,">>=" }, 224cdf0e10cSrcweir { JS_RSHIFT_Z, ">>>" }, 225cdf0e10cSrcweir { JS_ASS_RSHIFT_Z,">>>=" }, 226cdf0e10cSrcweir { JS_GE, ">=" }, 227cdf0e10cSrcweir { JS_COND_QUEST,"?" }, 228cdf0e10cSrcweir { ACCESS, "Access" }, 229cdf0e10cSrcweir { ALIAS, "Alias" }, 230cdf0e10cSrcweir { AND, "And" }, 231cdf0e10cSrcweir { ANY, "Any" }, 232cdf0e10cSrcweir { APPEND, "Append" }, 233cdf0e10cSrcweir { AS, "As" }, 234cdf0e10cSrcweir { BASE, "Base" }, 235cdf0e10cSrcweir { BINARY, "Binary" }, 236cdf0e10cSrcweir { TBOOLEAN, "Boolean" }, 237cdf0e10cSrcweir { BYVAL, "ByVal", }, 238cdf0e10cSrcweir { CALL, "Call" }, 239cdf0e10cSrcweir { CASE, "Case" }, 240cdf0e10cSrcweir { _CDECL_, "Cdecl" }, 241cdf0e10cSrcweir { CLOSE, "Close" }, 242cdf0e10cSrcweir { COMPARE, "Compare" }, 243cdf0e10cSrcweir { _CONST_, "Const" }, 244cdf0e10cSrcweir { TCURRENCY,"Currency" }, 245cdf0e10cSrcweir { TDATE, "Date" }, 246cdf0e10cSrcweir { DECLARE, "Declare" }, 247cdf0e10cSrcweir { DEFBOOL, "DefBool" }, 248cdf0e10cSrcweir { DEFCUR, "DefCur" }, 249cdf0e10cSrcweir { DEFDATE, "DefDate" }, 250cdf0e10cSrcweir { DEFDBL, "DefDbl" }, 251cdf0e10cSrcweir { DEFERR, "DefErr" }, 252cdf0e10cSrcweir { DEFINT, "DefInt" }, 253cdf0e10cSrcweir { DEFLNG, "DefLng" }, 254cdf0e10cSrcweir { DEFOBJ, "DefObj" }, 255cdf0e10cSrcweir { DEFSNG, "DefSng" }, 256cdf0e10cSrcweir { DEFSTR, "DefStr" }, 257cdf0e10cSrcweir { DEFVAR, "DefVar" }, 258cdf0e10cSrcweir { DIM, "Dim" }, 259cdf0e10cSrcweir { DO, "Do" }, 260cdf0e10cSrcweir { TDOUBLE, "Double" }, 261cdf0e10cSrcweir { EACH, "Each" }, 262cdf0e10cSrcweir { ELSE, "Else" }, 263cdf0e10cSrcweir { ELSEIF, "ElseIf" }, 264cdf0e10cSrcweir { END, "End" }, 265cdf0e10cSrcweir { ENDFUNC, "End Function" }, 266cdf0e10cSrcweir { ENDIF, "End If" }, 267cdf0e10cSrcweir { ENDSELECT,"End Select" }, 268cdf0e10cSrcweir { ENDSUB, "End Sub" }, 269cdf0e10cSrcweir { ENDTYPE, "End Type" }, 270cdf0e10cSrcweir { ENDIF, "EndIf" }, 271cdf0e10cSrcweir { EQV, "Eqv" }, 272cdf0e10cSrcweir { ERASE, "Erase" }, 273cdf0e10cSrcweir { _ERROR_, "Error" }, 274cdf0e10cSrcweir { EXIT, "Exit" }, 275cdf0e10cSrcweir { EXPLICIT, "Explicit" }, 276cdf0e10cSrcweir { FOR, "For" }, 277cdf0e10cSrcweir { FUNCTION, "Function" }, 278cdf0e10cSrcweir { GLOBAL, "Global" }, 279cdf0e10cSrcweir { GOSUB, "GoSub" }, 280cdf0e10cSrcweir { GOTO, "GoTo" }, 281cdf0e10cSrcweir { IF, "If" }, 282cdf0e10cSrcweir { IMP, "Imp" }, 283cdf0e10cSrcweir { _IN_, "In" }, 284cdf0e10cSrcweir { INPUT, "Input" }, // auch INPUT # 285cdf0e10cSrcweir { TINTEGER, "Integer" }, 286cdf0e10cSrcweir { IS, "Is" }, 287cdf0e10cSrcweir { LET, "Let" }, 288cdf0e10cSrcweir { LIB, "Lib" }, 289cdf0e10cSrcweir { LINE, "Line" }, 290cdf0e10cSrcweir { LINEINPUT,"Line Input" }, 291cdf0e10cSrcweir { LOCAL, "Local" }, 292cdf0e10cSrcweir { LOCK, "Lock" }, 293cdf0e10cSrcweir { TLONG, "Long" }, 294cdf0e10cSrcweir { LOOP, "Loop" }, 295cdf0e10cSrcweir { LPRINT, "LPrint" }, 296cdf0e10cSrcweir { LSET, "LSet" }, // JSM 297cdf0e10cSrcweir { MOD, "Mod" }, 298cdf0e10cSrcweir { NAME, "Name" }, 299cdf0e10cSrcweir { NEW, "New" }, 300cdf0e10cSrcweir { NEXT, "Next" }, 301cdf0e10cSrcweir { NOT, "Not" }, 302cdf0e10cSrcweir { TOBJECT, "Object" }, 303cdf0e10cSrcweir { ON, "On" }, 304cdf0e10cSrcweir { OPEN, "Open" }, 305cdf0e10cSrcweir { OPTION, "Option" }, 306cdf0e10cSrcweir { _OPTIONAL_, "Optional" }, 307cdf0e10cSrcweir { OR, "Or" }, 308cdf0e10cSrcweir { OUTPUT, "Output" }, 309cdf0e10cSrcweir { PRESERVE, "Preserve" }, 310cdf0e10cSrcweir { PRINT, "Print" }, 311cdf0e10cSrcweir { PRIVATE, "Private" }, 312cdf0e10cSrcweir { PUBLIC, "Public" }, 313cdf0e10cSrcweir { RANDOM, "Random" }, 314cdf0e10cSrcweir { READ, "Read" }, 315cdf0e10cSrcweir { REDIM, "ReDim" }, 316cdf0e10cSrcweir { REM, "Rem" }, 317cdf0e10cSrcweir { RESUME, "Resume" }, 318cdf0e10cSrcweir { RETURN, "Return" }, 319cdf0e10cSrcweir { RSET, "RSet" }, // JSM 320cdf0e10cSrcweir { SELECT, "Select" }, 321cdf0e10cSrcweir { SET, "Set" }, 322cdf0e10cSrcweir { SHARED, "Shared" }, 323cdf0e10cSrcweir { TSINGLE, "Single" }, 324cdf0e10cSrcweir { STATIC, "Static" }, 325cdf0e10cSrcweir { STEP, "Step" }, 326cdf0e10cSrcweir { STOP, "Stop" }, 327cdf0e10cSrcweir { TSTRING, "String" }, 328cdf0e10cSrcweir { SUB, "Sub" }, 329cdf0e10cSrcweir { STOP, "System" }, 330cdf0e10cSrcweir { TEXT, "Text" }, 331cdf0e10cSrcweir { THEN, "Then" }, 332cdf0e10cSrcweir { TO, "To", }, 333cdf0e10cSrcweir { TYPE, "Type" }, 334cdf0e10cSrcweir { UNTIL, "Until" }, 335cdf0e10cSrcweir { TVARIANT, "Variant" }, 336cdf0e10cSrcweir { WEND, "Wend" }, 337cdf0e10cSrcweir { WHILE, "While" }, 338cdf0e10cSrcweir { WITH, "With" }, 339cdf0e10cSrcweir { WRITE, "Write" }, // auch WRITE # 340cdf0e10cSrcweir { XOR, "Xor" }, 341cdf0e10cSrcweir { JS_LINDEX, "[" }, 342cdf0e10cSrcweir { JS_RINDEX, "]" }, 343cdf0e10cSrcweir { JS_BIT_XOR, "^" }, 344cdf0e10cSrcweir { JS_ASS_XOR, "^=" }, 345cdf0e10cSrcweir { JS_BIT_OR, "|" }, 346cdf0e10cSrcweir { JS_ASS_OR, "|=" }, 347cdf0e10cSrcweir { JS_LOG_OR, "||" }, 348cdf0e10cSrcweir { JS_BIT_NOT, "~" }, 349cdf0e10cSrcweir { NIL } 350cdf0e10cSrcweir }; 351cdf0e10cSrcweir */ 352cdf0e10cSrcweir 353cdf0e10cSrcweir // #i109076 354cdf0e10cSrcweir TokenLabelInfo::TokenLabelInfo( void ) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir m_pTokenCanBeLabelTab = new bool[VBASUPPORT+1]; 357cdf0e10cSrcweir for( int i = 0 ; i <= VBASUPPORT ; ++i ) 358cdf0e10cSrcweir m_pTokenCanBeLabelTab[i] = false; 359cdf0e10cSrcweir 360cdf0e10cSrcweir // Token accepted as label by VBA 361cdf0e10cSrcweir SbiToken eLabelToken[] = { ACCESS, ALIAS, APPEND, BASE, BINARY, CLASSMODULE, 362cdf0e10cSrcweir COMPARE, COMPATIBLE, DEFERR, _ERROR_, EXPLICIT, LIB, LINE, LPRINT, NAME, 363cdf0e10cSrcweir TOBJECT, OUTPUT, PROPERTY, RANDOM, READ, STEP, STOP, TEXT, VBASUPPORT, NIL }; 364cdf0e10cSrcweir SbiToken* pTok = eLabelToken; 365cdf0e10cSrcweir SbiToken eTok; 366cdf0e10cSrcweir for( pTok = eLabelToken ; (eTok = *pTok) != NIL ; ++pTok ) 367cdf0e10cSrcweir m_pTokenCanBeLabelTab[eTok] = true; 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir TokenLabelInfo::~TokenLabelInfo() 371cdf0e10cSrcweir { 372cdf0e10cSrcweir delete[] m_pTokenCanBeLabelTab; 373cdf0e10cSrcweir } 374cdf0e10cSrcweir 375cdf0e10cSrcweir 376cdf0e10cSrcweir // Der Konstruktor ermittelt die Laenge der Token-Tabelle. 377cdf0e10cSrcweir 378cdf0e10cSrcweir SbiTokenizer::SbiTokenizer( const ::rtl::OUString& rSrc, StarBASIC* pb ) 379cdf0e10cSrcweir : SbiScanner( rSrc, pb ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir pTokTable = aTokTable_Basic; 382cdf0e10cSrcweir //if( StarBASIC::GetGlobalLanguageMode() == SB_LANG_JAVASCRIPT ) 383cdf0e10cSrcweir // pTokTable = aTokTable_Java; 384cdf0e10cSrcweir TokenTable *tp; 385cdf0e10cSrcweir bEof = bAs = sal_False; 386cdf0e10cSrcweir eCurTok = NIL; 387cdf0e10cSrcweir ePush = NIL; 388cdf0e10cSrcweir bEos = bKeywords = bErrorIsSymbol = sal_True; 389cdf0e10cSrcweir if( !nToken ) 390cdf0e10cSrcweir for( nToken = 0, tp = pTokTable; tp->t; nToken++, tp++ ) {} 391cdf0e10cSrcweir } 392cdf0e10cSrcweir 393cdf0e10cSrcweir SbiTokenizer::~SbiTokenizer() 394cdf0e10cSrcweir { 395cdf0e10cSrcweir } 396cdf0e10cSrcweir 397cdf0e10cSrcweir // Wiederablage (Pushback) eines Tokens. (Bis zu 2 Tokens) 398cdf0e10cSrcweir 399cdf0e10cSrcweir void SbiTokenizer::Push( SbiToken t ) 400cdf0e10cSrcweir { 401cdf0e10cSrcweir if( ePush != NIL ) 402cdf0e10cSrcweir Error( SbERR_INTERNAL_ERROR, "PUSH" ); 403cdf0e10cSrcweir else ePush = t; 404cdf0e10cSrcweir } 405cdf0e10cSrcweir 406cdf0e10cSrcweir void SbiTokenizer::Error( SbError code, const char* pMsg ) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir aError = String::CreateFromAscii( pMsg ); 409cdf0e10cSrcweir Error( code ); 410cdf0e10cSrcweir } 411cdf0e10cSrcweir 412cdf0e10cSrcweir void SbiTokenizer::Error( SbError code, String aMsg ) 413cdf0e10cSrcweir { 414cdf0e10cSrcweir aError = aMsg; 415cdf0e10cSrcweir Error( code ); 416cdf0e10cSrcweir } 417cdf0e10cSrcweir 418cdf0e10cSrcweir void SbiTokenizer::Error( SbError code, SbiToken tok ) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir aError = Symbol( tok ); 421cdf0e10cSrcweir Error( code ); 422cdf0e10cSrcweir } 423cdf0e10cSrcweir 424cdf0e10cSrcweir // Einlesen des naechsten Tokens, ohne dass das Token geschluckt wird 425cdf0e10cSrcweir 426cdf0e10cSrcweir SbiToken SbiTokenizer::Peek() 427cdf0e10cSrcweir { 428cdf0e10cSrcweir if( ePush == NIL ) 429cdf0e10cSrcweir { 430cdf0e10cSrcweir sal_uInt16 nOldLine = nLine; 431cdf0e10cSrcweir sal_uInt16 nOldCol1 = nCol1; 432cdf0e10cSrcweir sal_uInt16 nOldCol2 = nCol2; 433cdf0e10cSrcweir ePush = Next(); 434cdf0e10cSrcweir nPLine = nLine; nLine = nOldLine; 435cdf0e10cSrcweir nPCol1 = nCol1; nCol1 = nOldCol1; 436cdf0e10cSrcweir nPCol2 = nCol2; nCol2 = nOldCol2; 437cdf0e10cSrcweir } 438cdf0e10cSrcweir return eCurTok = ePush; 439cdf0e10cSrcweir } 440cdf0e10cSrcweir 441cdf0e10cSrcweir // Dies ist fuer die Decompilation. 442cdf0e10cSrcweir // Zahlen und Symbole liefern einen Leerstring zurueck. 443cdf0e10cSrcweir 444cdf0e10cSrcweir const String& SbiTokenizer::Symbol( SbiToken t ) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir // Zeichen-Token? 447cdf0e10cSrcweir if( t < FIRSTKWD ) 448cdf0e10cSrcweir { 449cdf0e10cSrcweir aSym = (char) t; 450cdf0e10cSrcweir return aSym; 451cdf0e10cSrcweir } 452cdf0e10cSrcweir switch( t ) 453cdf0e10cSrcweir { 454cdf0e10cSrcweir case NEG : aSym = '-'; return aSym; 455cdf0e10cSrcweir case EOS : aSym = String::CreateFromAscii( ":/CRLF" ); return aSym; 456cdf0e10cSrcweir case EOLN : aSym = String::CreateFromAscii( "CRLF" ); return aSym; 457cdf0e10cSrcweir default: break; 458cdf0e10cSrcweir } 459cdf0e10cSrcweir TokenTable* tp = pTokTable; 460cdf0e10cSrcweir for( short i = 0; i < nToken; i++, tp++ ) 461cdf0e10cSrcweir { 462cdf0e10cSrcweir if( tp->t == t ) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir aSym = String::CreateFromAscii( tp->s ); 465cdf0e10cSrcweir return aSym; 466cdf0e10cSrcweir } 467cdf0e10cSrcweir } 468cdf0e10cSrcweir const sal_Unicode *p = aSym.GetBuffer(); 469cdf0e10cSrcweir if (*p <= ' ') aSym = String::CreateFromAscii( "???" ); 470cdf0e10cSrcweir return aSym; 471cdf0e10cSrcweir } 472cdf0e10cSrcweir 473cdf0e10cSrcweir // Einlesen des naechsten Tokens und Ablage desselben 474cdf0e10cSrcweir // Tokens, die nicht in der Token-Tabelle vorkommen, werden 475cdf0e10cSrcweir // direkt als Zeichen zurueckgeliefert. 476cdf0e10cSrcweir // Einige Worte werden gesondert behandelt. 477cdf0e10cSrcweir 478cdf0e10cSrcweir SbiToken SbiTokenizer::Next() 479cdf0e10cSrcweir { 480cdf0e10cSrcweir if (bEof) return EOLN; 481cdf0e10cSrcweir // Schon eines eingelesen? 482cdf0e10cSrcweir if( ePush != NIL ) 483cdf0e10cSrcweir { 484cdf0e10cSrcweir eCurTok = ePush; 485cdf0e10cSrcweir ePush = NIL; 486cdf0e10cSrcweir nLine = nPLine; 487cdf0e10cSrcweir nCol1 = nPCol1; 488cdf0e10cSrcweir nCol2 = nPCol2; 489cdf0e10cSrcweir bEos = IsEoln( eCurTok ); 490cdf0e10cSrcweir return eCurTok; 491cdf0e10cSrcweir } 492cdf0e10cSrcweir TokenTable *tp; 493cdf0e10cSrcweir 494cdf0e10cSrcweir // Sonst einlesen: 495cdf0e10cSrcweir if( !NextSym() ) 496cdf0e10cSrcweir { 497cdf0e10cSrcweir bEof = bEos = sal_True; 498cdf0e10cSrcweir return eCurTok = EOLN; 499cdf0e10cSrcweir } 500cdf0e10cSrcweir // Zeilenende? 501cdf0e10cSrcweir if( aSym.GetBuffer()[0] == '\n' ) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir bEos = sal_True; return eCurTok = EOLN; 504cdf0e10cSrcweir } 505cdf0e10cSrcweir bEos = sal_False; 506cdf0e10cSrcweir 507cdf0e10cSrcweir // Zahl? 508cdf0e10cSrcweir if( bNumber ) 509cdf0e10cSrcweir return eCurTok = NUMBER; 510cdf0e10cSrcweir 511cdf0e10cSrcweir // String? 512cdf0e10cSrcweir else if( ( eScanType == SbxDATE || eScanType == SbxSTRING ) && !bSymbol ) 513cdf0e10cSrcweir return eCurTok = FIXSTRING; 514cdf0e10cSrcweir // Sonderfaelle von Zeichen, die zwischen "Z" und "a" liegen. ICompare() 515cdf0e10cSrcweir // wertet die Position dieser Zeichen unterschiedlich aus. 516cdf0e10cSrcweir else if( aSym.GetBuffer()[0] == '^' ) 517cdf0e10cSrcweir return eCurTok = EXPON; 518cdf0e10cSrcweir else if( aSym.GetBuffer()[0] == '\\' ) 519cdf0e10cSrcweir return eCurTok = IDIV; 520cdf0e10cSrcweir else 521cdf0e10cSrcweir { 522cdf0e10cSrcweir // Mit Typkennung oder ein Symbol und keine Keyword-Erkennung? 523cdf0e10cSrcweir // Dann kein Token-Test 524cdf0e10cSrcweir if( eScanType != SbxVARIANT 525cdf0e10cSrcweir || ( !bKeywords && bSymbol ) ) 526cdf0e10cSrcweir return eCurTok = SYMBOL; 527cdf0e10cSrcweir // Gueltiges Token? 528cdf0e10cSrcweir short lb = 0; 529cdf0e10cSrcweir short ub = nToken-1; 530cdf0e10cSrcweir short delta; 531cdf0e10cSrcweir do 532cdf0e10cSrcweir { 533cdf0e10cSrcweir delta = (ub - lb) >> 1; 534cdf0e10cSrcweir tp = &pTokTable[ lb + delta ]; 535cdf0e10cSrcweir StringCompare res = aSym.CompareIgnoreCaseToAscii( tp->s ); 536cdf0e10cSrcweir // Gefunden? 537cdf0e10cSrcweir if( res == COMPARE_EQUAL ) 538cdf0e10cSrcweir goto special; 539cdf0e10cSrcweir // Groesser? Dann untere Haelfte 540cdf0e10cSrcweir if( res == COMPARE_LESS ) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir if ((ub - lb) == 2) ub = lb; 543cdf0e10cSrcweir else ub = ub - delta; 544cdf0e10cSrcweir } 545cdf0e10cSrcweir // Kleiner? Dann obere Haelfte 546cdf0e10cSrcweir else 547cdf0e10cSrcweir { 548cdf0e10cSrcweir if ((ub -lb) == 2) lb = ub; 549cdf0e10cSrcweir else lb = lb + delta; 550cdf0e10cSrcweir } 551cdf0e10cSrcweir } while( delta ); 552cdf0e10cSrcweir // Symbol? Wenn nicht >= Token 553cdf0e10cSrcweir sal_Unicode ch = aSym.GetBuffer()[0]; 554cdf0e10cSrcweir if( !BasicSimpleCharClass::isAlpha( ch, bCompatible ) && !bSymbol ) 555cdf0e10cSrcweir return eCurTok = (SbiToken) (ch & 0x00FF); 556cdf0e10cSrcweir return eCurTok = SYMBOL; 557cdf0e10cSrcweir } 558cdf0e10cSrcweir special: 559cdf0e10cSrcweir // #i92642 560cdf0e10cSrcweir bool bStartOfLine = (eCurTok == NIL || eCurTok == REM || eCurTok == EOLN); 561cdf0e10cSrcweir if( !bStartOfLine && (tp->t == NAME || tp->t == LINE) ) 562cdf0e10cSrcweir return eCurTok = SYMBOL; 563cdf0e10cSrcweir else if( tp->t == TEXT ) 564cdf0e10cSrcweir return eCurTok = SYMBOL; 565cdf0e10cSrcweir 566cdf0e10cSrcweir // #i92642: Special LINE token handling -> SbiParser::Line() 567cdf0e10cSrcweir 568cdf0e10cSrcweir // END IF, CASE, SUB, DEF, FUNCTION, TYPE, CLASS, WITH 569cdf0e10cSrcweir if( tp->t == END ) 570cdf0e10cSrcweir { 571cdf0e10cSrcweir // AB, 15.3.96, Spezialbehandlung fuer END, beim Peek() geht die 572cdf0e10cSrcweir // aktuelle Zeile verloren, daher alles merken und danach restaurieren 573cdf0e10cSrcweir sal_uInt16 nOldLine = nLine; 574cdf0e10cSrcweir sal_uInt16 nOldCol = nCol; 575cdf0e10cSrcweir sal_uInt16 nOldCol1 = nCol1; 576cdf0e10cSrcweir sal_uInt16 nOldCol2 = nCol2; 577cdf0e10cSrcweir String aOldSym = aSym; 578cdf0e10cSrcweir SaveLine(); // pLine im Scanner sichern 579cdf0e10cSrcweir 580cdf0e10cSrcweir eCurTok = Peek(); 581cdf0e10cSrcweir switch( eCurTok ) 582cdf0e10cSrcweir { 583cdf0e10cSrcweir case IF: Next(); eCurTok = ENDIF; break; 584cdf0e10cSrcweir case SELECT: Next(); eCurTok = ENDSELECT; break; 585cdf0e10cSrcweir case SUB: Next(); eCurTok = ENDSUB; break; 586cdf0e10cSrcweir case FUNCTION: Next(); eCurTok = ENDFUNC; break; 587cdf0e10cSrcweir case PROPERTY: Next(); eCurTok = ENDPROPERTY; break; 588cdf0e10cSrcweir case TYPE: Next(); eCurTok = ENDTYPE; break; 589cdf0e10cSrcweir case ENUM: Next(); eCurTok = ENDENUM; break; 590cdf0e10cSrcweir case WITH: Next(); eCurTok = ENDWITH; break; 591cdf0e10cSrcweir default : eCurTok = END; 592cdf0e10cSrcweir } 593cdf0e10cSrcweir nCol1 = nOldCol1; 594cdf0e10cSrcweir if( eCurTok == END ) 595cdf0e10cSrcweir { 596cdf0e10cSrcweir // Alles zuruecksetzen, damit Token nach END ganz neu gelesen wird 597cdf0e10cSrcweir ePush = NIL; 598cdf0e10cSrcweir nLine = nOldLine; 599cdf0e10cSrcweir nCol = nOldCol; 600cdf0e10cSrcweir nCol2 = nOldCol2; 601cdf0e10cSrcweir aSym = aOldSym; 602cdf0e10cSrcweir RestoreLine(); // pLine im Scanner restaurieren 603cdf0e10cSrcweir } 604cdf0e10cSrcweir return eCurTok; 605cdf0e10cSrcweir } 606cdf0e10cSrcweir // Sind Datentypen Keywords? 607cdf0e10cSrcweir // Nur nach AS, sonst sind es Symbole! 608cdf0e10cSrcweir // Es gibt ja ERROR(), DATA(), STRING() etc. 609cdf0e10cSrcweir eCurTok = tp->t; 610cdf0e10cSrcweir // AS: Datentypen sind Keywords 611cdf0e10cSrcweir if( tp->t == AS ) 612cdf0e10cSrcweir bAs = sal_True; 613cdf0e10cSrcweir else 614cdf0e10cSrcweir { 615cdf0e10cSrcweir if( bAs ) 616cdf0e10cSrcweir bAs = sal_False; 617cdf0e10cSrcweir else if( eCurTok >= DATATYPE1 && eCurTok <= DATATYPE2 && (bErrorIsSymbol || eCurTok != _ERROR_) ) 618cdf0e10cSrcweir eCurTok = SYMBOL; 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir // CLASSMODULE, PROPERTY, GET, ENUM token only visible in compatible mode 622cdf0e10cSrcweir SbiToken eTok = tp->t; 623cdf0e10cSrcweir if( bCompatible ) 624cdf0e10cSrcweir { 625cdf0e10cSrcweir // #129904 Suppress system 626cdf0e10cSrcweir if( eTok == STOP && aSym.CompareIgnoreCaseToAscii( "system" ) == COMPARE_EQUAL ) 627cdf0e10cSrcweir eCurTok = SYMBOL; 628cdf0e10cSrcweir 629cdf0e10cSrcweir if( eTok == GET && bStartOfLine ) 630cdf0e10cSrcweir eCurTok = SYMBOL; 631cdf0e10cSrcweir } 632cdf0e10cSrcweir else 633cdf0e10cSrcweir { 634cdf0e10cSrcweir if( eTok == CLASSMODULE || 635cdf0e10cSrcweir eTok == IMPLEMENTS || 636cdf0e10cSrcweir eTok == PARAMARRAY || 637cdf0e10cSrcweir eTok == ENUM || 638cdf0e10cSrcweir eTok == PROPERTY || 639cdf0e10cSrcweir eTok == GET || 640cdf0e10cSrcweir eTok == TYPEOF ) 641cdf0e10cSrcweir { 642cdf0e10cSrcweir eCurTok = SYMBOL; 643cdf0e10cSrcweir } 644cdf0e10cSrcweir } 645cdf0e10cSrcweir 646cdf0e10cSrcweir bEos = IsEoln( eCurTok ); 647cdf0e10cSrcweir return eCurTok; 648cdf0e10cSrcweir } 649cdf0e10cSrcweir 650cdf0e10cSrcweir #ifdef _MSC_VER 651cdf0e10cSrcweir #pragma optimize("",off) 652cdf0e10cSrcweir #endif 653cdf0e10cSrcweir 654cdf0e10cSrcweir // Kann das aktuell eingelesene Token ein Label sein? 655cdf0e10cSrcweir 656cdf0e10cSrcweir sal_Bool SbiTokenizer::MayBeLabel( sal_Bool bNeedsColon ) 657cdf0e10cSrcweir { 658cdf0e10cSrcweir if( eCurTok == SYMBOL || m_aTokenLabelInfo.canTokenBeLabel( eCurTok ) ) 659cdf0e10cSrcweir return bNeedsColon ? DoesColonFollow() : sal_True; 660cdf0e10cSrcweir else 661cdf0e10cSrcweir return sal_Bool( eCurTok == NUMBER 662cdf0e10cSrcweir && eScanType == SbxINTEGER 663cdf0e10cSrcweir && nVal >= 0 ); 664cdf0e10cSrcweir } 665cdf0e10cSrcweir 666cdf0e10cSrcweir #ifdef _MSC_VER 667cdf0e10cSrcweir #pragma optimize("",off) 668cdf0e10cSrcweir #endif 669cdf0e10cSrcweir 670cdf0e10cSrcweir 671cdf0e10cSrcweir void SbiTokenizer::Hilite( SbTextPortions& rList ) 672cdf0e10cSrcweir { 673cdf0e10cSrcweir bErrors = sal_False; 674cdf0e10cSrcweir bUsedForHilite = sal_True; 675cdf0e10cSrcweir SbiToken eLastTok = NIL; 676cdf0e10cSrcweir for( ;; ) 677cdf0e10cSrcweir { 678cdf0e10cSrcweir Next(); 679cdf0e10cSrcweir if( IsEof() ) 680cdf0e10cSrcweir break; 681cdf0e10cSrcweir SbTextPortion aRes; 682cdf0e10cSrcweir aRes.nLine = nLine; 683cdf0e10cSrcweir aRes.nStart = nCol1; 684cdf0e10cSrcweir aRes.nEnd = nCol2; 685cdf0e10cSrcweir switch( eCurTok ) 686cdf0e10cSrcweir { 687cdf0e10cSrcweir case REM: 688cdf0e10cSrcweir aRes.eType = SB_COMMENT; break; 689cdf0e10cSrcweir case SYMBOL: 690cdf0e10cSrcweir aRes.eType = SB_SYMBOL; break; 691cdf0e10cSrcweir case FIXSTRING: 692cdf0e10cSrcweir aRes.eType = SB_STRING; break; 693cdf0e10cSrcweir case NUMBER: 694cdf0e10cSrcweir aRes.eType = SB_NUMBER; break; 695cdf0e10cSrcweir default: 696cdf0e10cSrcweir if( ( eCurTok >= FIRSTKWD && eCurTok <= LASTKWD ) 697cdf0e10cSrcweir || (eCurTok >= _CDECL_ ) ) 698cdf0e10cSrcweir aRes.eType = SB_KEYWORD; 699cdf0e10cSrcweir else 700cdf0e10cSrcweir aRes.eType = SB_PUNCTUATION; 701cdf0e10cSrcweir } 702cdf0e10cSrcweir // Die Folge xxx.Keyword sollte nicht als Kwd geflagt werden 703cdf0e10cSrcweir if( aRes.eType == SB_KEYWORD 704cdf0e10cSrcweir && ( eLastTok == DOT|| eLastTok == EXCLAM ) ) 705cdf0e10cSrcweir aRes.eType = SB_SYMBOL; 706cdf0e10cSrcweir if( eCurTok != EOLN && aRes.nStart <= aRes.nEnd ) 707cdf0e10cSrcweir rList.Insert( aRes, rList.Count() ); 708cdf0e10cSrcweir if( aRes.eType == SB_COMMENT ) 709cdf0e10cSrcweir break; 710cdf0e10cSrcweir eLastTok = eCurTok; 711cdf0e10cSrcweir } 712cdf0e10cSrcweir bUsedForHilite = sal_False; 713cdf0e10cSrcweir } 714cdf0e10cSrcweir 715