summaryrefslogtreecommitdiffstats
path: root/dcop/dcopidl/yacc.yy
blob: ed38f320fc9b92df1bfcb71a96b3ec18973b8a71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
%{
/*****************************************************************
Copyright (c) 1999 Torben Weis <weis@kde.org>
Copyright (c) 2000 Matthias Ettrich <ettrich@kde.org>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

******************************************************************/

#include <config.h>

// Workaround for a bison issue:
// bison.simple concludes from _GNU_SOURCE that stpcpy is available,
// while GNU string.h only exposes it if __USE_GNU is set.
#ifdef _GNU_SOURCE
#define __USE_GNU 1
#endif

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

#include <tqstring.h>

#define AMP_ENTITY "&amp;"
#define YYERROR_VERBOSE

extern int yylex();

// extern QString idl_lexFile;
extern int idl_line_no;
extern int function_mode;

static int dcop_area = 0;
static int dcop_signal_area = 0;

static QString in_namespace( "" );

void dcopidlInitFlex( const char *_code );

void yyerror( const char *s )
{
	qDebug( "In line %i : %s", idl_line_no, s );
        exit(1);
	//   theParser->parse_error( idl_lexFile, s, idl_line_no );
}

%}


%union
{
  long   _int;
  QString        *_str;
  unsigned short          _char;
  double _float;
}

%nonassoc T_UNIMPORTANT
%token <_char> T_CHARACTER_LITERAL
%token <_float> T_DOUBLE_LITERAL
%right <_str> T_IDENTIFIER
%token <_int> T_INTEGER_LITERAL
%token <_str> T_STRING_LITERAL
%token <_str> T_INCLUDE
%token T_CLASS
%token T_STRUCT
%token T_LEFT_CURLY_BRACKET
%token T_LEFT_PARANTHESIS
%token T_RIGHT_CURLY_BRACKET
%token T_RIGHT_PARANTHESIS
%token T_COLON
%token T_SEMICOLON
%token T_PUBLIC
%token T_PROTECTED
%token T_TRIPE_DOT
%token T_PRIVATE
%token T_VIRTUAL
%token T_CONST
%token T_INLINE
%token T_FRIEND
%token T_RETURN
%token T_SIGNAL
%token T_SLOT
%token T_TYPEDEF
%token T_PLUS
%token T_MINUS
%token T_COMMA
%right T_ASTERISK
%token T_TILDE
%token T_LESS
%token T_GREATER
%token T_AMPERSAND
%token T_EXTERN
%token T_EXTERN_C
%token T_ACCESS
%token T_ENUM
%token T_NAMESPACE
%token T_USING
%token T_UNKNOWN
%token T_TRIPLE_DOT
%token T_TRUE
%token T_FALSE
%token T_STATIC
%token T_MUTABLE
%token T_EQUAL
%token T_SCOPE
%token T_NULL
%token T_INT
%token T_ARRAY_OPEN
%token T_ARRAY_CLOSE
%token T_CHAR
%token T_DCOP
%token T_DCOP_AREA
%token T_DCOP_SIGNAL_AREA
%token T_SIGNED
%token T_UNSIGNED
%token T_LONG
%token T_SHORT
%token T_FUNOPERATOR
%token T_MISCOPERATOR
%token T_SHIFT

%type <_str> body
%type <_str> class_header
%type <_str> super_classes
%type <_str> super_class
%type <_str> super_class_name
%type <_str> typedef
%type <_str> function
%type <_str> function_header
%type <_str> param
%type <_str> type
%type <_str> type_name
%type <_str> templ_type
%type <_str> templ_type_list
%type <_str> type_list
%type <_str> params
%type <_str> int_type
%type <_int> const_qualifier
%type <_int> virtual_qualifier
%type <_str> Identifier
%type <_int> dcoptag

%%

/*1*/
main
	: includes declaration main
	  {
	  }
	| /* empty */
	;
	
includes
	: includes T_INCLUDE
          {
		printf("<INCLUDE>%s</INCLUDE>\n", $2->latin1() );
	  }
	| T_EXTERN_C T_LEFT_CURLY_BRACKET main T_RIGHT_CURLY_BRACKET
	  {
	  }
        | /* empty */
          {
          }
        ;

