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