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