1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _TOKEN_HXX 29*cdf0e10cSrcweir #define _TOKEN_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "scanner.hxx" 32*cdf0e10cSrcweir #ifndef _SBDEF_HXX 33*cdf0e10cSrcweir #include <basic/sbdef.hxx> 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #if defined( SHARED ) 37*cdf0e10cSrcweir #define SbiTokenSHAREDTMPUNDEF 38*cdf0e10cSrcweir #undef SHARED 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir // Der Tokenizer ist stand-alone, d.h. er kann von ueberallher verwendet 42*cdf0e10cSrcweir // werden. Eine BASIC-Instanz ist fuer Fehlermeldungen notwendig. Ohne 43*cdf0e10cSrcweir // BASIC werden die Fehler nur gezaehlt. Auch ist Basic notwendig, wenn 44*cdf0e10cSrcweir // eine erweiterte SBX-Variable zur Erkennung von Datentypen etc. verwendet 45*cdf0e10cSrcweir // werden soll. 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir enum SbiToken { 48*cdf0e10cSrcweir NIL = 0, 49*cdf0e10cSrcweir // Token zwischen 0x20 und 0x3F sind Literale: 50*cdf0e10cSrcweir LPAREN = '(', RPAREN = ')', COMMA = ',', DOT = '.', EXCLAM = '!', 51*cdf0e10cSrcweir HASH = '#', SEMICOLON = ';', 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir // Anweisungen: 54*cdf0e10cSrcweir FIRSTKWD = 0x40, 55*cdf0e10cSrcweir AS = FIRSTKWD, ALIAS, ASSIGN, 56*cdf0e10cSrcweir CALL, CASE, CLOSE, COMPARE, _CONST_, 57*cdf0e10cSrcweir DECLARE, DIM, DO, 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir // in der Reihenfolge der Datentyp-Enums! 60*cdf0e10cSrcweir DEFINT, DEFLNG, DEFSNG, DEFDBL, DEFCUR, DEFDATE, DEFSTR, DEFOBJ, 61*cdf0e10cSrcweir DEFERR, DEFBOOL, DEFVAR, 62*cdf0e10cSrcweir // in der Reihenfolge der Datentyp-Enums! 63*cdf0e10cSrcweir DATATYPE1, 64*cdf0e10cSrcweir TINTEGER = DATATYPE1, 65*cdf0e10cSrcweir TLONG, TSINGLE, TDOUBLE, TCURRENCY, TDATE, TSTRING, TOBJECT, 66*cdf0e10cSrcweir _ERROR_, TBOOLEAN, TVARIANT, TBYTE, 67*cdf0e10cSrcweir DATATYPE2 = TBYTE, 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir EACH, ELSE, ELSEIF, END, ERASE, EXIT, 70*cdf0e10cSrcweir FOR, FUNCTION, 71*cdf0e10cSrcweir GET, GLOBAL, GOSUB, GOTO, 72*cdf0e10cSrcweir IF, _IN_, INPUT, 73*cdf0e10cSrcweir LET, LINE, LINEINPUT, LOCAL, LOOP, LPRINT, LSET, 74*cdf0e10cSrcweir NAME, NEW, NEXT, 75*cdf0e10cSrcweir ON, OPEN, OPTION, IMPLEMENTS, 76*cdf0e10cSrcweir PRINT, PRIVATE, PROPERTY, PUBLIC, 77*cdf0e10cSrcweir REDIM, REM, RESUME, RETURN, RSET, 78*cdf0e10cSrcweir SELECT, SET, SHARED, STATIC, STEP, STOP, SUB, 79*cdf0e10cSrcweir TEXT, THEN, TO, TYPE, ENUM, 80*cdf0e10cSrcweir UNTIL, 81*cdf0e10cSrcweir WEND, WHILE, WITH, WRITE, 82*cdf0e10cSrcweir ENDENUM, ENDIF, ENDFUNC, ENDPROPERTY, ENDSUB, ENDTYPE, ENDSELECT, ENDWITH, 83*cdf0e10cSrcweir // Ende aller Keywords 84*cdf0e10cSrcweir LASTKWD = ENDWITH, 85*cdf0e10cSrcweir // Statement-Ende 86*cdf0e10cSrcweir EOS, EOLN, 87*cdf0e10cSrcweir // Operatoren: 88*cdf0e10cSrcweir EXPON, NEG, MUL, 89*cdf0e10cSrcweir DIV, IDIV, MOD, PLUS, MINUS, 90*cdf0e10cSrcweir EQ, NE, LT, GT, LE, GE, 91*cdf0e10cSrcweir NOT, AND, OR, XOR, EQV, 92*cdf0e10cSrcweir IMP, CAT, LIKE, IS, TYPEOF, 93*cdf0e10cSrcweir // Sonstiges: 94*cdf0e10cSrcweir FIRSTEXTRA, 95*cdf0e10cSrcweir NUMBER=FIRSTEXTRA, FIXSTRING, SYMBOL, _CDECL_, BYVAL, BYREF, 96*cdf0e10cSrcweir OUTPUT, RANDOM, APPEND, BINARY, ACCESS, 97*cdf0e10cSrcweir LOCK, READ, PRESERVE, BASE, ANY, LIB, _OPTIONAL_, 98*cdf0e10cSrcweir EXPLICIT, COMPATIBLE, CLASSMODULE, PARAMARRAY, WITHEVENTS, 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir // Ab hier kommen JavaScript-Tokens (gleiches enum, damit gleicher Typ) 101*cdf0e10cSrcweir FIRSTJAVA, 102*cdf0e10cSrcweir JS_BREAK=FIRSTJAVA, JS_CONTINUE, JS_FOR, JS_FUNCTION, JS_IF, JS_NEW, 103*cdf0e10cSrcweir JS_RETURN, JS_THIS, JS_VAR, JS_WHILE, JS_WITH, 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir // JavaScript-Operatoren 106*cdf0e10cSrcweir // _ASS_ = Assignment 107*cdf0e10cSrcweir JS_COMMA, JS_ASSIGNMENT, JS_ASS_PLUS, JS_ASS_MINUS, JS_ASS_MUL, 108*cdf0e10cSrcweir JS_ASS_DIV, JS_ASS_MOD, JS_ASS_LSHIFT, JS_ASS_RSHIFT, JS_ASS_RSHIFT_Z, 109*cdf0e10cSrcweir JS_ASS_AND, JS_ASS_XOR, JS_ASS_OR, 110*cdf0e10cSrcweir JS_COND_QUEST, JS_COND_SEL, JS_LOG_OR, JS_LOG_AND, JS_BIT_OR, 111*cdf0e10cSrcweir JS_BIT_XOR, JS_BIT_AND, JS_EQ, JS_NE, JS_LT, JS_LE, 112*cdf0e10cSrcweir JS_GT, JS_GE, JS_LSHIFT, JS_RSHIFT, JS_RSHIFT_Z, 113*cdf0e10cSrcweir JS_PLUS, JS_MINUS, JS_MUL, JS_DIV, JS_MOD, JS_LOG_NOT, JS_BIT_NOT, 114*cdf0e10cSrcweir JS_INC, JS_DEC, JS_LPAREN, JS_RPAREN, JS_LINDEX, JS_RINDEX 115*cdf0e10cSrcweir , VBASUPPORT 116*cdf0e10cSrcweir }; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir #ifdef SbiTokenSHAREDTMPUNDEF 119*cdf0e10cSrcweir #define SHARED 120*cdf0e10cSrcweir #undef SbiTokenSHAREDTMPUNDEF 121*cdf0e10cSrcweir #endif 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir // #i109076 124*cdf0e10cSrcweir class TokenLabelInfo 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir bool* m_pTokenCanBeLabelTab; 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir public: 129*cdf0e10cSrcweir TokenLabelInfo( void ); 130*cdf0e10cSrcweir TokenLabelInfo( const TokenLabelInfo& rInfo ) 131*cdf0e10cSrcweir : m_pTokenCanBeLabelTab( NULL ) 132*cdf0e10cSrcweir { (void)rInfo; } 133*cdf0e10cSrcweir ~TokenLabelInfo(); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir bool canTokenBeLabel( SbiToken eTok ) 136*cdf0e10cSrcweir { return m_pTokenCanBeLabelTab[eTok]; } 137*cdf0e10cSrcweir }; 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir class SbiTokenizer : public SbiScanner { 140*cdf0e10cSrcweir TokenLabelInfo m_aTokenLabelInfo; 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir protected: 143*cdf0e10cSrcweir SbiToken eCurTok; // aktuelles Token 144*cdf0e10cSrcweir SbiToken ePush; // Pushback-Token 145*cdf0e10cSrcweir sal_uInt16 nPLine, nPCol1, nPCol2; // Pushback-Location 146*cdf0e10cSrcweir sal_Bool bEof; // sal_True bei Dateiende 147*cdf0e10cSrcweir sal_Bool bEos; // sal_True bei Statement-Ende 148*cdf0e10cSrcweir sal_Bool bKeywords; // sal_True, falls Keywords geparst werden 149*cdf0e10cSrcweir sal_Bool bAs; // letztes Keyword war AS 150*cdf0e10cSrcweir sal_Bool bErrorIsSymbol; // Handle Error token as Symbol, not keyword 151*cdf0e10cSrcweir public: 152*cdf0e10cSrcweir SbiTokenizer( const ::rtl::OUString&, StarBASIC* = NULL ); 153*cdf0e10cSrcweir ~SbiTokenizer(); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir inline sal_Bool IsEof() { return bEof; } 156*cdf0e10cSrcweir inline sal_Bool IsEos() { return bEos; } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir void Push( SbiToken ); // Pushback eines Tokens 159*cdf0e10cSrcweir const String& Symbol( SbiToken );// Rueckumwandlung 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir SbiToken Peek(); // das naechste Token lesen 162*cdf0e10cSrcweir SbiToken Next(); // Ein Token lesen 163*cdf0e10cSrcweir sal_Bool MayBeLabel( sal_Bool= sal_False ); // Kann es ein Label sein? 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir void Hilite( SbTextPortions& ); // Syntax-Highlighting 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir void Error( SbError c ) { GenError( c ); } 168*cdf0e10cSrcweir void Error( SbError, SbiToken ); 169*cdf0e10cSrcweir void Error( SbError, const char* ); 170*cdf0e10cSrcweir void Error( SbError, String ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir void Keywords( sal_Bool b ) { bKeywords = b; } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir static sal_Bool IsEoln( SbiToken t ) 175*cdf0e10cSrcweir { return sal_Bool( t == EOS || t == EOLN || t == REM ); } 176*cdf0e10cSrcweir static sal_Bool IsKwd( SbiToken t ) 177*cdf0e10cSrcweir { return sal_Bool( t >= FIRSTKWD && t <= LASTKWD ); } 178*cdf0e10cSrcweir static sal_Bool IsExtra( SbiToken t ) 179*cdf0e10cSrcweir { return sal_Bool( t >= FIRSTEXTRA ); } 180*cdf0e10cSrcweir }; 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir #endif 184