xref: /AOO42X/main/basic/source/inc/parser.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 _PARSER_HXX
29*cdf0e10cSrcweir #define _PARSER_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "expr.hxx"
32*cdf0e10cSrcweir #include "codegen.hxx"
33*cdf0e10cSrcweir #include "symtbl.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <vector>
37*cdf0e10cSrcweir typedef ::std::vector< String > StringVector;
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir struct SbiParseStack;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir class SbiParser : public SbiTokenizer
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir     friend class SbiExpression;
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir     SbiParseStack* pStack;          // Block-Stack
46*cdf0e10cSrcweir     SbiProcDef* pProc;              // aktuelle Prozedur
47*cdf0e10cSrcweir     SbiExprNode*  pWithVar;         // aktuelle With-Variable
48*cdf0e10cSrcweir     SbiToken    eEndTok;            // das Ende-Token
49*cdf0e10cSrcweir     sal_uInt32      nGblChain;          // Chainkette fuer globale DIMs
50*cdf0e10cSrcweir     sal_Bool        bGblDefs;           // sal_True globale Definitionen allgemein
51*cdf0e10cSrcweir     sal_Bool        bNewGblDefs;        // sal_True globale Definitionen vor Sub
52*cdf0e10cSrcweir     sal_Bool        bSingleLineIf;      // sal_True einzeiliges if-Statement
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir     SbiSymDef*  VarDecl( SbiDimList**,sal_Bool,sal_Bool );// Variablen-Deklaration
55*cdf0e10cSrcweir     SbiProcDef* ProcDecl(sal_Bool bDecl);// Prozedur-Deklaration
56*cdf0e10cSrcweir     void DefStatic( sal_Bool bPrivate );
57*cdf0e10cSrcweir     void DefProc( sal_Bool bStatic, sal_Bool bPrivate ); // Prozedur einlesen
58*cdf0e10cSrcweir     void DefVar( SbiOpcode eOp, sal_Bool bStatic ); // DIM/REDIM einlesen
59*cdf0e10cSrcweir     void TypeDecl( SbiSymDef&, sal_Bool bAsNewAlreadyParsed=sal_False );    // AS-Deklaration
60*cdf0e10cSrcweir     void OpenBlock( SbiToken, SbiExprNode* = NULL );    // Block oeffnen
61*cdf0e10cSrcweir     void CloseBlock();              // Block aufloesen
62*cdf0e10cSrcweir     sal_Bool Channel( sal_Bool=sal_False );     // Kanalnummer parsen
63*cdf0e10cSrcweir     void StmntBlock( SbiToken );    // Statement-Block abarbeiten
64*cdf0e10cSrcweir     void DefType( sal_Bool bPrivate );  // Parse type declaration
65*cdf0e10cSrcweir     void DefEnum( sal_Bool bPrivate );  // Parse enum declaration
66*cdf0e10cSrcweir     void DefDeclare( sal_Bool bPrivate );
67*cdf0e10cSrcweir     void EnableCompatibility();
68*cdf0e10cSrcweir public:
69*cdf0e10cSrcweir     SbxArrayRef   rTypeArray;       // das Type-Array
70*cdf0e10cSrcweir     SbxArrayRef   rEnumArray;       // Enum types
71*cdf0e10cSrcweir     SbiStringPool aGblStrings;      // der String-Pool
72*cdf0e10cSrcweir     SbiStringPool aLclStrings;      // der String-Pool
73*cdf0e10cSrcweir     SbiSymPool    aGlobals;         // globale Variable
74*cdf0e10cSrcweir     SbiSymPool    aPublics;         // modulglobale Variable
75*cdf0e10cSrcweir     SbiSymPool    aRtlSyms;         // Runtime-Library
76*cdf0e10cSrcweir     SbiCodeGen    aGen;             // Code-Generator
77*cdf0e10cSrcweir     StarBASIC*    pBasic;           // StarBASIC-Instanz
78*cdf0e10cSrcweir     SbiSymPool*   pPool;            // aktueller Pool
79*cdf0e10cSrcweir     SbiExprType   eCurExpr;         // aktueller Expr-Typ
80*cdf0e10cSrcweir     short         nBase;            // OPTION BASE-Wert
81*cdf0e10cSrcweir     sal_Bool          bText;            // OPTION COMPARE TEXT
82*cdf0e10cSrcweir     sal_Bool          bExplicit;        // sal_True: OPTION EXPLICIT
83*cdf0e10cSrcweir     sal_Bool          bClassModule;     // sal_True: OPTION ClassModule
84*cdf0e10cSrcweir     StringVector  aIfaceVector;     // Holds all interfaces implemented by a class module
85*cdf0e10cSrcweir     StringVector  aRequiredTypes;   // Types used in Dim As New <type> outside subs
86*cdf0e10cSrcweir     SbxDataType   eDefTypes[26];    // DEFxxx-Datentypen
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     SbiParser( StarBASIC*, SbModule* );
89*cdf0e10cSrcweir     sal_Bool Parse();                   // die Aktion
90*cdf0e10cSrcweir     SbiExprNode* GetWithVar();      // Innerste With-Variable liefern
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     // AB 31.3.1996, Symbol in Runtime-Library suchen
93*cdf0e10cSrcweir     SbiSymDef* CheckRTLForSym( const String& rSym, SbxDataType eType );
94*cdf0e10cSrcweir     void AddConstants( void );
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir     sal_Bool HasGlobalCode();           // Globaler Code definiert?
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir     sal_Bool TestToken( SbiToken );     // bestimmtes TOken?
99*cdf0e10cSrcweir     sal_Bool TestSymbol( sal_Bool=sal_False );  // Symbol?
100*cdf0e10cSrcweir     sal_Bool TestComma();               // Komma oder EOLN?
101*cdf0e10cSrcweir     void TestEoln();                // EOLN?
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     void Symbol( const KeywordSymbolInfo* pKeywordSymbolInfo = NULL );  // Let oder Call
104*cdf0e10cSrcweir     void ErrorStmnt();              // ERROR n
105*cdf0e10cSrcweir     void NotImp();                  // nicht implementiert
106*cdf0e10cSrcweir     void BadBlock();                // LOOP/WEND/NEXT
107*cdf0e10cSrcweir     void BadSyntax();               // Falsches SbiToken
108*cdf0e10cSrcweir     void NoIf();                    // ELSE/ELSE IF ohne IF
109*cdf0e10cSrcweir     void Assign();                  // LET
110*cdf0e10cSrcweir     void Call();                    // CALL
111*cdf0e10cSrcweir     void Close();                   // CLOSE
112*cdf0e10cSrcweir     void Declare();                 // DECLARE
113*cdf0e10cSrcweir     void DefXXX();                  // DEFxxx
114*cdf0e10cSrcweir     void Dim();                     // DIM
115*cdf0e10cSrcweir     void ReDim();                   // ReDim();
116*cdf0e10cSrcweir     void Erase();                   // ERASE
117*cdf0e10cSrcweir     void Exit();                    // EXIT
118*cdf0e10cSrcweir     void For();                     // FOR...NEXT
119*cdf0e10cSrcweir     void Goto();                    // GOTO / GOSUB
120*cdf0e10cSrcweir     void If();                      // IF
121*cdf0e10cSrcweir     void Implements();              // IMPLEMENTS
122*cdf0e10cSrcweir     void Input();                   // INPUT, INPUT #
123*cdf0e10cSrcweir     void Line();                    // LINE -> LINE INPUT [#] (#i92642)
124*cdf0e10cSrcweir     void LineInput();               // LINE INPUT, LINE INPUT #
125*cdf0e10cSrcweir     void LSet();                    // LSET
126*cdf0e10cSrcweir     void Name();                    // NAME .. AS ..
127*cdf0e10cSrcweir     void On();                      // ON ERROR/variable
128*cdf0e10cSrcweir     void OnGoto();                  // ON...GOTO / GOSUB
129*cdf0e10cSrcweir     void Open();                    // OPEN
130*cdf0e10cSrcweir     void Option();                  // OPTION
131*cdf0e10cSrcweir     void Print();                   // PRINT, PRINT #
132*cdf0e10cSrcweir     void SubFunc();                 // SUB / FUNCTION
133*cdf0e10cSrcweir     void Resume();                  // RESUME
134*cdf0e10cSrcweir     void Return();                  // RETURN
135*cdf0e10cSrcweir     void RSet();                    // RSET
136*cdf0e10cSrcweir     void DoLoop();                  // DO...LOOP
137*cdf0e10cSrcweir     void Select();                  // SELECT ... CASE
138*cdf0e10cSrcweir     void Set();                     // SET
139*cdf0e10cSrcweir     void Static();                  // STATIC
140*cdf0e10cSrcweir     void Stop();                    // STOP/SYSTEM
141*cdf0e10cSrcweir     void Type();                    // TYPE...AS...END TYPE
142*cdf0e10cSrcweir     void Enum();                    // TYPE...END ENUM
143*cdf0e10cSrcweir     void While();                   // WHILE/WEND
144*cdf0e10cSrcweir     void With();                    // WITH
145*cdf0e10cSrcweir     void Write();                   // WRITE
146*cdf0e10cSrcweir };
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir #endif
154