dcoptag
	: T_DCOP { $$ = 1; }
	| /* empty */ { $$ = 0; }
	;

declaration
	: T_CLASS Identifier class_header dcoptag body T_SEMICOLON
	  {
	 	if ($4)
			  printf("<CLASS>\n    <NAME>%s</NAME>\n%s%s</CLASS>\n", ( in_namespace + *$2 ).latin1(), $3->latin1(), $5->latin1() );
		// default C++ visibility specifier is 'private'
		dcop_area = 0;
		dcop_signal_area = 0;

	  }
	| T_CLASS T_IDENTIFIER Identifier class_header dcoptag body T_SEMICOLON
	  {
	 	if ($5)
			  printf("<CLASS>\n    <NAME>%s</NAME>\n    <LINK_SCOPE>%s</LINK_SCOPE>\n%s%s</CLASS>\n", ( in_namespace + *$3 ).latin1(),$2->latin1(),  $4->latin1(), $6->latin1() );
		// default C++ visibility specifier is 'private'
		dcop_area = 0;
		dcop_signal_area = 0;

	  }
	| T_CLASS Identifier T_SEMICOLON
	  {
	  }
	| T_STRUCT Identifier T_SEMICOLON
	  {
	  }
	| T_STRUCT Identifier class_header body T_SEMICOLON
	  {
	  }
	| T_NAMESPACE T_IDENTIFIER T_LEFT_CURLY_BRACKET
                  {
                      in_namespace += *$2; in_namespace += "::";
                  } 
            main T_RIGHT_CURLY_BRACKET opt_semicolon
                  {
                      int pos = in_namespace.findRev( "::", -3 );
                      if( pos >= 0 )
                          in_namespace = in_namespace.left( pos + 2 );
                      else
                          in_namespace = "";
                  }
        | T_USING T_NAMESPACE T_IDENTIFIER T_SEMICOLON
          {
          }
        | T_USING T_IDENTIFIER T_SCOPE T_IDENTIFIER T_SEMICOLON
          {
          }
	| T_EXTERN T_SEMICOLON
	  {
	  }
	| T_TYPEDEF type Identifier T_SEMICOLON
	  {
	  }
	| T_TYPEDEF T_STRUCT T_LEFT_CURLY_BRACKET member_list T_RIGHT_CURLY_BRACKET Identifier T_SEMICOLON
	  {
	  }
	| T_TYPEDEF T_STRUCT Identifier T_LEFT_CURLY_BRACKET member_list T_RIGHT_CURLY_BRACKET Identifier T_SEMICOLON
	  {
	  }
	| T_INLINE function
	  {
	  }
	| function
	  {
	  }
	| member
	  {
	  }
	| enum
	  {
	  }
	;

member_list
	: member member_list
	| /* empty */
	;

bool_value: T_TRUE | T_FALSE;

nodcop_area: T_PRIVATE | T_PROTECTED | T_PUBLIC ;

sigslot: T_SIGNAL | T_SLOT | ;

nodcop_area_begin
	: nodcop_area sigslot T_COLON
        {
	  dcop_area = 0;
	  dcop_signal_area = 0;
	}
	| sigslot T_COLON
	{
	  dcop_area = 0;
	  dcop_signal_area = 0;
	}
	;

dcop_area_begin
	: T_DCOP_AREA T_COLON
	{
	  dcop_area = 1;
	  dcop_signal_area = 0;
	}
	;

dcop_signal_area_begin
	: T_DCOP_SIGNAL_AREA T_COLON
	{
	  /*
	  A dcop signals area needs all dcop area capabilities,
	  e.g. parsing of function parameters.
	  */
	  dcop_area = 1;
	  dcop_signal_area = 1;
	}
	;
	
Identifier
	: T_IDENTIFIER %prec T_UNIMPORTANT {
	  $$ = $1;
	}
	| T_IDENTIFIER T_SCOPE Identifier {
	   QString* tmp = new QString( "%1::%2" );
           *tmp = tmp->arg(*($1)).arg(*($3));
           $$ = tmp;
	}
	;
		
