xref: /trunk/main/basic/source/inc/parser.hxx (revision 7a7771fb4d20b857459c676939e2cc2f4dec9635) !
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _PARSER_HXX
25 #define _PARSER_HXX
26 
27 #include "expr.hxx"
28 #include "codegen.hxx"
29 #include "symtbl.hxx"
30 
31 
32 #include <vector>
33 #include <map>
34 typedef ::std::vector< String > StringVector;
35 
36 struct SbiParseStack;
37 
38 class SbiParser : public SbiTokenizer
39 {
40     friend class SbiExpression;
41 
42     SbiParseStack* pStack;          // Block-Stack
43     SbiProcDef* pProc;              // aktuelle Prozedur
44     SbiExprNode*  pWithVar;         // aktuelle With-Variable
45     SbiToken    eEndTok;            // das Ende-Token
46     sal_uInt32      nGblChain;          // Chainkette fuer globale DIMs
47     sal_Bool        bGblDefs;           // sal_True globale Definitionen allgemein
48     sal_Bool        bNewGblDefs;        // sal_True globale Definitionen vor Sub
49     sal_Bool        bSingleLineIf;      // sal_True einzeiliges if-Statement
50 
51     SbiSymDef*  VarDecl( SbiDimList**,sal_Bool,sal_Bool );// Variablen-Deklaration
52     SbiProcDef* ProcDecl(sal_Bool bDecl);// Prozedur-Deklaration
53     void DefStatic( sal_Bool bPrivate );
54     void DefProc( sal_Bool bStatic, sal_Bool bPrivate ); // Prozedur einlesen
55     void DefVar( SbiOpcode eOp, sal_Bool bStatic ); // DIM/REDIM einlesen
56     void TypeDecl( SbiSymDef&, sal_Bool bAsNewAlreadyParsed=sal_False );    // AS-Deklaration
57     void OpenBlock( SbiToken, SbiExprNode* = NULL );    // Block oeffnen
58     void CloseBlock();              // Block aufloesen
59     sal_Bool Channel( sal_Bool=sal_False );     // Kanalnummer parsen
60     void StmntBlock( SbiToken );    // Statement-Block abarbeiten
61     void DefType( sal_Bool bPrivate );  // Parse type declaration
62     void DefEnum( sal_Bool bPrivate );  // Parse enum declaration
63     void DefDeclare( sal_Bool bPrivate );
64     void EnableCompatibility();
65 public:
66     SbxArrayRef   rTypeArray;       // das Type-Array
67     SbxArrayRef   rEnumArray;       // Enum types
68     SbiStringPool aGblStrings;      // der String-Pool
69     SbiStringPool aLclStrings;      // der String-Pool
70     SbiSymPool    aGlobals;         // globale Variable
71     SbiSymPool    aPublics;         // modulglobale Variable
72     SbiSymPool    aRtlSyms;         // Runtime-Library
73     SbiCodeGen    aGen;             // Code-Generator
74     StarBASIC*    pBasic;           // StarBASIC-Instanz
75     SbiSymPool*   pPool;            // aktueller Pool
76     SbiExprType   eCurExpr;         // aktueller Expr-Typ
77     short         nBase;            // OPTION BASE-Wert
78     sal_Bool          bText;            // OPTION COMPARE TEXT
79     sal_Bool          bExplicit;        // sal_True: OPTION EXPLICIT
80     sal_Bool          bClassModule;     // sal_True: OPTION ClassModule
81     StringVector  aIfaceVector;     // Holds all interfaces implemented by a class module
82     StringVector  aRequiredTypes;   // Types used in Dim As New <type> outside subs
83     SbxDataType   eDefTypes[26];    // DEFxxx-Datentypen
84 
85     SbiParser( StarBASIC*, SbModule* );
86     sal_Bool Parse();                   // die Aktion
87     SbiExprNode* GetWithVar();      // Innerste With-Variable liefern
88 
89     // AB 31.3.1996, Symbol in Runtime-Library suchen
90     SbiSymDef* CheckRTLForSym( const String& rSym, SbxDataType eType );
91     void AddConstants( void );
92 
93     sal_Bool HasGlobalCode();           // Globaler Code definiert?
94 
95     sal_Bool TestToken( SbiToken );     // bestimmtes TOken?
96     sal_Bool TestSymbol( sal_Bool=sal_False );  // Symbol?
97     sal_Bool TestComma();               // Komma oder EOLN?
98     void TestEoln();                // EOLN?
99 
100     void Symbol( const KeywordSymbolInfo* pKeywordSymbolInfo = NULL );  // Let oder Call
101     void ErrorStmnt();              // ERROR n
102     void NotImp();                  // nicht implementiert
103     void BadBlock();                // LOOP/WEND/NEXT
104     void BadSyntax();               // Falsches SbiToken
105     void NoIf();                    // ELSE/ELSE IF ohne IF
106     void Assign();                  // LET
107     void Call();                    // CALL
108     void Close();                   // CLOSE
109     void Declare();                 // DECLARE
110     void DefXXX();                  // DEFxxx
111     void Dim();                     // DIM
112     void ReDim();                   // ReDim();
113     void Erase();                   // ERASE
114     void Exit();                    // EXIT
115     void For();                     // FOR...NEXT
116     void Goto();                    // GOTO / GOSUB
117     void If();                      // IF
118     void Implements();              // IMPLEMENTS
119     void Input();                   // INPUT, INPUT #
120     void Line();                    // LINE -> LINE INPUT [#] (#i92642)
121     void LineInput();               // LINE INPUT, LINE INPUT #
122     void LSet();                    // LSET
123     void Name();                    // NAME .. AS ..
124     void On();                      // ON ERROR/variable
125     void OnGoto();                  // ON...GOTO / GOSUB
126     void Open();                    // OPEN
127     void Option();                  // OPTION
128     void Print();                   // PRINT, PRINT #
129     void SubFunc();                 // SUB / FUNCTION
130     void Resume();                  // RESUME
131     void Return();                  // RETURN
132     void RSet();                    // RSET
133     void DoLoop();                  // DO...LOOP
134     void Select();                  // SELECT ... CASE
135     void Set();                     // SET
136     void Static();                  // STATIC
137     void Stop();                    // STOP/SYSTEM
138     void Type();                    // TYPE...AS...END TYPE
139     void Enum();                    // TYPE...END ENUM
140     void While();                   // WHILE/WEND
141     void With();                    // WITH
142     void Write();                   // WRITE
143     void PPIf();                    // #If (VBA conditional compilation)
144     void PPConst();                 // #Const (VBA conditional compilation)
145     bool evaluatePPCondition();     // Evaluate #If condition expression
146     bool evaluatePPTerm();          // Evaluate single term (no And/Or)
147     bool isVBAPredefinedConst( const String& aName, bool& bValue ); // VBA7, Mac, etc.
148     void skipStatement();               // Skip a statement without generating code
149     void skipUntilEndIf();              // Skip statements until matching #End If
150 
151     // Conditional compilation constants map
152     std::map<String, bool> maConstMap;
153     // Numeric constants (e.g. #Const VERSION = 2)
154     std::map<String, double> maConstNumMap;
155 };
156 
157 
158 
159 
160 
161 
162 #endif
163