2 * Copyright (C) 1999 the Free Software Foundation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
31 extern char *filename;
35 static GList *class_nodes = NULL;
38 static GList *typestack = NULL;
40 static GList *funcargs = NULL;
41 static GList *checks = NULL;
42 static int has_this = FALSE;
44 static GList *gtktypes = NULL;
59 if(strcmp(yytext,"\n")==0) {
60 out=g_strconcat("Error: ",str," before newline",NULL);
61 } else if(yytext[0]=='\0') {
62 out=g_strconcat("Error: ",str," at end of input",NULL);
64 char *tmp = g_strdup(yytext);
65 while((p=strchr(tmp,'\n')))
68 out=g_strconcat("Error: ",str," before '",tmp,"'",NULL);
72 fprintf(stderr,"%s:%d: %s\n",filename,line_no,out);
79 push_variable(char *name, int scope)
82 Type *type = typestack->data;
83 typestack = g_list_remove(typestack,typestack->data);
85 var = new_variable(scope,type,name);
86 class_nodes = g_list_append(class_nodes, var);
90 push_function(int scope, char *oid, char *id, char *onerror,
91 GString *cbuf,int line_no)
96 if(scope!=INIT_METHOD && scope!=CLASS_INIT_METHOD) {
97 type = typestack->data;
98 typestack = g_list_remove(typestack,typestack->data);
100 type = (Type *)new_type(0,g_strdup("void"));
103 node = new_method(scope,type,oid,gtktypes,id,funcargs,
104 onerror,cbuf,line_no);
108 class_nodes = g_list_append(class_nodes, node);
112 push_funcarg(char *name)
115 Type *type = typestack->data;
116 typestack = g_list_remove(typestack,typestack->data);
118 node = new_funcarg(type,name,checks);
121 funcargs = g_list_append(funcargs, node);
125 push_init_arg(char *name, int is_class)
132 tn = g_strconcat(((Class *)class)->otype,":Class",NULL);
134 tn = g_strdup(((Class *)class)->otype);
136 type = new_type(1,tn);
137 node = new_funcarg((Type *)type,name,NULL);
138 funcargs = g_list_prepend(funcargs, node);
142 push_this(char *this)
147 type = new_type(1,g_strdup(((Class *)class)->otype));
148 ch = g_list_append(ch,new_check(NULL_CHECK,NULL));
149 ch = g_list_append(ch,new_check(TYPE_CHECK,NULL));
150 node = new_funcarg((Type *)type,this,ch);
151 funcargs = g_list_prepend(funcargs, node);
164 %token VOID STRUCT UNION ENUM SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
166 %token CHECK CNULL TYPE ONERROR
168 %token <id> TOKEN NUMBER TYPETOKEN
169 %token <cbuf> CCODE HCODE
170 %token <line> PUBLIC PRIVATE ARGUMENT VIRTUAL SIGNAL OVERRIDE
174 prog: ccodes class ccodes { ; }
180 ccodes: ccodes CCODE {
181 Node *node = new_ccode(FALSE,$<cbuf>2);
182 nodes = g_list_append(nodes,node);
185 Node *node = new_ccode(TRUE,$<cbuf>2);
186 nodes = g_list_append(nodes,node);
189 Node *node = new_ccode(FALSE,$<cbuf>1);
190 nodes = g_list_append(nodes,node);
193 Node *node = new_ccode(TRUE,$<cbuf>1);
194 nodes = g_list_append(nodes,node);
198 class: classdec '{' classcode '}' {
199 ((Class *)class)->nodes = class_nodes;
201 nodes = g_list_append(nodes,class);
205 classdec: CLASS TYPETOKEN FROM TYPETOKEN {
206 class = new_class($<id>2,$<id>4,NULL);
210 classcode: classcode method { ; }
211 | classcode variable { ; }
212 | classcode argument { ; }
218 variable: PUBLIC type TOKEN ';' {
219 push_variable($<id>3,PUBLIC_SCOPE);
221 | PRIVATE type TOKEN ';' {
222 push_variable($<id>3,PRIVATE_SCOPE);
225 argument: ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE TOKEN '{' CCODE ';' {
226 if(strcmp($<id>5,"get")==0 &&
227 strcmp($<id>8,"set")==0) {
229 g_free($<id>5); g_free($<id>8);
230 node = new_argument($<id>3,$<list>2,$<id>4,
232 class_nodes = g_list_append(class_nodes,node);
233 } else if(strcmp($<id>5,"set")==0 &&
234 strcmp($<id>8,"get")==0) {
236 g_free($<id>5); g_free($<id>8);
237 node = new_argument($<id>3,$<list>2,$<id>4,
239 class_nodes = g_list_append(class_nodes,node);
241 g_free($<id>3); g_free($<id>4);
242 g_free($<id>5); g_free($<id>8);
243 g_list_foreach($<list>2,(GFunc)g_free,NULL);
244 g_string_free($<cbuf>10,TRUE);
245 g_string_free($<cbuf>7,TRUE);
246 yyerror(_("parse error"));
250 | ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE ';' {
251 if(strcmp($<id>5,"get")==0) {
254 node = new_argument($<id>3,$<list>2,$<id>4,
256 class_nodes = g_list_append(class_nodes,node);
257 } else if(strcmp($<id>5,"set")==0) {
260 node = new_argument($<id>3,$<list>2,$<id>4,
262 class_nodes = g_list_append(class_nodes,node);
264 g_free($<id>5); g_free($<id>3);
266 g_list_foreach($<list>2,(GFunc)g_free,NULL);
267 g_string_free($<cbuf>7,TRUE);
268 yyerror(_("parse error"));
274 argflags: '(' flaglist ')' { $<list>$ = $<list>2; }
275 | { $<list>$ = NULL; }
278 flaglist: TOKEN '|' flaglist {
279 $<list>$ = g_list_append($<list>3,$<id>1);
282 $<list>$ = g_list_append(NULL,$<id>1);
288 Node *node = new_type(0,$<id>1);
289 typestack = g_list_prepend(typestack,node);
292 Node *node = new_type(stars,$<id>1);
294 typestack = g_list_prepend(typestack,node);
298 type1: UNSIGNED integer {
299 $<id>$ = g_strconcat("unsigned ",$<id>2,NULL);
302 $<id>$ = g_strconcat("signed ",$<id>2,NULL);
305 $<id>$ = g_strdup($<id>1);
308 $<id>$ = g_strdup("unsigned char");
311 $<id>$ = g_strdup("signed char");
314 $<id>$ = g_strdup("double");
317 $<id>$ = g_strdup("float");
323 $<id>$ = g_strconcat($<id>1,$<id>2,NULL);
330 $<id>$ = g_strdup("void");
341 $<id>$ = "short int";
362 stars: '*' stars { stars++; }
366 sigtype: TOKEN '(' tokenlist ')' {
367 gtktypes = g_list_prepend(gtktypes,$<id>1);
371 tokenlist: tokenlist ',' TOKEN {
372 gtktypes = g_list_append(gtktypes,$<id>3);
375 gtktypes = g_list_append(gtktypes,$<id>1);
379 /*here CCODE will include the ending '}' */
380 method: SIGNAL LAST sigtype type TOKEN '(' funcargs ')' onerror '{' CCODE {
382 yyerror(_("signal without 'this' as "
386 push_function(SIGNAL_LAST_METHOD,NULL,
387 $<id>5, $<id>9, $<cbuf>11,$<line>1);
389 | SIGNAL LAST sigtype type TOKEN '(' funcargs ')' onerror ';' {
391 yyerror(_("signal without 'this' as "
395 push_function(SIGNAL_LAST_METHOD, NULL,
396 $<id>5, $<id>9, NULL,$<line>1);
398 | SIGNAL FIRST sigtype type TOKEN '(' funcargs ')' onerror '{' CCODE {
400 yyerror(_("signal without 'this' as "
404 push_function(SIGNAL_FIRST_METHOD, NULL,
405 $<id>5, $<id>9, $<cbuf>11,$<line>1);
407 | SIGNAL FIRST sigtype type TOKEN '(' funcargs ')' onerror ';' {
409 yyerror(_("signal without 'this' as "
413 push_function(SIGNAL_FIRST_METHOD, NULL, $<id>5,
414 $<id>9, NULL,$<line>1);
416 | SIGNAL sigtype type TOKEN '(' funcargs ')' onerror '{' CCODE {
418 yyerror(_("signal without 'this' as "
422 push_function(SIGNAL_LAST_METHOD, NULL,
423 $<id>4, $<id>8, $<cbuf>10,$<line>1);
425 | SIGNAL sigtype type TOKEN '(' funcargs ')' onerror ';' {
427 yyerror(_("signal without 'this' as "
431 push_function(SIGNAL_LAST_METHOD, NULL, $<id>4,
432 $<id>8, NULL,$<line>1);
434 | VIRTUAL type TOKEN '(' funcargs ')' onerror '{' CCODE {
435 push_function(VIRTUAL_METHOD, NULL, $<id>3,
436 $<id>7, $<cbuf>9,$<line>1);
438 | VIRTUAL type TOKEN '(' funcargs ')' onerror ';' {
439 push_function(VIRTUAL_METHOD, NULL, $<id>3,
440 $<id>7, NULL,$<line>1);
442 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' onerror '{' CCODE {
443 push_function(OVERRIDE_METHOD, $<id>3,
444 $<id>6, $<id>10, $<cbuf>12,$<line>1);
446 | PUBLIC type TOKEN '(' funcargs ')' onerror '{' CCODE {
447 push_function(PUBLIC_SCOPE, NULL, $<id>3,
448 $<id>7, $<cbuf>9,$<line>1);
450 | PRIVATE type TOKEN '(' funcargs ')' onerror '{' CCODE {
451 push_function(PRIVATE_SCOPE, NULL, $<id>3,
452 $<id>7, $<cbuf>9,$<line>1);
454 | TOKEN '(' TOKEN ')' ';' {
455 if(strcmp($<id>1,"init")==0) {
456 push_init_arg($<id>3,FALSE);
457 push_function(INIT_METHOD, NULL, $<id>1,
458 NULL, NULL,$<line>2);
459 } else if(strcmp($<id>1,"class_init")==0) {
460 push_init_arg($<id>3,TRUE);
461 push_function(CLASS_INIT_METHOD, NULL,
462 $<id>1, NULL, NULL,$<line>2);
466 yyerror(_("parse error"));
470 | TOKEN '(' TOKEN ')' '{' CCODE {
471 if(strcmp($<id>1,"init")==0) {
472 push_init_arg($<id>3,FALSE);
473 push_function(INIT_METHOD, NULL,
474 $<id>1, NULL, $<cbuf>6,$<line>2);
475 } else if(strcmp($<id>1,"class_init")==0) {
476 push_init_arg($<id>3,TRUE);
477 push_function(CLASS_INIT_METHOD, NULL,
478 $<id>1, NULL, $<cbuf>6,$<line>2);
482 g_string_free($<cbuf>3,TRUE);
483 yyerror(_("parse error"));
489 onerror: ONERROR TOKEN { $<id>$ = $<id>2; }
490 | ONERROR number { $<id>$ = $<id>2; }
491 | ONERROR '{' CCODE {
492 $<id>$ = ($<cbuf>3)->str;
493 g_string_free($<cbuf>3,FALSE);
501 funcargs: VOID { has_this = FALSE; }
504 if(strcmp($<id>1,"this")==0)
508 yyerror(_("parse error"));
512 | TOKEN ',' arglist {
514 if(strcmp($<id>1,"this")==0)
518 yyerror(_("parse error"));
522 | arglist { has_this = FALSE; }
525 arglist: arglist ',' arg { ; }
530 push_funcarg($<id>2);
532 | type TOKEN '(' CHECK checklist ')' {
533 push_funcarg($<id>2);
537 checklist: checklist check { ; }
542 Node *node = new_check(NULL_CHECK,NULL);
543 checks = g_list_append(checks,node);
546 Node *node = new_check(TYPE_CHECK,NULL);
547 checks = g_list_append(checks,node);
550 Node *node = new_check(GT_CHECK,$<id>2);
551 checks = g_list_append(checks,node);
554 Node *node = new_check(LT_CHECK,$<id>2);
555 checks = g_list_append(checks,node);
558 Node *node = new_check(GE_CHECK,$<id>3);
559 checks = g_list_append(checks,node);
562 Node *node = new_check(LE_CHECK,$<id>3);
563 checks = g_list_append(checks,node);
566 Node *node = new_check(EQ_CHECK,$<id>3);
567 checks = g_list_append(checks,node);
570 Node *node = new_check(NE_CHECK,$<id>3);
571 checks = g_list_append(checks,node);
575 number: NUMBER { $<id>$ = $<id>1; }
577 $<id>$ = g_strconcat("-",$<id>2,NULL);