super_class_name
	: Identifier
	  {
		QString* tmp = new QString( "    <SUPER>%1</SUPER>\n" );
		*tmp = tmp->arg( *($1) );
		$$ = tmp;
	  }
	| Identifier T_LESS type_list T_GREATER
	  {
		QString* tmp = new QString( "    <SUPER>%1</SUPER>\n" );
		*tmp = tmp->arg( *($1) + "&lt;" + *($3) + "&gt;" );
		$$ = tmp;
	  }
	;

super_class
	: virtual_qualifier T_PUBLIC super_class_name
	  {
		$$ = $3;
	  }
	| super_class_name
	  {
		$$ = $1;
	  }
	;

super_classes
	: super_class T_LEFT_CURLY_BRACKET
	  {
		$$ = $1;
	  }
	| super_class T_COMMA super_classes
	  {
		/* $$ = $1; */
		$$ = new QString( *($1) + *($3) );
	  }
	;

class_header
	: T_COLON super_classes
	  {
		$$ = $2;
	  }
	| T_LEFT_CURLY_BRACKET
	  {
		$$ = new QString( "" );
	  }
	;

opt_semicolon
        : /* empty */
          {
          }
        | T_SEMICOLON
	  ;

body
	: T_RIGHT_CURLY_BRACKET
	  {
		$$ = new QString( "" );
	  }
	| typedef body
	  {
		$$ = new QString( *($1) + *($2) );
	  }
	| T_INLINE function body
	  {
		$$ = new QString( *($2) + *($3) );
	  }
	| function body
	  {
		$$ = new QString( *($1) + *($2) );
	  }
	| dcop_signal_area_begin body
	  {
		$$ = $2;
	  }
	| enum body
	  {
		$$ = $2;
	  }
	| dcop_area_begin body
	  {
		$$ = $2;
	  }
	| nodcop_area_begin body
	  {	
	        $$ = $2;
	  }
	| member body
	  {
 	        $$ = $2;
	  }
	| T_FRIEND T_CLASS Identifier T_SEMICOLON body
	  {
		$$ = $5;
	  }
	| T_FRIEND Identifier T_SEMICOLON body
	  {
		$$ = $4;
	  }
	| T_FRIEND function_header T_SEMICOLON body
	  {
		$$ = $4;
	  }
	| T_CLASS Identifier T_SEMICOLON body
	  {
		$$ = $4;
	  }
        | T_CLASS Identifier class_header body T_SEMICOLON body
          {
                $$ = $6;
          }
	| T_STRUCT Identifier T_SEMICOLON body
	  {
		$$ = $4;
	  }
        | T_STRUCT Identifier class_header body T_SEMICOLON body
          {
                $$ = $6;
          }
        | T_USING T_IDENTIFIER T_SCOPE T_IDENTIFIER T_SEMICOLON body
          {
                $$ = $6;
          }
	;

enum
	: T_ENUM T_IDENTIFIER T_LEFT_CURLY_BRACKET enum_list T_RIGHT_CURLY_BRACKET T_IDENTIFIER T_SEMICOLON
	| T_ENUM T_IDENTIFIER T_LEFT_CURLY_BRACKET enum_list T_RIGHT_CURLY_BRACKET T_SEMICOLON
	| T_ENUM T_LEFT_CURLY_BRACKET enum_list T_RIGHT_CURLY_BRACKET T_IDENTIFIER T_SEMICOLON
	| T_ENUM T_LEFT_CURLY_BRACKET enum_list T_RIGHT_CURLY_BRACKET T_SEMICOLON
	;

enum_list
	: enum_item T_COMMA enum_list
	| enum_item
	;

enum_item
	: T_IDENTIFIER T_EQUAL int_expression {}
	| T_IDENTIFIER {}
	;

number
	: T_CHARACTER_LITERAL {}
	| T_INTEGER_LITERAL {}
	| T_MINUS T_INTEGER_LITERAL {}
	| T_NULL {}
	| Identifier {}
	;
	
