1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basic.hxx"
35 #include <tools/stream.hxx>
39 // Test, ob ein I/O-Channel angegeben wurde
41 BOOL
SbiParser::Channel( BOOL bAlways
)
47 SbiExpression
aExpr( this );
48 while( Peek() == COMMA
|| Peek() == SEMICOLON
)
55 Error( SbERR_EXPECTED
, "#" );
59 // Fuer PRINT und WRITE wird bei Objektvariablen versucht,
60 // die Default-Property anzusprechen.
64 void SbiParser::Print()
66 BOOL bChan
= Channel();
67 // Die Ausdruecke zum Drucken:
70 if( !IsEoln( Peek() ) )
72 SbiExpression
* pExpr
= new SbiExpression( this );
76 aGen
.Gen( eCurTok
== COMMA
? _PRINTF
: _BPRINT
);
78 if( eCurTok
== COMMA
|| eCurTok
== SEMICOLON
)
81 if( IsEoln( Peek() ) ) break;
85 aGen
.Gen( _PRCHAR
, '\n' );
93 // WRITE #chan, expr, ...
95 void SbiParser::Write()
97 BOOL bChan
= Channel();
98 // Die Ausdruecke zum Drucken:
101 SbiExpression
* pExpr
= new SbiExpression( this );
105 if( Peek() == COMMA
)
107 aGen
.Gen( _PRCHAR
, ',' );
109 if( IsEoln( Peek() ) ) break;
113 aGen
.Gen( _PRCHAR
, '\n' );
121 // LINE INPUT [prompt], var$
123 void SbiParser::LineInput()
126 // BOOL bChan = Channel( TRUE );
127 SbiExpression
* pExpr
= new SbiExpression( this, SbOPERAND
);
128 /* AB 15.1.96: Keinen allgemeinen Ausdruck mehr zulassen
129 SbiExpression* pExpr = new SbiExpression( this );
130 if( !pExpr->IsVariable() )
132 SbiToken eTok = Peek();
133 if( eTok == COMMA || eTok == SEMICOLON ) Next();
134 else Error( SbERR_EXPECTED, COMMA );
142 Error( SbERR_VAR_EXPECTED );
144 pExpr = new SbiExpression( this, SbOPERAND );
147 if( !pExpr
->IsVariable() )
148 Error( SbERR_VAR_EXPECTED
);
149 if( pExpr
->GetType() != SbxVARIANT
&& pExpr
->GetType() != SbxSTRING
)
150 Error( SbERR_CONVERSION
);
154 aGen
.Gen( _CHAN0
); // ResetChannel() nicht mehr in StepLINPUT()
159 void SbiParser::Input()
161 aGen
.Gen( _RESTART
);
163 // BOOL bChan = Channel( TRUE );
164 SbiExpression
* pExpr
= new SbiExpression( this, SbOPERAND
);
165 /* ALT: Jetzt keinen allgemeinen Ausdruck mehr zulassen
166 SbiExpression* pExpr = new SbiExpression( this );
172 if( !pExpr
->IsVariable() )
173 Error( SbERR_VAR_EXPECTED
);
176 if( Peek() == COMMA
)
180 pExpr
= new SbiExpression( this, SbOPERAND
);
185 aGen
.Gen( _CHAN0
); // ResetChannel() nicht mehr in StepINPUT()
188 // OPEN stringexpr FOR mode ACCCESS access mode AS Channel [Len=n]
190 void SbiParser::Open()
192 SbiExpression
aFileName( this );
200 nMode
= STREAM_READ
; nFlags
|= SBSTRM_INPUT
; break;
202 nMode
= STREAM_WRITE
| STREAM_TRUNC
; nFlags
|= SBSTRM_OUTPUT
; break;
204 nMode
= STREAM_WRITE
; nFlags
|= SBSTRM_APPEND
; break;
206 nMode
= STREAM_READ
| STREAM_WRITE
; nFlags
|= SBSTRM_RANDOM
; break;
208 nMode
= STREAM_READ
| STREAM_WRITE
; nFlags
|= SBSTRM_BINARY
; break;
210 Error( SbERR_SYNTAX
);
212 if( Peek() == ACCESS
)
216 // #27964# Nur STREAM_READ,STREAM_WRITE-Flags in nMode beeinflussen
217 nMode
&= ~(STREAM_READ
| STREAM_WRITE
); // loeschen
220 if( Peek() == WRITE
)
223 nMode
|= (STREAM_READ
| STREAM_WRITE
);
226 nMode
|= STREAM_READ
;
228 else if( eTok
== WRITE
)
229 nMode
|= STREAM_WRITE
;
231 Error( SbERR_SYNTAX
);
240 Next(); nMode
|= STREAM_SHARE_DENYNONE
; break;
250 if( Peek() == WRITE
) Next(), nMode
|= STREAM_SHARE_DENYALL
;
251 else nMode
|= STREAM_SHARE_DENYREAD
;
253 else if( eTok
== WRITE
)
254 nMode
|= STREAM_SHARE_DENYWRITE
;
256 Error( SbERR_SYNTAX
);
262 SbiExpression
* pChan
= new SbiExpression( this );
264 Error( SbERR_SYNTAX
);
265 SbiExpression
* pLen
= NULL
;
266 if( Peek() == SYMBOL
)
270 if( aLen
.EqualsIgnoreCaseAscii( "LEN" ) )
273 pLen
= new SbiExpression( this );
276 if( !pLen
) pLen
= new SbiExpression( this, 128, SbxINTEGER
);
277 // Der Stack fuer den OPEN-Befehl sieht wie folgt aus:
285 aGen
.Gen( _OPEN
, nMode
, nFlags
);
292 void SbiParser::Name()
294 SbiExpression
aExpr1( this );
296 SbiExpression
aExpr2( this );
304 void SbiParser::Close()
307 if( IsEoln( eCurTok
) )
308 aGen
.Gen( _CLOSE
, 0 );
312 SbiExpression
aExpr( this );
313 while( Peek() == COMMA
|| Peek() == SEMICOLON
)
316 aGen
.Gen( _CHANNEL
);
317 aGen
.Gen( _CLOSE
, 1 );
319 if( IsEoln( Peek() ) )