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,
32 extern char *filename;
36 static GList *class_nodes = NULL;
39 static GList *typestack = NULL;
41 static GList *funcargs = NULL;
42 static GList *checks = NULL;
43 static int has_this = FALSE;
45 static GList *gtktypes = NULL;
60 if(strcmp(yytext,"\n")==0) {
61 out=g_strconcat("Error: ",str," before newline",NULL);
62 } else if(yytext[0]=='\0') {
63 out=g_strconcat("Error: ",str," at end of input",NULL);
65 char *tmp = g_strdup(yytext);
66 while((p=strchr(tmp,'\n')))
69 out=g_strconcat("Error: ",str," before '",tmp,"'",NULL);
73 fprintf(stderr,"%s:%d: %s\n",filename,line_no,out);
80 push_variable(char *name, int scope)
83 Type *type = typestack->data;
84 typestack = g_list_remove(typestack,typestack->data);
86 var = new_variable(scope,type,name);
87 class_nodes = g_list_append(class_nodes, var);
91 push_function(int scope, char *oid, char *id, char *onerror,
92 GString *cbuf,int line_no)
97 if(scope!=INIT_METHOD && scope!=CLASS_INIT_METHOD) {
98 type = typestack->data;
99 typestack = g_list_remove(typestack,typestack->data);
101 type = (Type *)new_type(0,g_strdup("void"));
104 node = new_method(scope,type,oid,gtktypes,id,funcargs,
105 onerror,cbuf,line_no);
109 class_nodes = g_list_append(class_nodes, node);
113 push_funcarg(char *name)
116 Type *type = typestack->data;
117 typestack = g_list_remove(typestack,typestack->data);
119 node = new_funcarg(type,name,checks);
122 funcargs = g_list_append(funcargs, node);
126 push_init_arg(char *name, int is_class)
133 tn = g_strconcat(((Class *)class)->otype,":Class",NULL);
135 tn = g_strdup(((Class *)class)->otype);
137 type = new_type(1,tn);
138 node = new_funcarg((Type *)type,name,NULL);
139 funcargs = g_list_prepend(funcargs, node);
143 push_this(char *this)
148 type = new_type(1,g_strdup(((Class *)class)->otype));
149 ch = g_list_append(ch,new_check(NULL_CHECK,NULL));
150 ch = g_list_append(ch,new_check(TYPE_CHECK,NULL));
151 node = new_funcarg((Type *)type,this,ch);
152 funcargs = g_list_prepend(funcargs, node);
165 %token VOID STRUCT UNION ENUM SIGNED UNSIGNED LONG SHORT INT FLOAT DOUBLE CHAR
167 %token CHECK CNULL TYPE ONERROR
169 %token <id> TOKEN NUMBER TYPETOKEN
170 %token <cbuf> CCODE HCODE
171 %token <line> PUBLIC PRIVATE ARGUMENT VIRTUAL SIGNAL OVERRIDE
175 prog: ccodes class ccodes { ; }
181 ccodes: ccodes CCODE {
182 Node *node = new_ccode(FALSE,$<cbuf>2);
183 nodes = g_list_append(nodes,node);
186 Node *node = new_ccode(TRUE,$<cbuf>2);
187 nodes = g_list_append(nodes,node);
190 Node *node = new_ccode(FALSE,$<cbuf>1);
191 nodes = g_list_append(nodes,node);
194 Node *node = new_ccode(TRUE,$<cbuf>1);
195 nodes = g_list_append(nodes,node);
199 class: classdec '{' classcode '}' {
200 ((Class *)class)->nodes = class_nodes;
202 nodes = g_list_append(nodes,class);
206 classdec: CLASS TYPETOKEN FROM TYPETOKEN {
207 class = new_class($<id>2,$<id>4,NULL);
211 classcode: classcode method { ; }
212 | classcode variable { ; }
213 | classcode argument { ; }
219 variable: PUBLIC type TOKEN ';' {
220 push_variable($<id>3,PUBLIC_SCOPE);
222 | PRIVATE type TOKEN ';' {
223 push_variable($<id>3,PRIVATE_SCOPE);
226 argument: ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE TOKEN '{' CCODE ';' {
227 if(strcmp($<id>5,"get")==0 &&
228 strcmp($<id>8,"set")==0) {
230 g_free($<id>5); g_free($<id>8);
231 node = new_argument($<id>3,$<list>2,$<id>4,
233 class_nodes = g_list_append(class_nodes,node);
234 } else if(strcmp($<id>5,"set")==0 &&
235 strcmp($<id>8,"get")==0) {
237 g_free($<id>5); g_free($<id>8);
238 node = new_argument($<id>3,$<list>2,$<id>4,
240 class_nodes = g_list_append(class_nodes,node);
242 g_free($<id>3); g_free($<id>4);
243 g_free($<id>5); g_free($<id>8);
244 g_list_foreach($<list>2,(GFunc)g_free,NULL);
245 g_string_free($<cbuf>10,TRUE);
246 g_string_free($<cbuf>7,TRUE);
247 yyerror(_("parse error"));
251 | ARGUMENT argflags TOKEN TOKEN TOKEN '{' CCODE ';' {
252 if(strcmp($<id>5,"get")==0) {
255 node = new_argument($<id>3,$<list>2,$<id>4,
257 class_nodes = g_list_append(class_nodes,node);
258 } else if(strcmp($<id>5,"set")==0) {
261 node = new_argument($<id>3,$<list>2,$<id>4,
263 class_nodes = g_list_append(class_nodes,node);
265 g_free($<id>5); g_free($<id>3);
267 g_list_foreach($<list>2,(GFunc)g_free,NULL);
268 g_string_free($<cbuf>7,TRUE);
269 yyerror(_("parse error"));
275 argflags: '(' flaglist ')' { $<list>$ = $<list>2; }
276 | { $<list>$ = NULL; }
279 flaglist: TOKEN '|' flaglist {
280 $<list>$ = g_list_append($<list>3,$<id>1);
283 $<list>$ = g_list_append(NULL,$<id>1);
289 Node *node = new_type(0,$<id>1);
290 typestack = g_list_prepend(typestack,node);
293 Node *node = new_type(stars,$<id>1);
295 typestack = g_list_prepend(typestack,node);
299 type1: UNSIGNED integer {
300 $<id>$ = g_strconcat("unsigned ",$<id>2,NULL);
303 $<id>$ = g_strconcat("signed ",$<id>2,NULL);
306 $<id>$ = g_strdup($<id>1);
309 $<id>$ = g_strdup("unsigned char");
312 $<id>$ = g_strdup("signed char");
315 $<id>$ = g_strdup("char");
318 $<id>$ = g_strdup("double");
321 $<id>$ = g_strdup("float");
327 $<id>$ = g_strconcat($<id>1,$<id>2,NULL);
334 $<id>$ = g_strdup("void");
345 $<id>$ = "short int";
366 stars: '*' stars { stars++; }
370 sigtype: TOKEN '(' tokenlist ')' {
371 gtktypes = g_list_prepend(gtktypes,$<id>1);
375 tokenlist: tokenlist ',' TOKEN {
376 gtktypes = g_list_append(gtktypes,$<id>3);
379 gtktypes = g_list_append(gtktypes,$<id>1);
383 /*here CCODE will include the ending '}' */
384 method: SIGNAL LAST sigtype type TOKEN '(' funcargs ')' onerror '{' CCODE {
386 yyerror(_("signal without 'this' as "
390 push_function(SIGNAL_LAST_METHOD,NULL,
391 $<id>5, $<id>9, $<cbuf>11,$<line>1);
393 | SIGNAL LAST sigtype type TOKEN '(' funcargs ')' onerror ';' {
395 yyerror(_("signal without 'this' as "
399 push_function(SIGNAL_LAST_METHOD, NULL,
400 $<id>5, $<id>9, NULL,$<line>1);
402 | SIGNAL FIRST sigtype type TOKEN '(' funcargs ')' onerror '{' CCODE {
404 yyerror(_("signal without 'this' as "
408 push_function(SIGNAL_FIRST_METHOD, NULL,
409 $<id>5, $<id>9, $<cbuf>11,$<line>1);
411 | SIGNAL FIRST sigtype type TOKEN '(' funcargs ')' onerror ';' {
413 yyerror(_("signal without 'this' as "
417 push_function(SIGNAL_FIRST_METHOD, NULL, $<id>5,
418 $<id>9, NULL,$<line>1);
420 | SIGNAL sigtype type TOKEN '(' funcargs ')' onerror '{' CCODE {
422 yyerror(_("signal without 'this' as "
426 push_function(SIGNAL_LAST_METHOD, NULL,
427 $<id>4, $<id>8, $<cbuf>10,$<line>1);
429 | SIGNAL sigtype type TOKEN '(' funcargs ')' onerror ';' {
431 yyerror(_("signal without 'this' as "
435 push_function(SIGNAL_LAST_METHOD, NULL, $<id>4,
436 $<id>8, NULL,$<line>1);
438 | VIRTUAL type TOKEN '(' funcargs ')' onerror '{' CCODE {
439 push_function(VIRTUAL_METHOD, NULL, $<id>3,
440 $<id>7, $<cbuf>9,$<line>1);
442 | VIRTUAL type TOKEN '(' funcargs ')' onerror ';' {
443 push_function(VIRTUAL_METHOD, NULL, $<id>3,
444 $<id>7, NULL,$<line>1);
446 | OVERRIDE '(' TYPETOKEN ')' type TOKEN '(' funcargs ')' onerror '{' CCODE {
447 push_function(OVERRIDE_METHOD, $<id>3,
448 $<id>6, $<id>10, $<cbuf>12,$<line>1);
450 | PUBLIC type TOKEN '(' funcargs ')' onerror '{' CCODE {
451 push_function(PUBLIC_SCOPE, NULL, $<id>3,
452 $<id>7, $<cbuf>9,$<line>1);
454 | PRIVATE type TOKEN '(' funcargs ')' onerror '{' CCODE {
455 push_function(PRIVATE_SCOPE, NULL, $<id>3,
456 $<id>7, $<cbuf>9,$<line>1);
458 | TOKEN '(' TOKEN ')' ';' {
459 if(strcmp($<id>1,"init")==0) {
460 push_init_arg($<id>3,FALSE);
461 push_function(INIT_METHOD, NULL, $<id>1,
462 NULL, NULL,$<line>2);
463 } else if(strcmp($<id>1,"class_init")==0) {
464 push_init_arg($<id>3,TRUE);
465 push_function(CLASS_INIT_METHOD, NULL,
466 $<id>1, NULL, NULL,$<line>2);
470 yyerror(_("parse error"));
474 | TOKEN '(' TOKEN ')' '{' CCODE {
475 if(strcmp($<id>1,"init")==0) {
476 push_init_arg($<id>3,FALSE);
477 push_function(INIT_METHOD, NULL,
478 $<id>1, NULL, $<cbuf>6,$<line>2);
479 } else if(strcmp($<id>1,"class_init")==0) {
480 push_init_arg($<id>3,TRUE);
481 push_function(CLASS_INIT_METHOD, NULL,
482 $<id>1, NULL, $<cbuf>6,$<line>2);
486 g_string_free($<cbuf>3,TRUE);
487 yyerror(_("parse error"));
493 onerror: ONERROR TOKEN { $<id>$ = $<id>2; }
494 | ONERROR number { $<id>$ = $<id>2; }
495 | ONERROR '{' CCODE {
496 $<id>$ = ($<cbuf>3)->str;
497 g_string_free($<cbuf>3,FALSE);
505 funcargs: VOID { has_this = FALSE; }
508 if(strcmp($<id>1,"this")==0)
512 yyerror(_("parse error"));
516 | TOKEN ',' arglist {
518 if(strcmp($<id>1,"this")==0)
522 yyerror(_("parse error"));
526 | arglist { has_this = FALSE; }
529 arglist: arglist ',' arg { ; }
534 push_funcarg($<id>2);
536 | type TOKEN '(' CHECK checklist ')' {
537 push_funcarg($<id>2);
541 checklist: checklist check { ; }
546 Node *node = new_check(NULL_CHECK,NULL);
547 checks = g_list_append(checks,node);
550 Node *node = new_check(TYPE_CHECK,NULL);
551 checks = g_list_append(checks,node);
554 Node *node = new_check(GT_CHECK,$<id>2);
555 checks = g_list_append(checks,node);
558 Node *node = new_check(LT_CHECK,$<id>2);
559 checks = g_list_append(checks,node);
562 Node *node = new_check(GE_CHECK,$<id>3);
563 checks = g_list_append(checks,node);
566 Node *node = new_check(LE_CHECK,$<id>3);
567 checks = g_list_append(checks,node);
570 Node *node = new_check(EQ_CHECK,$<id>3);
571 checks = g_list_append(checks,node);
574 Node *node = new_check(NE_CHECK,$<id>3);
575 checks = g_list_append(checks,node);
579 number: NUMBER { $<id>$ = $<id>1; }
581 $<id>$ = g_strconcat("-",$<id>2,NULL);