int_expression
	: number {}
	| number T_PLUS number {}
	| number T_SHIFT number {}
	;

typedef
	: T_TYPEDEF Identifier T_LESS type_list T_GREATER Identifier T_SEMICOLON
	  {
		if (dcop_area) {
 		  QString* tmp = new QString("<TYPEDEF name=\"%1\" template=\"%2\"><PARAM %3</TYPEDEF>\n");
		  *tmp = tmp->arg( *($6) ).arg( *($2) ).arg( *($4) );
		  $$ = tmp;
		} else {
		  $$ = new QString("");
		}
	  }
	| T_TYPEDEF Identifier T_LESS type_list T_GREATER T_SCOPE T_IDENTIFIER Identifier T_SEMICOLON
	  {
		if (dcop_area)
		  yyerror("scoped template typedefs are not supported in dcop areas!");
	  }
	;

const_qualifier
	: /* empty */
	  {
		$$ = 0;
	  }
	| T_CONST
	  {
		$$ = 1;
	  }
	;

int_type
	: T_SIGNED { $$ = new QString("signed int"); }
	| T_SIGNED T_INT { $$ = new QString("signed int"); }
	| T_UNSIGNED { $$ = new QString("unsigned int"); }
	| T_UNSIGNED T_INT { $$ = new QString("unsigned int"); }
	| T_SIGNED T_SHORT { $$ = new QString("signed short int"); }
	| T_SIGNED T_SHORT T_INT { $$ = new QString("signed short int"); }
	| T_SIGNED T_LONG { $$ = new QString("signed long int"); }
	| T_SIGNED T_LONG T_INT { $$ = new QString("signed long int"); }
	| T_UNSIGNED T_SHORT { $$ = new QString("unsigned short int"); }
	| T_UNSIGNED T_SHORT T_INT { $$ = new QString("unsigned short int"); }
	| T_UNSIGNED T_LONG { $$ = new QString("unsigned long int"); }
	| T_UNSIGNED T_LONG T_INT { $$ = new QString("unsigned long int"); }
	| T_INT { $$ = new QString("int"); }
	| T_LONG { $$ = new QString("long int"); }
	| T_LONG T_INT { $$ = new QString("long int"); }
	| T_SHORT { $$ = new QString("short int"); }
	| T_SHORT T_INT { $$ = new QString("short int"); }
	| T_CHAR { $$ = new QString("char"); }
	| T_SIGNED T_CHAR { $$ = new QString("signed char"); }
	| T_UNSIGNED T_CHAR { $$ = new QString("unsigned char"); }
	;

asterisks
	: T_ASTERISK asterisks
	| T_ASTERISK
	;

params
	: /* empty */
	  {
		$$ = new QString( "" );
	  }
	| param
	| params T_COMMA param
	  {
		$$ = new QString( *($1) + *($3) );
	  }
	;

/* Lowlevel definition of a type - doesn't include const, * nor & */
type_name
	: int_type
	| Identifier { $$ = $1; }
	| T_STRUCT Identifier { $$ = $2; }
	| T_CLASS Identifier { $$ = $2; }
	| Identifier T_LESS templ_type_list T_GREATER {
		QString *tmp = new QString("%1&lt;%2&gt;");
		*tmp = tmp->arg(*($1));
		*tmp = tmp->arg(*($3));
		$$ = tmp;
	 }
	| Identifier T_LESS templ_type_list T_GREATER T_SCOPE Identifier{
		QString *tmp = new QString("%1&lt;%2&gt;::%3");
		*tmp = tmp->arg(*($1));
		*tmp = tmp->arg(*($3));
		*tmp = tmp->arg(*($6));
		$$ = tmp;
	 }
	;

/* List of types inside a template def like QMap< blah, blah > */
templ_type_list
	: templ_type T_COMMA templ_type_list
	  {
	    $$ = new QString(*($1) + "," + *($3));
	  }
	| templ_type
  	  {
 	    $$ = $1;
	  }
	;

/* One type inside a template. No '&' or const here. */
templ_type
	: type_name asterisks
  	  {
	    if (dcop_area)
	      yyerror("in dcop areas are no pointers allowed");
	  }
	| type_name
  	  {
 	    $$ = $1;
	  }
	;

/* The hi-level, complete definition of a type, which also generates
   the <TYPE> tag for it */
type
	: T_CONST type_name asterisks
  	  {
	    if (dcop_area)
	      yyerror("in dcop areas are no pointers allowed");
	  }
	| T_CONST type_name T_AMPERSAND {
	     if (dcop_area) {
	  	QString* tmp = new QString("<TYPE  qleft=\"const\" qright=\"" AMP_ENTITY "\">%1</TYPE>");
		*tmp = tmp->arg( *($2) );
		$$ = tmp;
	     }
	  }
	| T_CONST type_name %prec T_UNIMPORTANT {
		QString* tmp = new QString("<TYPE>%1</TYPE>");
		*tmp = tmp->arg( *($2) );
		$$ = tmp;
	}
    | type_name T_CONST %prec T_UNIMPORTANT {
        QString* tmp = new QString("<TYPE>%1</TYPE>");
        *tmp = tmp->arg( *($1) );
        $$ = tmp;
    }
    | type_name T_CONST T_AMPERSAND { 
        if (dcop_area) { 
           QString* tmp = new QString("<TYPE  qleft=\"const\" qright=\"" AMP_ENTITY "\">%1</TYPE>"); 
           *tmp = tmp->arg( *($1) ); 
           $$ = tmp; 
        } 
    } 
	| type_name T_AMPERSAND {
	     if (dcop_area)
		yyerror("in dcop areas are only const references allowed!");
	  }

	| type_name %prec T_UNIMPORTANT {
		QString* tmp = new QString("<TYPE>%1</TYPE>");
		*tmp = tmp->arg( *($1) );
		$$ = tmp;
	}
	| type_name asterisks
  	  {
	    if (dcop_area)
	      yyerror("in dcop areas are no pointers allowed");
	  }
	;

type_list
	: type T_COMMA type_list
	  {
	    $$ = new QString(*($1) + "," + *($3));
	  }
	| type
  	  {
 	    $$ = $1;
	  }
	;
	
param
	: type Identifier default
	  {
		if (dcop_area) {
		   QString* tmp = new QString("\n        <ARG>%1<NAME>%2</NAME></ARG>");
  		   *tmp = tmp->arg( *($1) );
  		   *tmp = tmp->arg( *($2) );
		   $$ = tmp;		
		} else $$ = new QString();
	  }
	| type default
	  {
		if (dcop_area) {
		   QString* tmp = new QString("\n        <ARG>%1</ARG>");
  		   *tmp = tmp->arg( *($1) );
		   $$ = tmp;		
		} else $$ = new QString();
	  }
	| T_TRIPLE_DOT
	  {
		if (dcop_area)
			yyerror("variable arguments not supported in dcop area.");
		$$ = new QString("");
	  }
	;

default
	: /* empty */
	  {
	  }
	| T_EQUAL value
	  {
	  }
	| T_EQUAL T_LEFT_PARANTHESIS type T_RIGHT_PARANTHESIS value /* cast */
	  {
	  }
	;

/* Literal or calculated value, used for an initialization */
value
	: T_STRING_LITERAL
          {
          }
        | int_expression
          {
          }
        | T_DOUBLE_LITERAL
          {
          }
        | bool_value
          {
          }
        | Identifier T_LEFT_PARANTHESIS params T_RIGHT_PARANTHESIS
          {
          }
        ;

virtual_qualifier
	: /* empty */ { $$ = 0; }
	| T_VIRTUAL { $$ = 1; }
	;

operator
	: T_MISCOPERATOR | T_SHIFT | T_GREATER | T_LESS | T_EQUAL
	;

function_header
	: type Identifier T_LEFT_PARANTHESIS params T_RIGHT_PARANTHESIS const_qualifier
	  {
	     if (dcop_area || dcop_signal_area) {
		QString* tmp = 0;
                tmp = new QString(
                        "    <%4>\n"
                        "        %2\n"
                        "        <NAME>%1</NAME>"
                        "%3\n"
                        "     </%5>\n");
		*tmp = tmp->arg( *($2) );
		*tmp = tmp->arg( *($1) );
                *tmp = tmp->arg( *($4) );
                
                QString tagname = (dcop_signal_area) ? "SIGNAL" : "FUNC";
                QString attr = ($6) ? " qual=\"const\"" : "";
                *tmp = tmp->arg( QString("%1%2").arg(tagname).arg(attr) );
                *tmp = tmp->arg( QString("%1").arg(tagname) );
		$$ = tmp;
   	     } else
	        $$ = new QString("");
	  }
	| type T_FUNOPERATOR operator T_LEFT_PARANTHESIS params T_RIGHT_PARANTHESIS const_qualifier
	  {
	     if (dcop_area)
		yyerror("operators aren't allowed in dcop areas!");
	     $$ = new QString("");
	  }
	;

/* In an inline constructor:
   List of values used as initialization for member var, or as params to parent constructor */
values
	: value {}
	| value T_COMMA values {}
	| /* empty */ {}
	;
	
/* One initialization done by an inline constructor */
init_item
	: T_IDENTIFIER T_LEFT_PARANTHESIS values T_RIGHT_PARANTHESIS {}
	;

/* List of initializations done by an inline constructor */
init_list
	: init_item {}
	| init_item T_COMMA init_list {}
	;

function
	: function_header function_body
 	  {
	        $$ = $1;
	  }
	| T_VIRTUAL function_header T_EQUAL T_NULL function_body
	  {
		$$ = $2;
	  }
	| T_VIRTUAL function_header function_body
	  {
		$$ = $2;
	  }
	| Identifier T_LEFT_PARANTHESIS params T_RIGHT_PARANTHESIS function_body
	  {
	      /* The constructor */
	      assert(!dcop_area);
              $$ = new QString("");
	  }
	| Identifier T_LEFT_PARANTHESIS params T_RIGHT_PARANTHESIS T_COLON init_list function_body
	  {
	      /* The constructor */
	      assert(!dcop_area);
              $$ = new QString("");
	  }
	| virtual_qualifier T_TILDE Identifier T_LEFT_PARANTHESIS T_RIGHT_PARANTHESIS function_body
	  {
	      /* The destructor */
  	      assert(!dcop_area);
              $$ = new QString("");
	  }
	| T_STATIC function_header function_body
	  {
              if (dcop_area) {
                 if (dcop_signal_area)
                     yyerror("DCOP signals cannot be static");
                 else
                     yyerror("DCOP functions cannot be static");
              } else {
                 $$ = new QString();
              }  
	  }      
	;

function_begin : T_LEFT_CURLY_BRACKET
	{
		function_mode = 1;
	}
	;
	
function_body
	: T_SEMICOLON
	| function_begin function_lines T_RIGHT_CURLY_BRACKET
	| function_begin function_lines T_RIGHT_CURLY_BRACKET T_SEMICOLON
	;

function_lines
	: function_line function_lines {}
	| /* empty */ {}
	;

function_line
	: T_SEMICOLON /* dummy */
	;

Identifier_list_rest
	: T_COMMA Identifier_list
	| /* empty */
	;

Identifier_list_entry : T_IDENTIFIER {}
                      | T_IDENTIFIER T_EQUAL value {}
                      | asterisks T_IDENTIFIER {}
	;

Identifier_list : Identifier_list_entry Identifier_list_rest {}
	;

member
	: type Identifier_list T_SEMICOLON {}
	| type Identifier T_COLON T_INTEGER_LITERAL T_SEMICOLON {}
	| T_STATIC type T_IDENTIFIER default T_SEMICOLON {}
	| T_MUTABLE type T_IDENTIFIER default T_SEMICOLON {}
	| type T_IDENTIFIER T_ARRAY_OPEN int_expression T_ARRAY_CLOSE T_SEMICOLON {}
	| T_STATIC type T_IDENTIFIER T_ARRAY_OPEN int_expression T_ARRAY_CLOSE T_SEMICOLON {}
	;

%%

void dcopidlParse( const char *_code )
{
    dcopidlInitFlex( _code );
    yyparse();
}