bump product version to 4.1.6.2
[LibreOffice.git] / rsc / source / parser / rscyacc.y
blob8373ec602231e7c8af21fae0f59f79d4034d7356
1 %{
2 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 /*
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "sal/config.h"
23 #include <stdio.h>
24 #include <ctype.h>
25 #include <string.h>
27 #include <rtl/strbuf.hxx>
28 #include <tools/rc.h>
29 #include <rscerror.h>
30 #include <rsctools.hxx>
31 #include <rscclass.hxx>
32 #include <rsccont.hxx>
33 #include <rsctree.hxx>
34 #include <rscdb.hxx>
35 #include <rscdef.hxx>
36 #include <rscpar.hxx>
38 #include <rsclex.hxx>
40 ObjectStack S;
41 RscTop * pCurClass;
42 sal_uInt32 nCurMask;
43 char szErrBuf[ 100 ];
45 RSCINST GetVarInst( const RSCINST & rInst, const char * pVarName )
47 RSCINST aInst;
49 aInst = rInst.pClass->GetVariable( rInst, pHS->getID( pVarName ),
50 RSCINST() );
52 if( !aInst.pData )
53 pTC->pEH->Error( ERR_NOVARIABLENAME, rInst.pClass, RscId() );
55 return( aInst );
58 void SetNumber( const RSCINST & rInst, const char * pVarName, sal_Int32 lValue )
60 RSCINST aInst;
62 aInst = GetVarInst( rInst, pVarName );
64 if( aInst.pData ){
65 ERRTYPE aError;
66 aError = aInst.pClass->SetNumber( aInst, lValue );
68 if( aError.IsError() )
69 pTC->pEH->Error( aError, aInst.pClass, RscId() );
73 void SetConst( const RSCINST & rInst, const char * pVarName,
74 Atom nValueId, sal_Int32 nVal )
76 RSCINST aInst;
78 aInst = GetVarInst( rInst, pVarName );
79 if( aInst.pData )
81 ERRTYPE aError;
82 aError = aInst.pClass->SetConst( aInst, nValueId, nVal );
84 if( aError.IsError() )
85 pTC->pEH->Error( aError, aInst.pClass, RscId() );
89 void SetString( const RSCINST & rInst, const char * pVarName, const char * pStr )
91 RSCINST aInst;
93 aInst = GetVarInst( rInst, pVarName );
94 if( aInst.pData ){
95 ERRTYPE aError;
96 aError = aInst.pClass->SetString( aInst, pStr );
98 if( aError.IsError() )
99 pTC->pEH->Error( aError, aInst.pClass, RscId() );
103 RscId MakeRscId( RscExpType aExpType )
105 if( !aExpType.IsNothing() )
107 sal_Int32 lValue(0);
109 if( !aExpType.Evaluate( &lValue ) )
110 pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
111 if( lValue < 1 || lValue > (sal_Int32)0x7FFF )
113 pTC->pEH->Error( ERR_IDRANGE, NULL, RscId(),
114 rtl::OString::valueOf(lValue).getStr() );
117 if( aExpType.IsDefinition() )
118 return RscId( aExpType.aExp.pDef );
119 else
120 return RscId( lValue );
122 return RscId();
125 sal_Bool DoClassHeader( RSCHEADER * pHeader, sal_Bool bMember )
127 RSCINST aCopyInst;
128 RscId aName1 = MakeRscId( pHeader->nName1 );
129 RscId aName2 = MakeRscId( pHeader->nName2 );
131 if( pHeader->pRefClass )
132 aCopyInst.pClass = pHeader->pRefClass;
133 else
134 aCopyInst.pClass = pHeader->pClass;
136 if( TYPE_COPY == pHeader->nTyp )
138 ObjNode * pCopyObj = aCopyInst.pClass->GetObjNode( aName2 );
140 if( !pCopyObj )
142 rtl::OStringBuffer aMsg( pHS->getString( aCopyInst.pClass->GetId() ) );
143 aMsg.append(' ');
144 aMsg.append(aName2.GetName());
145 pTC->pEH->Error( ERR_NOCOPYOBJ, pHeader->pClass, aName1,
146 aMsg.getStr() );
148 else
149 aCopyInst.pData = pCopyObj->GetRscObj();
152 if( bMember )
154 // Angabe von Superklassen oder abgeleiteten Klassen ist jetzt erlaubt
155 if( S.Top().pClass->InHierarchy( pHeader->pClass )
156 || pHeader->pClass->InHierarchy( S.Top().pClass) )
158 if( aCopyInst.IsInst() )
160 RSCINST aTmpI( S.Top() );
161 aTmpI.pClass->Destroy( aTmpI );
162 aTmpI.pClass->Create( &aTmpI, aCopyInst );
165 else
166 pTC->pEH->Error( ERR_FALSETYPE, S.Top().pClass, aName1,
167 pHS->getString( pHeader->pClass->GetId() ).getStr() );
169 else
171 if( S.IsEmpty() )
173 if( (sal_Int32)aName1 < 256 )
174 pTC->pEH->Error( WRN_GLOBALID, pHeader->pClass, aName1 );
176 if( aCopyInst.IsInst() )
177 S.Push( pHeader->pClass->Create( NULL, aCopyInst ) );
178 else
179 S.Push( pHeader->pClass->Create( NULL, RSCINST() ) );
181 pTC->pEH->StdOut( ".", RscVerbosityVerbose );
183 if( !aName1.IsId() )
184 pTC->pEH->Error( ERR_IDEXPECTED, pHeader->pClass, aName1 );
185 else
187 ObjNode * pNode = new ObjNode( aName1, S.Top().pData,
188 pFI->GetFileIndex() );
189 if( !pHeader->pClass->PutObjNode( pNode ) )
190 pTC->pEH->Error( ERR_DOUBLEID, pHeader->pClass, aName1 );
193 else
195 RSCINST aTmpI;
196 ERRTYPE aError;
198 if( (sal_Int32)aName1 >= 256 && aName1.IsId() )
199 pTC->pEH->Error( WRN_LOCALID, pHeader->pClass, aName1 );
200 aError = S.Top().pClass->GetElement( S.Top(), aName1,
201 pHeader->pClass, aCopyInst, &aTmpI );
203 if( aError.IsWarning() )
204 pTC->pEH->Error( aError, pHeader->pClass, aName1 );
205 else if( aError.IsError() )
207 if( ERR_CONT_INVALIDTYPE == aError )
208 pTC->pEH->Error( aError, S.Top().pClass, aName1,
209 pHS->getString( pHeader->pClass->GetId() ).getStr() );
210 else
211 pTC->pEH->Error( aError, S.Top().pClass, aName1 );
212 S.Top().pClass->GetElement( S.Top(), RscId(),
213 pHeader->pClass, RSCINST(), &aTmpI );
215 if( !aTmpI.IsInst() )
216 return( sal_False );
218 S.Push( aTmpI );
221 if( TYPE_REF == pHeader->nTyp )
223 ERRTYPE aError;
225 aError = S.Top().pClass->SetRef( S.Top(), aName2 );
226 pTC->pEH->Error( aError, S.Top().pClass, aName1 );
229 return( sal_True );
232 RSCINST GetFirstTupelEle( const RSCINST & rTop )
233 { // Aufwaertskompatible, Tupel probieren
234 RSCINST aInst;
235 ERRTYPE aErr;
237 aErr = rTop.pClass->GetElement( rTop, RscId(), NULL, RSCINST(), &aInst );
238 if( !aErr.IsError() )
239 aInst = aInst.pClass->GetTupelVar( aInst, 0, RSCINST() );
240 return aInst;
243 //#define YYDEBUG 1
245 #ifdef UNX
246 #define YYMAXDEPTH 2000
247 #else
248 #define YYMAXDEPTH 800
249 #endif
251 #if defined _MSC_VER
252 #pragma warning(push, 1)
253 #pragma warning(disable:4129 4273 4701 4702)
254 #endif
255 #if HAVE_GCC_PRAGMA_DIAGNOSTIC_MODIFY
256 #pragma GCC diagnostic ignored "-Wwrite-strings"
257 #elif defined __SUNPRO_CC
258 #pragma disable_warn
259 #endif
262 /* Compilerstack */
264 %union {
265 Atom varid;
266 struct {
267 Atom hashid;
268 sal_Int32 nValue;
269 } constname;
270 RscTop * pClass;
271 RSCHEADER header;
272 struct {
273 CLASS_DATA pData;
274 RscTop * pClass;
275 } instance;
276 sal_Int32 value;
277 sal_uInt16 ushort;
278 short exp_short;
279 char * string;
280 sal_Bool svbool;
281 REF_ENUM copyref;
282 RscDefine * defineele;
283 CharSet charset;
284 RscExpType macrostruct;
287 /* Token */
288 %token <value> NUMBER
289 %token <string> SYMBOL
290 %token <defineele> RSCDEFINE
291 %token <string> STRING
292 %token <string> INCLUDE_STRING
293 %token <character> CHARACTER
294 %token <svbool> BOOLEAN
296 %token LINE
297 %token AUTO_ID
298 %token NOT
299 %token XSCALE
300 %token YSCALE
301 %token RGB
302 %token GEOMETRY
303 %token POSITION
304 %token DIMENSION
305 %token INZOOMOUTPUTSIZE
306 %token FLOATINGPOS
307 %token DEFINE
308 %token INCLUDE
309 %token MACROTARGET
310 %token DEFAULT
313 %token <pClass> CLASSNAME
314 %token <varid> VARNAME
315 %token <constname> CONSTNAME
316 %token CLASS
317 %token EXTENDABLE
318 %token WRITEIFSET
321 %type <macrostruct> macro_expression
322 %type <macrostruct> id_expression
323 %type <value> long_expression
324 %type <string> string_multiline
326 %type <pClass> type
327 %type <pClass> type_base
328 %type <header> class_header_body
329 %type <header> class_header
330 %type <header> var_header_class
331 %type <copyref> copy_ref
332 %type <ushort> type_flags
335 %left '|'
336 %left '&'
337 %left LEFTSHIFT RIGHTSHIFT
338 %left '+' '-'
339 %left '*' '/'
340 %left UNARYMINUS
341 %left UNARYPLUS
342 %left ','
343 %left '(' ')'
346 /* Grammatik */
348 %start resource_definitions
352 resource_definitions
354 | resource_definitions resource_definition
355 | MACROTARGET macro_expression
357 RscExpType aExpType;
358 sal_Int32 lValue;
360 aExpType.cType = RSCEXP_NOTHING;
361 pExp = new RscExpression( aExpType, '+', $2 );
362 if( !pExp->Evaluate( &lValue ) )
363 pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
367 resource_definition
368 : line_number
369 | '#' DEFINE SYMBOL macro_expression
371 sal_Bool bError = sal_False;
373 if( $4.IsNumber() ){
374 if( !pTC->aFileTab.NewDef( pFI->GetFileIndex(),
375 rtl::OString( $3 ),
376 $4.GetLong(), ULONG_MAX ) )
377 bError = sal_True;
379 else if( $4.IsDefinition() ){
380 RscExpType aExpType;
381 RscExpression * pExpr;
383 aExpType.cType = RSCEXP_NOTHING;
384 aExpType.SetLong( 0 );
385 aExpType.cType = RSCEXP_LONG;
386 pExpr = new RscExpression( aExpType, '+', $4 );
388 if( !pTC->aFileTab.NewDef( pFI->GetFileIndex(),
389 rtl::OString( $3 ), pExpr, ULONG_MAX ) )
390 bError = sal_True;
392 else if( $4.IsExpression() ){
393 if( !pTC->aFileTab.NewDef( pFI->GetFileIndex(),
394 rtl::OString( $3 ), $4.aExp.pExp,
395 ULONG_MAX ) )
396 bError = sal_True;
399 if( bError ){
400 pTC->pEH->Error( ERR_DECLAREDEFINE, NULL, RscId(), $3 );
403 | '#' DEFINE RSCDEFINE macro_expression
405 pTC->pEH->Error( ERR_DOUBLEDEFINE, NULL, RscId(), $3->GetName().getStr() );
407 | '#' INCLUDE STRING
410 | '#' INCLUDE INCLUDE_STRING
413 | class_definition ';'
415 #ifdef D40
416 void * pMem;
417 pMem = rtl_allocateMemory( 20000 );
418 rtl_freeMemory( pMem );
419 #endif
421 | new_class_definition_header '{' new_class_definition_body '}' ';'
422 | new_class_definition_header ';'
425 new_class_definition_header
426 : CLASS SYMBOL id_expression ':' CLASSNAME
428 sal_Int32 lType;
430 $3.Evaluate( &lType );
432 // Klasse anlegen
433 Atom nId = pHS->getID( $2 );
434 pCurClass = new RscClass( nId, lType, $5 );
435 nCurMask = 1;
436 pTC->aNmTb.Put( nId, CLASSNAME, pCurClass );
437 pTC->GetRoot()->Insert( pCurClass );
439 | CLASS CLASSNAME id_expression ':' CLASSNAME
441 pCurClass = $2;
442 nCurMask = 1;
446 new_class_definition_body
448 | property_definition ';' new_class_definition_body
451 property_definition
452 : type_flags type SYMBOL
454 // Variable anlegen
455 Atom nId = pTC->aNmTb.Put( $3, VARNAME );
456 pCurClass->SetVariable( nId, $2, NULL, $1, nCurMask );
457 nCurMask <<= 1;
459 | type_flags type VARNAME
461 pCurClass->SetVariable( $3, $2, NULL, $1, nCurMask );
462 nCurMask <<= 1;
466 type_flags
467 : type_flags EXTENDABLE
469 $$ = $1 | VAR_EXTENDABLE;
471 | type_flags WRITEIFSET
473 $$ = $1 | VAR_SVDYNAMIC;
477 $$ = 0;
481 type
482 : type_base
484 $$ = $1;
486 | type_base '[' ']'
488 if( $1 )
490 rtl::OString aTypeName = rtl::OStringBuffer(pHS->getString($1->GetId())).
491 append("[]").makeStringAndClear();
492 $$ = pTC->SearchType( pHS->getID( aTypeName.getStr(), true ) );
493 if( !$$ )
495 RscCont * pCont;
496 pCont = new RscCont( pHS->getID( aTypeName.getStr() ), RSC_NOTYPE );
497 pCont->SetTypeClass( $1 );
498 pTC->InsertType( pCont );
499 $$ = pCont;
502 else
503 $$ = NULL;
507 type_base
508 : CLASSNAME
510 $$ = $1;
512 | SYMBOL
514 RscTop * pType = pTC->SearchType( pHS->getID( $1, true ) );
515 if( !pType )
516 pTC->pEH->Error( ERR_NOTYPE, pCurClass, RscId() );
517 $$ = pType;
521 class_definition
522 : class_header class_body
524 if( TYPE_REF == $1.nTyp )
525 pTC->pEH->Error( ERR_REFNOTALLOWED, S.Top().pClass,
526 RscId( $1.nName1 ) );
527 S.Pop();
529 | class_header
531 ERRTYPE aError;
532 RscId aRscId( $1.nName1 );
534 if( TYPE_NOTHING == $1.nTyp && aRscId.IsId() )
535 aError = S.Top().pClass->SetRef( S.Top(), aRscId );
536 else if( TYPE_COPY == $1.nTyp )
537 aError = ERR_COPYNOTALLOWED;
538 if( aError.IsError() || aError.IsWarning() )
539 pTC->pEH->Error( aError, S.Top().pClass, aRscId );
540 S.Pop();
544 class_header
545 : class_header_body
547 if( !DoClassHeader( &$1, sal_False ) )
548 return( ERR_ERROR );
549 $$ = $1;
553 copy_ref
554 : '<'
556 $$ = TYPE_COPY;
558 | ','
560 $$ = TYPE_REF;
564 class_header_body
565 : CLASSNAME id_expression copy_ref CLASSNAME id_expression
567 $$.pClass = $1;
568 $$.nName1 = $2;
569 $$.nTyp = $3;
570 $$.pRefClass = $4;
571 $$.nName2 = $5;
573 | CLASSNAME id_expression copy_ref id_expression
575 $$.pClass = $1;
576 $$.nName1 = $2;
577 $$.nTyp = $3;
578 $$.pRefClass = NULL;
579 $$.nName2 = $4;
581 | CLASSNAME id_expression
583 $$.pClass = $1;
584 $$.nName1 = $2;
585 $$.nTyp = TYPE_NOTHING;
586 $$.pRefClass = NULL;
587 $$.nName2.cType = RSCEXP_NOTHING;
589 | CLASSNAME copy_ref id_expression
591 $$.pClass = $1;
592 $$.nName1.cType = RSCEXP_NOTHING;
593 $$.nTyp = $2;
594 $$.pRefClass = NULL;
595 $$.nName2 = $3;
597 | CLASSNAME copy_ref CLASSNAME id_expression
599 $$.pClass = $1;
600 $$.nName1.cType = RSCEXP_NOTHING;
601 $$.nTyp = $2;
602 $$.pRefClass = $3;
603 $$.nName2 = $4;
605 | CLASSNAME
607 $$.pClass = $1;
608 $$.nName1.cType = RSCEXP_NOTHING;
609 $$.nTyp = TYPE_NOTHING;
610 $$.nName2.cType = RSCEXP_NOTHING;
614 class_body
615 : '{' var_definitions '}'
616 | '{' '}'
617 | string_multiline
619 SetString( S.Top(), "TEXT", $1 );
623 var_definitions
624 : var_definition
625 | var_definitions var_definition
628 xy_mapmode
629 : CONSTNAME
631 SetConst( S.Top(), "_XYMAPMODE", $1.hashid, $1.nValue );
636 wh_mapmode
637 : CONSTNAME
639 SetConst( S.Top(), "_WHMAPMODE", $1.hashid, $1.nValue );
644 xywh_mapmode
645 : CONSTNAME
647 SetConst( S.Top(), "_XYMAPMODE", $1.hashid, $1.nValue );
648 SetConst( S.Top(), "_WHMAPMODE", $1.hashid, $1.nValue );
653 var_definition
654 : line_number
655 | var_header var_body ';'
657 S.Pop();
659 | class_definition ';'
660 | var_header_class class_body ';'
662 if( TYPE_REF == $1.nTyp )
663 pTC->pEH->Error( ERR_REFNOTALLOWED, S.Top().pClass,
664 RscId( $1.nName1 ) );
666 if( S.Top().pClass->GetCount( S.Top() ) )
667 pTC->pEH->Error( WRN_SUBINMEMBER, S.Top().pClass,
668 RscId( $1.nName1 ) );
670 S.Pop();
672 | var_header_class ';'
674 ERRTYPE aError;
675 RscId aRscId( $1.nName1 );
677 if( TYPE_NOTHING == $1.nTyp && aRscId.IsId() )
678 aError = S.Top().pClass->SetRef( S.Top(), aRscId );
679 else if( TYPE_COPY == $1.nTyp )
680 aError = ERR_COPYNOTALLOWED;
681 if( S.Top().pClass->GetCount( S.Top() ) )
682 aError = WRN_SUBINMEMBER;
683 if( aError.IsError() || aError.IsWarning() )
684 pTC->pEH->Error( aError, S.Top().pClass, aRscId );
686 S.Pop();
688 | XSCALE '=' '(' long_expression ',' long_expression ')' ';'
690 SetNumber( S.Top(), "_XNUMERATOR", $4 );
691 SetNumber( S.Top(), "_XDENOMINATOR", $6 );
693 | YSCALE '=' '(' long_expression ',' long_expression ')' ';'
695 SetNumber( S.Top(), "_YNUMERATOR", $4 );
696 SetNumber( S.Top(), "_YDENOMINATOR", $6 );
698 | RGB '=' '(' long_expression ',' long_expression
699 ',' long_expression ')' ';'
701 SetNumber( S.Top(), "RED", $4 );
702 SetNumber( S.Top(), "GREEN", $6 );
703 SetNumber( S.Top(), "BLUE", $8 );
705 | GEOMETRY '=' xywh_mapmode '(' long_expression ',' long_expression ','
706 long_expression ',' long_expression ')' ';'
708 SetNumber( S.Top(), "_X", $5 );
709 SetNumber( S.Top(), "_Y", $7 );
710 SetNumber( S.Top(), "_WIDTH", $9 );
711 SetNumber( S.Top(), "_HEIGHT", $11 );
713 | POSITION '=' xy_mapmode '(' long_expression ',' long_expression
714 ')' ';'
716 SetNumber( S.Top(), "_X", $5 );
717 SetNumber( S.Top(), "_Y", $7 );
719 | DIMENSION '=' wh_mapmode '(' long_expression ',' long_expression
720 ')' ';'
722 SetNumber( S.Top(), "_WIDTH", $5 );
723 SetNumber( S.Top(), "_HEIGHT", $7 );
725 | INZOOMOUTPUTSIZE '=' CONSTNAME '(' long_expression ',' long_expression
726 ')' ';'
728 SetConst( S.Top(), "_ZOOMINMAPMODE", $3.hashid, $3.nValue );
729 SetNumber( S.Top(), "_ZOOMINWIDTH", $5 );
730 SetNumber( S.Top(), "_ZOOMINHEIGHT", $7 );
732 | INZOOMOUTPUTSIZE '=' '(' long_expression ',' long_expression ')' ';'
734 SetNumber( S.Top(), "_ZOOMINWIDTH", $4 );
735 SetNumber( S.Top(), "_ZOOMINHEIGHT", $6 );
737 | FLOATINGPOS '=' CONSTNAME '(' long_expression ',' long_expression
738 ')' ';'
740 SetConst( S.Top(), "_FLOATINGPOSMAPMODE", $3.hashid, $3.nValue );
741 SetNumber( S.Top(), "_FLOATINGPOSX", $5 );
742 SetNumber( S.Top(), "_FLOATINGPOSY", $7 );
744 | FLOATINGPOS '=' '(' long_expression ',' long_expression ')' ';'
746 SetNumber( S.Top(), "_FLOATINGPOSX", $4 );
747 SetNumber( S.Top(), "_FLOATINGPOSY", $6 );
751 var_header_class
752 : VARNAME '=' class_header_body
754 RSCINST aInst;
756 aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST(), sal_False, $3.pClass );
758 if( aInst.pData )
759 S.Push( aInst );
760 else
762 pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(),
763 pHS->getString( $1 ).getStr() );
764 return( ERR_ERROR );
767 if( !DoClassHeader( &$3, sal_True ) )
768 return( ERR_ERROR );
769 $$ = $3;
771 | VARNAME '[' CONSTNAME ']' '=' class_header_body
773 RSCINST aInst;
775 aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() );
777 if( aInst.pData )
779 ERRTYPE aError;
780 RSCINST aIdxInst;
782 aError = aInst.pClass->GetArrayEle( aInst, $3.hashid, NULL, &aIdxInst );
783 if( aError.IsError() || aError.IsWarning() )
784 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
785 if( aError.IsError() )
786 return( ERR_ERROR );
787 S.Push( aIdxInst );
789 else
791 pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(),
792 pHS->getString( $1 ).getStr() );
793 return( ERR_ERROR );
795 if( !DoClassHeader( &$6, sal_True ) )
796 return( ERR_ERROR );
797 $$ = $6;
799 | VARNAME '[' SYMBOL ']' '=' class_header_body
801 RSCINST aInst;
803 aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() );
805 if( aInst.pData )
807 long nNewLang = pTC->AddLanguage( $3 );
808 ERRTYPE aError;
809 RSCINST aIdxInst;
811 aError = aInst.pClass->GetArrayEle( aInst, nNewLang, NULL, &aIdxInst );
812 if( aError.IsError() || aError.IsWarning() )
813 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
814 if( aError.IsError() )
815 return( ERR_ERROR );
816 S.Push( aIdxInst );
818 else
820 pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(),
821 pHS->getString( $1 ).getStr() );
822 return( ERR_ERROR );
824 if( !DoClassHeader( &$6, sal_True ) )
825 return( ERR_ERROR );
826 $$ = $6;
830 var_header
831 : VARNAME '='
833 RSCINST aInst;
835 aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() );
837 if( aInst.pData )
838 S.Push( aInst );
839 else{
840 pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(),
841 pHS->getString( $1 ).getStr() );
842 return( ERR_ERROR );
845 | VARNAME '[' CONSTNAME ']' '='
847 RSCINST aInst;
849 aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() );
851 if( aInst.pData )
853 ERRTYPE aError;
854 RSCINST aIdxInst;
856 aError = aInst.pClass->GetArrayEle( aInst, $3.hashid, NULL, &aIdxInst );
857 if( aError.IsError() || aError.IsWarning() )
858 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
859 if( aError.IsError() )
860 return( ERR_ERROR );
861 S.Push( aIdxInst );
863 else{
864 pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(),
865 pHS->getString( $1 ).getStr() );
866 return( ERR_ERROR );
869 | VARNAME '[' SYMBOL ']' '='
871 RSCINST aInst;
873 aInst = S.Top().pClass->GetVariable( S.Top(), $1, RSCINST() );
875 if( aInst.pData )
877 long nNewLang = pTC->AddLanguage( $3 );
878 ERRTYPE aError;
879 RSCINST aIdxInst;
881 aError = aInst.pClass->GetArrayEle( aInst, nNewLang, NULL, &aIdxInst );
882 if( aError.IsError() || aError.IsWarning() )
883 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
884 if( aError.IsError() )
885 return( ERR_ERROR );
886 S.Push( aIdxInst );
888 else{
889 pTC->pEH->Error( ERR_NOVARIABLENAME, S.Top().pClass, RscId(),
890 pHS->getString( $1 ).getStr() );
891 return( ERR_ERROR );
895 tupel_header0
898 RSCINST aInst;
900 aInst = S.Top().pClass->GetTupelVar( S.Top(), 0, RSCINST() );
901 if( aInst.pData )
902 S.Push( aInst );
903 else
905 pTC->pEH->Error( ERR_NOTUPELNAME, S.Top().pClass, RscId() );
906 return( ERR_ERROR );
911 tupel_header1
914 RSCINST aInst;
916 aInst = S.Top().pClass->GetTupelVar( S.Top(), 1, RSCINST() );
917 if( aInst.pData )
918 S.Push( aInst );
919 else
921 pTC->pEH->Error( ERR_NOTUPELNAME, S.Top().pClass, RscId() );
922 return( ERR_ERROR );
927 tupel_header2
930 RSCINST aInst;
932 aInst = S.Top().pClass->GetTupelVar( S.Top(), 2, RSCINST() );
933 if( aInst.pData )
934 S.Push( aInst );
935 else
937 pTC->pEH->Error( ERR_NOTUPELNAME, S.Top().pClass, RscId() );
938 return( ERR_ERROR );
943 tupel_header3
946 RSCINST aInst;
948 aInst = S.Top().pClass->GetTupelVar( S.Top(), 3, RSCINST() );
949 if( !aInst.pData )
951 pTC->pEH->Error( ERR_NOTUPELNAME, S.Top().pClass, RscId() );
952 return( ERR_ERROR );
954 S.Push( aInst );
958 tupel_body
959 : var_body
961 S.Pop();
965 var_list_header
968 ERRTYPE aError;
969 RSCINST aInst;
971 aError = S.Top().pClass->GetElement( S.Top(), RscId(),
972 NULL, RSCINST(), &aInst );
973 if( aError.IsError() || aError.IsWarning() )
974 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
975 if( aError.IsError() )
976 { // unbedingt Instanz auf den Stack bringen
977 aInst = S.Top().pClass->Create( NULL, RSCINST() );
979 S.Push( aInst );
983 list_body
984 : var_bodycomplex
986 S.Pop();
990 list_header
993 sal_uInt32 nCount = S.Top().pClass->GetCount( S.Top() );
994 sal_uInt32 i;
996 for( i = nCount; i > 0; i-- )
997 S.Top().pClass->DeletePos( S.Top(), i -1 );
1001 list
1002 : list var_list_header list_body ';'
1003 | list var_bodysimple ';'
1004 | list class_definition ';'
1005 | list line_number
1009 var_bodysimple
1010 : macro_expression
1012 sal_Int32 l;
1013 ERRTYPE aError;
1015 if( !$1.Evaluate( &l ) )
1016 pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
1017 else
1019 aError = S.Top().pClass->SetRef( S.Top(), RscId( $1 ) );
1020 if( aError.IsError() )
1022 aError.Clear();
1023 aError = S.Top().pClass->SetNumber( S.Top(), l );
1025 if( aError.IsError() )
1026 { // Aufwaertskompatible, Tupel probieren
1027 RSCINST aInst = GetFirstTupelEle( S.Top() );
1028 if( aInst.pData )
1030 aError.Clear(); // Fehler zuruecksetzen
1031 aError = aInst.pClass->SetRef( aInst, RscId( $1 ) );
1032 if( aError.IsError() )
1034 aError.Clear();
1035 aError = aInst.pClass->SetNumber( aInst, l );
1041 if( $1.IsExpression() )
1042 delete $1.aExp.pExp;
1044 if( aError.IsError() || aError.IsWarning() )
1045 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
1047 | CONSTNAME
1049 ERRTYPE aError;
1050 aError = S.Top().pClass->SetConst( S.Top(), $1.hashid, $1.nValue );
1051 if( aError.IsError() )
1052 { // Aufwaertskompatible, Tupel probieren
1053 RSCINST aInst = GetFirstTupelEle( S.Top() );
1054 if( aInst.pData )
1056 aError.Clear(); // Fehler zuruecksetzen
1057 aError = aInst.pClass->SetConst( aInst, $1.hashid, $1.nValue );
1061 if( aError.IsError() || aError.IsWarning() )
1062 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
1064 | NOT CONSTNAME
1066 ERRTYPE aError;
1067 aError = S.Top().pClass->SetNotConst( S.Top(), $2.hashid );
1068 if( aError.IsError() )
1069 { // Aufwaertskompatible, Tupel probieren
1070 RSCINST aInst = GetFirstTupelEle( S.Top() );
1071 if( aInst.pData )
1073 aError.Clear(); // Fehler zuruecksetzen
1074 aError = aInst.pClass->SetNotConst( aInst, $2.hashid );
1078 if( aError.IsError() || aError.IsWarning() )
1079 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
1081 | BOOLEAN
1083 ERRTYPE aError;
1084 aError = S.Top().pClass->SetBool( S.Top(), $1 );
1085 if( aError.IsError() )
1086 { // Aufwaertskompatible, Tupel probieren
1087 RSCINST aInst = GetFirstTupelEle( S.Top() );
1088 if( aInst.pData )
1090 aError.Clear(); // Fehler zuruecksetzen
1091 aError = aInst.pClass->SetBool( aInst, $1 );
1095 if( aError.IsError() || aError.IsWarning() )
1096 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
1098 | string_multiline
1100 ERRTYPE aError;
1101 aError = S.Top().pClass->SetString( S.Top(), $1 );
1102 if( aError.IsError() )
1103 { // Aufwaertskompatible, Tupel probieren
1104 RSCINST aInst = GetFirstTupelEle( S.Top() );
1105 if( aInst.pData )
1107 aError.Clear(); // Fehler zuruecksetzen
1108 aError = aInst.pClass->SetString( aInst, $1 );
1112 if( aError.IsError() || aError.IsWarning() )
1113 pTC->pEH->Error( aError, S.Top().pClass, RscId() );
1115 | DEFAULT
1118 var_bodycomplex
1119 : '{' list_header list '}'
1120 | '<' tupel_header0 tupel_body ';' '>'
1121 | '<' tupel_header0 tupel_body ';' tupel_header1 tupel_body ';' '>'
1122 | '<' tupel_header0 tupel_body ';' tupel_header1 tupel_body ';'
1123 tupel_header2 tupel_body ';' '>'
1124 | '<' tupel_header0 tupel_body ';' tupel_header1 tupel_body ';'
1125 tupel_header2 tupel_body ';' tupel_header3 tupel_body ';' '>'
1128 var_body
1129 : var_bodysimple
1130 | var_bodycomplex
1133 string_multiline
1134 : STRING
1136 $$ = $1;
1138 | string_multiline STRING
1140 rtl::OStringBuffer aBuf( 256 );
1141 aBuf.append( $1 );
1142 aBuf.append( $2 );
1143 $$ = (char*)pStringContainer->putString( aBuf.getStr() );
1147 long_expression
1148 : macro_expression
1150 if( !$1.Evaluate( &$$ ) )
1151 pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
1152 if( $1.IsExpression() )
1153 delete $1.aExp.pExp;
1157 macro_expression
1158 : RSCDEFINE
1160 $$.cType = RSCEXP_DEF;
1161 $$.aExp.pDef = $1;
1163 | NUMBER
1165 $$.cType = RSCEXP_LONG;
1166 $$.SetLong( $1 );
1168 | '-' macro_expression %prec UNARYMINUS
1170 if( $2.IsNumber() ){
1171 $$.cType = $2.cType;
1172 $$.SetLong( - $2.GetLong() );
1174 else{
1175 RscExpType aLeftExp;
1177 aLeftExp.cType = RSCEXP_NOTHING;
1178 $$.cType = RSCEXP_EXP;
1179 $$.aExp.pExp = new RscExpression( aLeftExp, '-', $2 );
1182 | '+' macro_expression %prec UNARYPLUS
1184 $$ = $2;
1186 | macro_expression '+' macro_expression
1188 if( $1.IsNumber() && $3.IsNumber() ){
1189 $$.cType = RSCEXP_LONG;
1190 $$.SetLong( $1.GetLong() + $3.GetLong() );
1192 else{
1193 $$.cType = RSCEXP_EXP;
1194 $$.aExp.pExp = new RscExpression( $1, '+', $3 );
1197 | macro_expression '-' macro_expression
1199 if( $1.IsNumber() && $3.IsNumber() ){
1200 $$.cType = RSCEXP_LONG;
1201 $$.SetLong( $1.GetLong() - $3.GetLong() );
1203 else{
1204 $$.cType = RSCEXP_EXP;
1205 $$.aExp.pExp = new RscExpression( $1, '-', $3 );
1208 | macro_expression '*' macro_expression
1210 if( $1.IsNumber() && $3.IsNumber() ){
1211 $$.cType = RSCEXP_LONG;
1212 $$.SetLong( $1.GetLong() * $3.GetLong() );
1214 else{
1215 $$.cType = RSCEXP_EXP;
1216 $$.aExp.pExp = new RscExpression( $1, '*', $3 );
1219 | macro_expression '/' macro_expression
1221 if( $1.IsNumber() && $3.IsNumber() ){
1222 if( 0 == $3.GetLong() ){
1223 $$.cType = RSCEXP_EXP;
1224 $$.aExp.pExp = new RscExpression( $1, '/', $3 );
1226 else{
1227 $$.cType = RSCEXP_LONG;
1228 $$.SetLong( $1.GetLong() / $3.GetLong() );
1231 else{
1232 $$.cType = RSCEXP_EXP;
1233 $$.aExp.pExp = new RscExpression( $1, '/', $3 );
1236 | macro_expression '&' macro_expression
1238 if( $1.IsNumber() && $3.IsNumber() ){
1239 $$.cType = RSCEXP_LONG;
1240 $$.SetLong( $1.GetLong() & $3.GetLong() );
1242 else{
1243 $$.cType = RSCEXP_EXP;
1244 $$.aExp.pExp = new RscExpression( $1, '&', $3 );
1247 | macro_expression '|' macro_expression
1249 if( $1.IsNumber() && $3.IsNumber() ){
1250 $$.cType = RSCEXP_LONG;
1251 $$.SetLong( $1.GetLong() | $3.GetLong() );
1253 else{
1254 $$.cType = RSCEXP_EXP;
1255 $$.aExp.pExp = new RscExpression( $1, '|', $3 );
1258 | '(' macro_expression ')'
1260 $$ = $2;
1262 | macro_expression LEFTSHIFT macro_expression
1264 if( $1.IsNumber() && $3.IsNumber() ){
1265 $$.cType = RSCEXP_LONG;
1266 $$.SetLong( $1.GetLong() << $3.GetLong() );
1268 else{
1269 $$.cType = RSCEXP_EXP;
1270 $$.aExp.pExp = new RscExpression( $1, 'l', $3 );
1273 | macro_expression RIGHTSHIFT macro_expression
1275 if( $1.IsNumber() && $3.IsNumber() ){
1276 $$.cType = RSCEXP_LONG;
1277 $$.SetLong( $1.GetLong() >> $3.GetLong() );
1279 else{
1280 $$.cType = RSCEXP_EXP;
1281 $$.aExp.pExp = new RscExpression( $1, 'r', $3 );
1286 id_expression
1287 : id_expression line_number
1288 | macro_expression
1289 { // pExpession auswerten und loeschen
1290 if( RSCEXP_EXP == $1.cType ){
1291 sal_Int32 lValue;
1293 if( !$1.Evaluate( &lValue ) )
1294 pTC->pEH->Error( ERR_ZERODIVISION, NULL, RscId() );
1295 delete $1.aExp.pExp;
1296 $$.cType = RSCEXP_LONG;
1297 $$.SetLong( lValue );
1299 else
1300 $$ = $1;
1304 DUMMY_NUMBER
1305 : NUMBER
1313 line_number
1314 : '#' LINE NUMBER STRING
1316 RscFile * pFName;
1318 pFI->SetLineNo( $3 );
1319 pFI->SetFileIndex( pTC->aFileTab.NewCodeFile( rtl::OString( $4 ) ) );
1320 pFName = pTC->aFileTab.Get( pFI->GetFileIndex() );
1321 pFName->bLoaded = sal_True;
1322 pFName->bScanned = sal_True;
1324 | '#' NUMBER STRING DUMMY_NUMBER
1326 RscFile * pFName;
1328 pFI->SetLineNo( $2 );
1329 pFI->SetFileIndex( pTC->aFileTab.NewCodeFile( rtl::OString( $3 ) ) );
1330 pFName = pTC->aFileTab.Get( pFI->GetFileIndex() );
1331 pFName->bLoaded = sal_True;
1332 pFName->bScanned = sal_True;
1334 | '#' NUMBER
1336 pFI->SetLineNo( $2 );
1341 #if defined _MSC_VER
1342 #pragma warning(pop)
1343 #endif
1345 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */