Initial revision
[charm.git] / src / xlat / xl-yacc.bison
1 %{
2 #include "xl-lex.h"
3 #include "xl-sym.h"
4
5 extern int CurrentInputLineNo,SavedLineNo;
6 extern char CurrentFileName[],SavedFileName[];
7 extern char ModuleName[];
8
9 #define USERDEFINED 1
10 #define SYSTEMDEFINED 2
11
12 #define YYSTYPE YSNPTR
13 #define YYMAXDEPTH 300
14
15 #define dump(string)    writeoutput(string,NOFREE)
16
17 extern char *AppendMap(),*AppendMapIndex();  
18 char token[256];
19
20 BUFFERTYPE buffer;
21
22 extern void RestoreCurrentTable();
23 extern void SetIdList();
24 extern void GenerateStruct();           /* outh.c */
25 extern void InsertSysCalls();           /* readtokens.c */
26 extern TYPEPTR ProcessTypeIdentifier();
27
28 char *dummy_ptr=NULL;
29 SYMTABPTR worksymtab,SavedFnNode;
30 SYMTABPTR ImportModule=NULL;
31 SYMTABPTR ModuleDefined=NULL;
32 SYMTABPTR Pass1Module=NULL;
33 SYMTABPTR sym1,sym2;
34 TYPEPTR SavedTypeNode;
35 char *SavedName,*itoa(),*Map(),*AccMonoName,*AccMonoTypeName;
36 char *ForwardedMsgName;
37 int SaveMsgCount;
38
39 SYMTABPTR GlobalModuleSearch(),GlobalEntryFind(),ProcessIdDcolonId();
40 void SwapFile();
41
42 char *CkMyData="_CK_4mydata->";
43 char *CkLocalPtr="_CK_4localptr";
44 char *CkDummyPtr="_CK_4dummyptr";
45 char *CkMsgQualifier="MSG";
46 char *DataSuffix="_Data";
47 char *AssignMyDataPtr=" *_CK_4mydata = (";
48 char *AssignMyID="\nChareIDType ThisChareID=((CHARE_BLOCK *)_CK_4mydata)[-1].selfID;";
49 char *AssignMyBOC="\nint ThisBOC=((CHARE_BLOCK *)_CK_4mydata)[-1].x.boc_num;";
50 char *DummyField="  char _CK;";
51 extern char *REFSUFFIX;         /* outh.c */
52 extern char *CkGenericAlloc,*CkVarSizeAlloc;
53
54
55 int INSIDE_PRIVFUNC_PROTO=0; /* Jun 14, 1995, added by Attila */
56 int PRIVATEFLAG=0;
57 int StoredEPFlag;
58 int IMPORTFLAG=0;
59 int IMPORTMSGFLAG=0; /* Dec 30, 1991 Added by Attila */
60 int SELFIMPMODULE=0; /* Jan 2, 1992  Added by Attila */
61 int MULTI_STMT_TR=0; /* Feb 18, 1992  Added by Attila */
62 int export_to_c_flag=0; /* March, 1994  Added by Attila */
63 int ImportStruct=0;
64 int ImportLevel=0;
65 int OUTPUTOFF=0;
66 int FUNCTIONCOUNT=0;
67 int FNNAMETOREFFLAG=0;
68 int FNREFTONAMEFLAG=0; /* Jan 16, 1992 Added by Attila */
69 int READMSGINITFLAG=0;
70 int BUFFEROUTPUT=0;
71 int FORWARDEDMESSAGE=0;
72 int MsgCount=10;        /* ARBITRARY - Set to > 1 */
73 int MsgToStructFlag=0;
74 FILE *outfile;
75
76 TYPEPTR SetType(typeptr)
77 TYPEPTR typeptr;
78 { (typeptr->count)++;
79   return(typeptr);
80 }
81
82 void RecursiveFree(typeptr)
83 TYPEPTR typeptr;
84 { if (typeptr->type != NULL) RecursiveFree(typeptr->type);
85   if (typeptr->table != NULL) FreeTree(typeptr->table); 
86   dontfree(typeptr);
87 }
88
89 void FreeType(typeptr)
90 TYPEPTR typeptr;
91 { if (typeptr==NULL) return;
92   if (--(typeptr->count) <= 0) RecursiveFree(typeptr); }
93
94 %}
95 %token CHARE
96 %token MAIN
97 %token MESSAGE
98 %token ENTRY
99 %token PRIVATE
100 %token DATAINIT
101 %token CHAREINIT
102 %token QUIESCENCE
103 %token MODULE
104 %token BRANCHOFFICE
105 %token READONLY
106 %token MONOTONIC
107 %token TABLE
108 %token ACCUMULATOR
109 %token STATIC
110 %token PACK
111 %token UNPACK
112 %token VARSIZE
113 %token FUNCTION
114 %token BRANCH
115 %token SIZEOF
116 %token AUTO
117 %token BREAK
118 %token CASE
119 %token CHAR
120 %token CONST
121 %token CONTINUE
122 %token DEFAULT
123 %token DO
124 %token DOUBLE
125 %token ELSE
126 %token ENUM
127 %token EXTERN
128 %token FLOAT
129 %token FOR
130 %token GOTO
131 %token IF
132 %token INT
133 %token LONG
134 %token REGISTER
135 %token RETURN
136 %token SHORT
137 %token SIGNED
138 %token STRUCT
139 %token SWITCH
140 %token TYPEDEF
141 %token UNION
142 %token UNSIGNED
143 %token VOID
144 %token WHILE
145 %token INTERFACE
146 %token ChareIDType 
147 %token EntryPointType 
148 %token PeNumType     
149 %token PackIDType   
150 %token WriteOnceID
151 %token PVECTOR  
152 %token ChareNumType
153 %token EntryNumType
154 %token BOOLEAN
155
156 %token R_PAREN
157 %token R_SQUARE
158 %token L_BRACE
159 %token R_BRACE
160 %token SEMICOLON
161 %token IDENTIFIER
162 %token TYPE_IDENTIFIER
163 %token EPIDENTIFIER
164 %token MCIDENTIFIER
165 %token STRING
166 %token NUMBER
167 %token CHAR_CONST
168 %token COMMA_R_BRACE
169 %token COMMA_L_BRACE
170 %token AT
171
172 %left COMMA
173 %right ASGNOP EQUAL
174 %left QUESTION COLON
175 %left OROR
176 %left ANDAND
177 %left OR
178 %left HAT
179 %left AND
180 %left EQUALEQUAL NOTEQUAL
181 %left COMPARE
182 %left SHIFT
183 %left PLUS MINUS
184 %left MULT DIV MOD
185 %left UNARY INCDEC TILDE EXCLAIM
186 %left L_PAREN L_SQUARE DOT POINTERREF
187
188 %token PRIVATECALL
189 %token BRANCHCALL
190 %token ID_DCOLON_ID
191 %token PUBLIC
192 %token FNNAMETOREF
193 %token CKALLOCMSG
194 %token CKALLOCPRIOMSG
195 %token READMSGINIT
196 %token ACCUMULATE
197 %token NEWVALUE
198 %token ACCIDTYPE
199 %token MONOIDTYPE
200 %token DUMMYMSG
201 %token FunctionRefType
202 %token FUNCTION_PTR
203 %token FNREFTONAME
204 %token IMPLICIT
205 %token BLOCKEDRECV
206 %token DAG
207 %token MATCH
208 %token AUTOFREE
209 %token WHEN
210 %token CHARECALL
211 %token ChareNameType
212 %token EXPORT_TO_C
213 %start program
214
215 %%
216 program         : file_text
217                         { if (yylex()) 
218                              warning("Ignoring Extraneous Characters at End"); 
219                           return(0); 
220                         }
221                 ;
222
223 file_text       : module_text
224                         { CurrentTable=StackBase->tableptr;
225                           if (InPass1)
226                                 {Pass1Module=GetSymTabNode(CurrentModule->name);
227                                  Pass1Module->type=CurrentModule->type;
228                                 } 
229                         }
230                 | import_text module_text
231                         { CurrentTable=StackBase->tableptr;
232                           if (InPass1)
233                                 {Pass1Module=GetSymTabNode(CurrentModule->name);
234                                  Pass1Module->type=CurrentModule->type;
235                                 } 
236                         }
237                 ;
238
239 import_text     : import_decl   
240                         { CurrentTable=StackBase->tableptr;
241                           CurrentModule=NULL;
242                         }
243                 | import_text import_decl
244                         { CurrentTable=StackBase->tableptr;
245                           CurrentModule=NULL;
246                         }
247                 ;
248
249 import_decl     : INTERFACE     { IMPORTFLAG=TRUE; ImportLevel=0;}
250                   MODULE IDENTIFIER 
251                         { CurrentModule=Insert($4->string,StackBase->tableptr); 
252                           FillSymTabNode(CurrentModule,MODULENAME,IMPORTED,
253                                 UNDEFINED,UNDEFINED,1,TRUE,NULL);
254                           CurrentTable=CurrentModule->type->table;
255 /* Adding On Oct. 27, 1991.*/
256                           SwapFile(OUT1);
257                           if (strcmp($4->string,ModuleName)) {
258                                 SELFIMPMODULE = 0;
259                                 writeoutput("\nextern struct { ",NOFREE);
260                               } 
261                           else{
262                                 SELFIMPMODULE = 1;
263                                 writeoutput("\nstruct { ",NOFREE);
264                           }
265                           SwapFile(NULL);
266                           DestroyString($4->string);dontfree($4);
267                         }
268                   L_BRACE import_constructs R_BRACE
269                         { SwapFile(OUT1);writeoutput("} ",NOFREE);
270                           writeoutput(CkPrefix,NOFREE);
271                           writeoutput(CurrentModule->name,NOFREE);
272                           writeoutput(" ;",NOFREE);WriteReturn();
273                           SwapFile(NULL);
274                           IMPORTFLAG=FALSE;
275                         }
276                 ;
277  
278 import_constructs : imp_construct
279                 | import_constructs imp_construct
280                 ;
281
282 ITypeDef        : TYPEDEF { SwapFile(OUT0);writeoutput("typedef ",NOFREE); }
283                 ;
284
285 imp_construct   : ITypeDef
286                   type_spec init_decl_list semicolon
287                           { SetIdList($2->type,$3->listptr,TYPENAME,0);
288                             dontfree($2);dontfree($3);
289                             WriteReturn();      
290                             SwapFile(NULL);
291                           }
292                 | ITypeDef
293                   init_decl_list semicolon
294                           { SetIdList(DUMMYPTR,$2->listptr,TYPENAME,0);
295                             dontfree($2);
296                             WriteReturn();      
297                             SwapFile(NULL);
298                           }
299                 | imp_fn_decl 
300                         { SwapFile(NULL); }
301                 | imp_message_defn
302                         { SwapFile(NULL); }
303                 | imp_acc
304                         { SwapFile(NULL); }
305                 | imp_mono
306                         { SwapFile(NULL); }
307                 | imp_chare_defn
308                         { SwapFile(NULL); }
309                 | imp_main_chare_defn
310                         { SwapFile(NULL); }
311                 | imp_boc_defn
312                         { SwapFile(NULL); }
313                 | { SwapFile(OUT0);  /* Jan 2 1992, Attila */
314                     if (SELFIMPMODULE) writeoutput("/* ",NOFREE);} 
315                   imp_readonly 
316                   { if (SELFIMPMODULE) {
317                        writeoutput("*/",NOFREE);
318               /*       WriteReturn(); Dec 15, 1993*/
319                     }
320                     WriteReturn(); /* Dec 15,1993 Attila */
321                     SwapFile(NULL); }
322                 | { SwapFile(OUT0); /* Jan 6 1992, Attila */
323                     if (SELFIMPMODULE) writeoutput("/* ",NOFREE);}
324                   table_defn
325                   { if (SELFIMPMODULE) {
326                        writeoutput("*/",NOFREE);
327               /*       WriteReturn(); Dec 15 1993 */
328                     } 
329                     WriteReturn(); /* Dec 15, 1993 */
330                     SwapFile(NULL); }
331                 ;
332
333 imp_acc         : ACCUMULATOR { SwapFile(OUT1); }
334                   aid_list SEMICOLON
335                         { writeoutput(";",NOFREE);WriteReturn(); }
336                 ;
337
338 imp_mono        : MONOTONIC { SwapFile(OUT1); }
339                   mid_list SEMICOLON
340                         { writeoutput(";",NOFREE);WriteReturn(); }
341                 ;
342
343 aid_list        : IDENTIFIER 
344                         { worksymtab=Insert($1->string,CurrentTable);
345                           worksymtab->idtype=ACCNAME;
346                           writeoutput("int ",NOFREE);
347                           writeoutput($1->string,NOFREE);
348                           DestroyString($1->string);dontfree($1);
349                         }
350                 | aid_list COMMA IDENTIFIER
351                         { worksymtab=Insert($3->string,CurrentTable);
352                           worksymtab->idtype=ACCNAME;
353                           writeoutput(",",NOFREE);
354                           writeoutput($3->string,NOFREE);
355                           DestroyString($3->string);dontfree($3);
356                         }
357                 ;
358
359 mid_list        : IDENTIFIER
360                         { worksymtab=Insert($1->string,CurrentTable);
361                           worksymtab->idtype=MONONAME;
362                           writeoutput("int ",NOFREE);
363                           writeoutput($1->string,NOFREE);
364                           DestroyString($1->string);dontfree($1);
365                         }
366                 | mid_list COMMA IDENTIFIER
367                         { worksymtab=Insert($3->string,CurrentTable);
368                           worksymtab->idtype=MONONAME;
369                           writeoutput(",",NOFREE);
370                           writeoutput($3->string,NOFREE);
371                           DestroyString($3->string);dontfree($3);
372                         }
373                 ;
374
375 imp_readonly    : readonly
376                 ;
377
378 ID_L_R_S        : IDENTIFIER L_PAREN R_PAREN SEMICOLON
379                         { worksymtab=Insert($1->string,CurrentTable);
380                           worksymtab->idtype=FNNAME;
381                           writeoutput(" (* ",NOFREE);
382                           writeoutput($1->string,NOFREE);
383                           writeoutput(")();\n  int ",NOFREE);
384                           writeoutput($1->string,NOFREE);
385                           writeoutput(REFSUFFIX,NOFREE);
386                           writeoutput(";",NOFREE);WriteReturn();
387                           DestroyString($1->string);dontfree($1);
388                         }
389                 ;
390
391 imp_fn_decl     : { SwapFile(OUT1); writeoutput("  int",NOFREE); } ID_L_R_S
392                 | { SwapFile(OUT1); writeoutput(" ",NOFREE); }
393                   system_types {writeoutput($2->string);} ID_L_R_S
394                 | TYPE_IDENTIFIER
395                         {
396                           SwapFile(OUT1);
397                           writeoutput("  ",NOFREE); 
398                           writeoutput(Map(CurrentModule->name,"0",
399                                                 $1->string),NOFREE);
400                           DestroyString($1->string);dontfree($1);
401                         }
402                   ID_L_R_S
403                 | {SwapFile(OUT1); writeoutput("  ",NOFREE);} su_spec ID_L_R_S
404                 ;
405         
406 optID           :       
407                 | IDENTIFIER    
408                         { writeoutput(Map(CurrentModule->name,"0",$1->string),NOFREE);
409                           worksymtab=Insert($1->string,CurrentTable);
410                           worksymtab->idtype=STRUCTNAME;
411                           DestroyString($1->string);dontfree($1);
412         /* NOT BOTHERING TO SET ITS TYPE */
413                         }
414                 ;
415
416 imp_message_defn: MESSAGE       { SwapFile(OUT0);
417                                   writeoutput("typedef struct ",NOFREE);
418                                   ImportLevel=0;
419                                   /* Dec 30 ,1991 added by Attila */
420                                   IMPORTMSGFLAG = 1;
421                                   /* End of Addition */
422                                 }
423                   optID L_BRACE { PushStack(); writeoutput(" {",NOFREE); }
424                   msg_opt_su_rest R_BRACE IDENTIFIER SEMICOLON
425                         { TYPEPTR typeptr;
426                           /* Added by Attila, Dec 23 1991 */
427                                   SwapFile(OUT1);
428                                   writeoutput("    int ",NOFREE);
429                                   writeoutput($8->string,NOFREE);
430                                   writeoutput(";",NOFREE);
431                                   WriteReturn();
432                                   SwapFile(OUT0);
433                           /* End Of Addition */
434                           writeoutput(" } ",NOFREE);
435                           typeptr=GetTypeNode(1,0);
436                           typeptr->basictype=STRUCTTYPE;
437                           typeptr->table=CurrentTable;
438                           PopStack(NOFREE);RestoreCurrentTable();
439                           worksymtab=Insert($8->string,CurrentTable);
440                           worksymtab->idtype=MESSAGENAME;
441                           worksymtab->type=typeptr;
442  /*               writeoutput(Map(CurrentModule,"0",$8->string),NOFREE); */
443  /* The statement above has been modified as follows, Attila Dec 23 1991 */
444                           writeoutput(Map(CurrentModule->name,
445                                           "0",$8->string),NOFREE);
446                           writeoutput(";",NOFREE);WriteReturn();
447                           DestroyString($8->string);dontfree($8);
448                           IMPORTMSGFLAG = 0; /* Dec 30,1991 added by Attila */
449                         }
450                 ;
451
452 imp_chare_defn  : CHARE IDENTIFIER
453                         { SwapFile(OUT1);
454                           writeoutput("  struct {",NOFREE);
455                           SwapFile(NULL);
456                           worksymtab=Insert($2->string,CurrentTable);
457                           FillSymTabNode(worksymtab,CHARENAME,IMPORTED,
458                                 UNDEFINED,UNDEFINED,1,TRUE,NULL);
459                           CurrentTable=worksymtab->type->table;
460                           CurrentChare=worksymtab;
461                         }
462                   L_BRACE entry_pub_fn_list R_BRACE
463                         { SwapFile(OUT1);
464                           writeoutput("  } ",NOFREE);
465                           writeoutput(CkPrefix,NOFREE);
466                           writeoutput($2->string,NOFREE);
467                           writeoutput(";\n  int ",NOFREE);
468                           writeoutput($2->string,NOFREE);
469                           writeoutput(";",NOFREE);WriteReturn();
470                           SwapFile(NULL);
471                           DestroyString($2->string);dontfree($2);
472                           CurrentTable=CurrentModule->type->table;
473                           CurrentChare=NULL;
474                         }
475                 ;
476
477 imp_boc_defn    : BRANCHOFFICE IDENTIFIER
478                         { SwapFile(OUT1);
479                           writeoutput("  struct {",NOFREE);
480                           worksymtab=Insert($2->string,CurrentTable);
481                           FillSymTabNode(worksymtab,BOCNAME,IMPORTED,
482                                 UNDEFINED,UNDEFINED,1,TRUE,NULL);
483                           CurrentTable=worksymtab->type->table;
484                           CurrentChare=worksymtab;
485                         }
486                   L_BRACE entry_pub_fn_list R_BRACE
487                         { SwapFile(OUT1);
488                           writeoutput("  } ",NOFREE);
489                           writeoutput(CkPrefix,NOFREE);
490                           writeoutput($2->string,NOFREE);
491                           writeoutput(";\n  int ",NOFREE);
492                           writeoutput($2->string,NOFREE);
493                           writeoutput(";",NOFREE);WriteReturn();
494                           DestroyString($2->string);dontfree($2);
495                           CurrentTable=CurrentModule->type->table;
496                           CurrentChare=NULL;
497                         }
498                 ;
499
500 imp_main_chare_defn : CHARE MAIN 
501                         { SwapFile(OUT1);
502                           writeoutput("  struct {",NOFREE);
503                           /* Jan 6, 1992, added by Attila */
504                           worksymtab=Insert("main",CurrentTable);
505                           FillSymTabNode(worksymtab,CHARENAME,IMPORTED,
506                                 UNDEFINED,UNDEFINED,1,TRUE,NULL);
507                           CurrentTable=worksymtab->type->table;
508                           CurrentChare=worksymtab;
509                           /* end of addition */
510                         }
511                   L_BRACE entry_list R_BRACE
512                         { /* Jan 6 1992 , Attila */ SwapFile(OUT1);
513                           writeoutput("  } ",NOFREE);
514                           writeoutput(CkPrefix,NOFREE);
515                           writeoutput("main",NOFREE);
516                           writeoutput(";\n  int ",NOFREE);
517                           writeoutput("main",NOFREE);
518                           writeoutput(";",NOFREE);WriteReturn();
519                           /* Jan 6 1992, added by Attila */
520                           CurrentTable=CurrentModule->type->table;
521                           CurrentChare=NULL;
522                           /* end of addition */
523                         }
524                 ;
525
526 EIS             : ENTRY IDENTIFIER SEMICOLON
527                         { SwapFile(OUT1);
528                           writeoutput("    int ",NOFREE);
529                           writeoutput($2->string,NOFREE);
530                           writeoutput(";",NOFREE);WriteReturn();
531                           SwapFile(NULL);
532                           worksymtab=Insert($2->string,CurrentTable);
533                           worksymtab->idtype=ENTRYNAME;
534                           worksymtab->declflag=IMPORTED;
535                           DestroyString($2->string);dontfree($2);
536                         }
537                 ;
538
539 entry_list      : EIS
540                 | entry_list EIS
541                 ;
542
543 ILRS            : IDENTIFIER L_PAREN R_PAREN SEMICOLON
544                         { OUTPUTOFF=FALSE;SwapFile(OUT1);
545                           writeoutput("    int ",NOFREE);
546                           writeoutput($1->string,NOFREE);
547                           writeoutput(";",NOFREE);WriteReturn();
548                           worksymtab=Insert($1->string,CurrentTable);
549                           worksymtab->idtype=PUBLICFNNAME;
550                           worksymtab->declflag=IMPORTED;
551                           DestroyString($1->string);dontfree($1);
552                         }
553
554 PUBFN           : PUBLIC        { OUTPUTOFF=TRUE; }
555                   type_spec ILRS
556                 | PUBLIC ILRS
557                 ;
558 entry_pub_fn_list : EIS
559                 | PUBFN
560                 | entry_pub_fn_list EIS
561                 | entry_pub_fn_list PUBFN
562                 ;
563
564 module_text     : MODULE IDENTIFIER
565                         { worksymtab=LocalFind($2->string);
566                           InPass1 = !InPass1;
567                           if (!InPass1) SwapFile(OUT); else SwapFile(NULL);
568                           SavedLineNo=CurrentInputLineNo;
569                           strcpy(SavedFileName,CurrentFileName);        
570                           if (worksymtab==NULL)
571                                 CurrentModule=Insert($2->string,StackBase->tableptr); 
572                           else  { if (InPass1)
573                                   { CurrentModule=worksymtab;
574                                     GenerateStruct($2->string,
575                                      worksymtab->type->table,TRUE,CkPrefix,0);
576                                     ImportModule=worksymtab->type->table;
577                                   }
578                                 }
579                           FillSymTabNode(CurrentModule,MODULENAME,DECLARED,
580                                 UNDEFINED,UNDEFINED,1,TRUE,NULL);
581                           CurrentTable=CurrentModule->type->table;
582                           ModuleDefined=CurrentModule;
583                           DestroyString($2->string);dontfree($2);
584                           InsertSysCalls();
585                           _dag_init(CurrentModule->name);
586                         }
587                   L_BRACE mod_constructs R_BRACE
588                 ;
589
590 mod_constructs  : construct
591                 | mod_constructs construct
592                 ;
593
594 ext_const       : IDENTIFIER
595                         { writeoutput($1->string,NOFREE);
596                           worksymtab = Insert($1->string,
597                                                 CurrentModule->type->table);
598                           worksymtab->idtype=VARNAME;
599                           worksymtab->type=INTPTR;
600                           DestroyString($1->string);dontfree($1); }
601                 | IDENTIFIER {writeoutput($1->string,NOFREE);}
602                   L_SQUARE {writeoutput("[",NOFREE);}
603                   ext_constant 
604                   R_SQUARE 
605                           {writeoutput("]",NOFREE);
606                           worksymtab = Insert($1->string,
607                                                 CurrentModule->type->table);
608                           worksymtab->idtype=ARRAYNAME;
609                           worksymtab->type=INTPTR;
610                           DestroyString($1->string);dontfree($1); }
611                 | IDENTIFIER L_PAREN R_PAREN
612                         { writeoutput($1->string,NOFREE);
613                           writeoutput("()",NOFREE);
614                           worksymtab = Insert($1->string,
615                                                 CurrentModule->type->table);
616                           DestroyString($1->string);dontfree($1);
617                           worksymtab->idtype=SYSCALLNAME;
618                           worksymtab->type=INTPTR;
619                         }
620         | IDENTIFIER L_PAREN
621             { writeoutput($1->string, NOFREE);
622               writeoutput("(", NOFREE);
623             }
624             ext_parameter_list R_PAREN
625             { worksymtab = Insert($1->string,
626                     CurrentModule->type->table);
627               DestroyString($1->string);dontfree($1);
628               worksymtab->idtype=SYSCALLNAME;
629               worksymtab->type=INTPTR;
630               writeoutput(")", NOFREE);
631             }
632                 ;
633
634 ext_parameter_list : typedef_name {
635               ;
636             }
637         | typedef_name IDENTIFIER {
638               writeoutput($1->string, NOFREE);
639             }
640         | ext_parameter_list comma typedef_name {
641              /* writeoutput($3->string, NOFREE);*/
642             }
643         | ext_parameter_list comma typedef_name IDENTIFIER {
644               writeoutput($4->string, NOFREE);
645             }
646         ;
647
648
649 ext_constant    : constant
650                 |
651                 ;
652 ext_list        : mopt {if($1!=NULL) {writeoutput("*",NOFREE);dontfree($1);} }
653                   ext_const
654                       
655                 | ext_list comma mopt 
656                        {if($3!=NULL) {writeoutput("*",NOFREE);dontfree($3);}}
657                   ext_const
658                 ;
659
660 construct       : TypeDef type_spec init_decl_list semicolon
661                         { SetIdList($2->type,$3->listptr,TYPENAME,0);
662                           dontfree($2);dontfree($3);
663                         }
664                 | TypeDef init_decl_list semicolon
665                           { SetIdList(DUMMYPTR,$2->listptr,TYPENAME,0);
666                             dontfree($2);
667                           }
668                 | module_su_spec module_init_decl semicolon 
669                     {  SetIdList($1->type,$2->listptr,VARNAME,0);
670                        dontfree($2); dontfree($1);
671                     }
672                 | EXTERN type_spec ext_list semicolon
673                 | EXTERN ext_list semicolon
674                 | function_decl semicolon
675                             { worksymtab=$1->table;
676                               if (worksymtab->localid==0)
677                                         worksymtab->idtype=SYSCALLNAME;
678                                 PopStack(FREE);PopStack(FREE);
679                                 RestoreCurrentTable(); }
680                 | function_decl function_body
681                   { worksymtab=$1->table;
682                     worksymtab->localid=1;
683                     dontfree($1); RestoreCurrentTable();} 
684                 | EXPORT_TO_C
685                         { export_to_c_flag = 1;}
686                   function_decl
687                         { export_to_c_flag = 0;}
688                   function_body
689                         { worksymtab=$3->table;
690                           worksymtab->localid=1;
691                           dontfree($3); RestoreCurrentTable();
692                         }
693                 | message_defn
694                 | acc_defn
695                 | mono_defn
696                 | chare_defn
697                 | dag_chare_defn
698                 | boc_defn
699                 | dag_boc_defn
700                 | main_chare_defn
701                 | readonly
702                 | table_defn
703                 | const_declaration
704                 ;
705
706
707 const_declaration : CONST typename IDENTIFIER
708             {
709               writeoutput($3->string, NOFREE);
710                       writeoutput("=", NOFREE);
711             }
712             EQUAL expression SEMICOLON
713             { writeoutput(";", NOFREE); }
714
715
716
717
718 /* Feb 18, 1992 added by Attila */
719 module_su_spec  : Struct IDENTIFIER { if (IMPORTFLAG) ImportStruct=TRUE;
720                                       if (ImportStruct)
721                                                 writeoutput(Map(CurrentModule->name,"_CKTYPE",$2->string),NOFREE); 
722                                       else      writeoutput($2->string,NOFREE); 
723                                       ImportStruct=FALSE;
724                                     }
725                   su_rest
726                         { SYMTABPTR dummy,temp;int i;TYPEPTR type;
727
728                           dummy=FindInTable(CurrentTable,$2->string,&i);
729                           if (i!=0) 
730                                 { worksymtab=Insert($2->string,CurrentTable);
731                                   worksymtab->type=GetTypeNode(1,0);
732                                 }
733                           else  { if ((dummy->declflag!=NOTDECLARED) ||
734                                         (dummy->idtype!=STRUCTNAME))
735                                         error("Bad Struct Name",EXIT);
736                                   worksymtab=dummy;
737                                   type=GetTypeNode(1+worksymtab->type->count,0);
738                                   dummy=(SYMTABPTR)worksymtab->type->type;
739                                   while (dummy!=NULL)
740                                         { temp=(SYMTABPTR)dummy;
741                                           dummy->type=type;dummy=temp;
742                                           /* this is an infinite loop */
743                                           /* set dummy to NULL */
744                                           dummy = NULL;
745                                         }
746                                   dontfree(worksymtab->type);
747                                   worksymtab->type=type;
748                                 }
749         
750                           worksymtab->type->basictype=STRUCTTYPE;
751                           worksymtab->idtype=STRUCTNAME;
752                           worksymtab->declflag=DECLARED;
753                           worksymtab->type->table=$4->table;
754                           $$=GetYSN();$$->type=worksymtab->type;
755                           DestroyString($2->string);dontfree($2);dontfree($4);
756                         }
757                 | Union IDENTIFIER      { if (IMPORTFLAG) ImportStruct=TRUE;
758                                           if (ImportStruct)
759                                                 writeoutput(Map(CurrentModule->name,"_CKTYPE",$2->string),NOFREE); 
760                                           else  writeoutput($2->string,NOFREE); 
761                                           ImportStruct=FALSE;
762                                         }
763                   su_rest
764                         { SYMTABPTR dummy,temp;int i;TYPEPTR type;
765
766                           
767                           {
768                           dummy=FindInTable(CurrentTable,$2->string,&i);
769                           if (i!=0) 
770                                 { worksymtab=Insert($2->string,CurrentTable);
771                                   worksymtab->type=GetTypeNode(1,0);
772                                 }
773                           else  { if ((dummy->declflag!=NOTDECLARED) ||
774                                         (dummy->idtype!=UNIONNAME))
775                                         error("Bad Struct Name",EXIT);
776                                   worksymtab=dummy;
777                                   type=GetTypeNode(1+worksymtab->type->count,0);
778                                   dummy=(SYMTABPTR)worksymtab->type->type;
779                                   while (dummy!=NULL)
780                                         { temp=(SYMTABPTR)dummy;
781                                           dummy->type=type;dummy=temp;
782                                           /* this is an infinite loop */
783                                           /* set dummy to NULL */
784                                           dummy = NULL;
785                                         }
786                                   dontfree(worksymtab->type);
787                                   worksymtab->type=type;
788                                 }
789         
790                           worksymtab->type->basictype=UNIONTYPE;
791                           worksymtab->idtype=UNIONNAME;
792                           worksymtab->declflag=DECLARED;
793                           worksymtab->type->table=$4->table;
794                           $$=GetYSN();$$->type=worksymtab->type;
795                           DestroyString($2->string);dontfree($2);dontfree($4); 
796                           }
797                         }
798                 | Enum IDENTIFIER 
799                         { SYMTABPTR dummy; int i;
800
801                           if (IMPORTFLAG) ImportStruct=TRUE;
802                           if (!ImportStruct)
803                                 writeoutput($2->string,NOFREE);  
804                           else  writeoutput(Map(CurrentModule->name,"_CKTYPE",$2->string),NOFREE); 
805                           writeoutput(" ",NOFREE);/*Feb18,1992 added by Attila*/
806                           ImportStruct=FALSE;
807                           $$=GetYSN();
808                           dummy=FindInTable(CurrentTable,$2->string,&i);
809                           if (i==0) 
810                                 worksymtab=dummy;
811                           else  { worksymtab=LocalFind($2->string);
812                                   if ((worksymtab==NULL)||
813                                       (worksymtab->idtype!=ENUMNAME))
814                                         { worksymtab =
815                                                 Insert($2->string,CurrentTable);
816                                           worksymtab->type=GetTypeNode(0,1);
817                                           worksymtab->idtype=ENUMNAME;
818                                           worksymtab->declflag=NOTDECLARED;
819                                           worksymtab->type->declflag=NOTDECLARED;
820                                           worksymtab->type->type=NULL;
821                                         }
822                                 }
823                                   
824                           if (worksymtab->idtype!=ENUMNAME)
825                                 error("Bad Struct Name",EXIT);
826                           $$->type=worksymtab->type; 
827                           DestroyString($2->string);dontfree($2);
828                         }
829                 | Enum IDENTIFIER { if (IMPORTFLAG) ImportStruct=TRUE;
830                                       if (ImportStruct)
831                                                 writeoutput(Map(CurrentModule->name,"_CKTYPE",$2->string),NOFREE); 
832                                       else      writeoutput($2->string,NOFREE); 
833                                       writeoutput(" ",NOFREE); /* Feb 18,1992*/
834                                       ImportStruct=FALSE;
835                                     }
836                   enum_rest 
837                         { SYMTABPTR dummy,temp;int i;TYPEPTR type;
838
839                           dummy=FindInTable(CurrentTable,$2->string,&i);
840                           if (i!=0) 
841                                 { worksymtab=Insert($2->string,CurrentTable);
842                                   worksymtab->type=GetTypeNode(1,0);
843                                 }
844                           else  { if ((dummy->declflag!=NOTDECLARED) ||
845                                         (dummy->idtype!=ENUMNAME))
846                                         error("Bad Struct Name",EXIT);
847                                   worksymtab=dummy;
848                                   type=GetTypeNode(1+worksymtab->type->count,0);
849                                   dummy=(SYMTABPTR)worksymtab->type->type;
850                                   while (dummy!=NULL)
851                                         { temp=(SYMTABPTR)dummy;
852                                           dummy->type=type;dummy=temp;
853                                           /* this is an infinite loop */
854                                           /* set dummy to NULL */
855                                           dummy = NULL;
856                                         }
857                                   dontfree(worksymtab->type);
858                                   worksymtab->type=type;
859                                 }
860         
861                           worksymtab->type->basictype=ENUMTYPE;
862                           worksymtab->idtype=ENUMNAME;
863                           worksymtab->declflag=DECLARED;
864                           worksymtab->type->table=$4->table;
865                           $$=GetYSN();$$->type=worksymtab->type;
866                           DestroyString($2->string);dontfree($2);dontfree($4);
867                         }
868                 ;
869
870 module_init_decl        : {$$=GetYSN();}
871                         ;
872
873 /*                                      */
874
875
876
877
878 decl_specs      : type_spec             { $$=$1; }
879                 | sc_spec               {$$=GetYSN();$$->type=DUMMYPTR;}
880                 | type_spec sc_spec     { $$=$1; }
881                 | sc_spec type_spec     { $$=$2; }
882                 ;
883
884 sc_spec         : AUTO 
885                 | STATIC
886                 | REGISTER
887                 | CONST
888                 ;
889
890 mod_declaration : decl_specs init_decl_list semicolon
891                           { SetIdList($1->type,$2->listptr,VARNAME,0);
892                             dontfree($2);dontfree($1);
893                           }
894                 | TypeDef init_decl_list semicolon
895                           { SetIdList(DUMMYPTR,$2->listptr,TYPENAME,0);
896                             dontfree($2);
897                           }
898                 | TypeDef type_spec init_decl_list semicolon
899                           { SetIdList($2->type,$3->listptr,TYPENAME,0);
900                             dontfree($2);dontfree($3);
901                           }
902                 | EXTERN type_spec mopt ext_list semicolon
903                 | EXTERN ext_list semicolon
904                 ;
905
906 declaration     : mod_declaration
907                 | privpub       { StoredEPFlag=PRIVATEFLAG;
908                                   PRIVATEFLAG=FALSE; 
909                                   INSIDE_PRIVFUNC_PROTO=1;}
910                   function_decl semicolon
911                           { $3->table->idtype=$1->idtype; dontfree($3); 
912                             PopStack(FREE);PopStack(FREE);dontfree($1);
913                             PRIVATEFLAG=StoredEPFlag;
914                             INSIDE_PRIVFUNC_PROTO=0;
915                           }
916                 ;
917
918 system_types    : CHAR          { $$=$1; $$->type=CHARPTR; }
919                 | UNSIGNED CHAR { $$=$1; $$->type=CHARPTR;
920                                   CreateUnsignedTerm(&($$->string),$2->string);
921                                 }
922                 | SIGNED CHAR { $$=$1; $$->type=CHARPTR;
923                                   CreateUnsignedTerm(&($$->string),$2->string);
924                                 }
925                 | SHORT         { $$=$1; $$->type=SHORTPTR; }
926                 | UNSIGNED SHORT{ $$=$1; $$->type=SHORTPTR; 
927                                   CreateUnsignedTerm(&($$->string), $2->string);                                }
928                 | SIGNED SHORT{ $$=$1; $$->type=SHORTPTR; 
929                                   CreateUnsignedTerm(&($$->string), $2->string);                                }
930                 | INT           { $$=$1; $$->type=INTPTR; }
931                 | LONG          { $$=$1; $$->type=LONGPTR; }
932                 | UNSIGNED LONG { $$=$1; $$->type=LONGPTR; 
933                                   CreateUnsignedTerm(&($$->string), $2->string);                                }
934                 | SIGNED LONG { $$=$1; $$->type=LONGPTR; 
935                                   CreateUnsignedTerm(&($$->string), $2->string);                                }
936                 | SIGNED INT { $$=$1; $$->type=INTPTR; 
937                                   CreateUnsignedTerm(&($$->string), $2->string);                                }
938                 | DOUBLE        { $$=$1; $$->type=DOUBLEPTR; }
939                 | FLOAT         { $$=$1; $$->type=FLOATPTR; }
940                 | UNSIGNED      { $$=$1; $$->type=UNSIGNEDPTR; }
941                 | SHORT INT     { $$=$1; $$->type=SHORTPTR; 
942                                   CreateUnsignedTerm(&($$->string), $2->string);                                }
943                 | LONG INT      { $$=$1; $$->type=LONGPTR; 
944                                   CreateUnsignedTerm(&($$->string), $2->string);                                }
945                 | LONG LONG     { $$=$1; $$->type=LONGPTR; 
946                                   CreateUnsignedTerm(&($$->string), $2->string);                                }
947                 | LONG FLOAT    { $$=$1; $$->type=DOUBLEPTR; 
948                                   CreateUnsignedTerm(&($$->string), $2->string);                                }
949                 | LONG DOUBLE   { $$=$1; $$->type=DOUBLEPTR; 
950                                   CreateUnsignedTerm(&($$->string), $2->string);                                }
951                 | UNSIGNED INT  { $$=$1; $$->type=UNSIGNEDPTR; 
952                                   CreateUnsignedTerm(&($$->string), $2->string);                                }
953                 | UNSIGNED INT INT { $$=$1;  $$->type=UNSIGNEDPTR;
954                                   CreateUnsignedTerm2(&($$->string), $2->string,$3->string);
955                                 }
956                 | UNSIGNED LONG LONG { $$=$1;  $$->type=UNSIGNEDPTR;
957                                   CreateUnsignedTerm2(&($$->string), $2->string,$3->string);
958                                 }
959                 | UNSIGNED LONG INT { $$=$1;  $$->type=UNSIGNEDPTR;
960                                   CreateUnsignedTerm2(&($$->string), $2->string,$3->string);
961                                 }
962                 | VOID          { $$=$1; $$->type=VOIDPTR; }
963                 | ChareIDType   { $$=$1; $$->type=CHAREIDPTR; }
964                 | EntryPointType { $$=$1; $$->type=ENTRYPOINTPTR; }
965                 | PeNumType     { $$=$1; $$->type=PENUMPTR; }
966                 | PackIDType    { $$=$1; $$->type=PACKIDPTR; }
967                 | WriteOnceID   { $$=$1; $$->type=WRITEONCEIDPTR; }
968                 | PVECTOR       { $$=$1; $$->type=PVECTORPTR; }
969                 | ChareNameType { $$=$1; $$->type=CHARENAMEPTR; }
970                 | ChareNumType  { $$=$1; $$->type=CHARENUMPTR; }
971                 | EntryNumType  { $$=$1; $$->type=ENTRYNUMPTR; }
972                 | BOOLEAN       { $$=$1; $$->type=BOOLEANPTR; }
973                 | ACCIDTYPE     { $$=$1; $$->type=INTPTR; /* TO SIMPLIFY */}
974                 | MONOIDTYPE    { $$=$1; $$->type=INTPTR; }
975                 | DUMMYMSG      { $$=$1; $$->type=INTPTR; }
976                 | FunctionRefType { $$=$1; $$->type=FUNCTIONREFPTR; }
977                 | FUNCTION_PTR  { $$=$1; $$->type=FUNCTIONPTR; } 
978                 ;
979
980 type_spec       : su_spec       { $$=$1; }
981                 | typedef_name  { $$=$1; }
982                 ;
983
984 init_decl_list  : init_decl     { $$=GetYSN();$$->listptr=GetListNode($1); }
985                 | init_decl_list comma init_decl
986                           { $$ = $1;
987                             if ($$->listptr==NULL)
988                                 error("Unexpected ','",EXIT);
989                             InsertNode($$->listptr,$3); 
990                           }
991                 |       {  $$=GetYSN(); }
992                 ;
993
994 init_decl       : declarator initializer_opt    { $$=$1; }
995                 ;
996
997 declarator      : IDENTIFIER    { /*writeoutput($1->string,NOFREE);*/
998                         /* When in import, modified if level=0 : see lex.c */
999                                 /*  if ((IMPORTFLAG)&&(ImportLevel==0)) */
1000                                 /*  Dec 30, 1991, modified by Attila */
1001                                   if ((IMPORTFLAG)&&(ImportLevel==0)
1002                                       && (!IMPORTMSGFLAG) )
1003                                   writeoutput(Map(CurrentModule->name,"0",
1004                                                         $1->string),NOFREE);
1005                                   else writeoutput($1->string,NOFREE);
1006                                   $$=$1;
1007                                 }
1008                 | lparen declarator rparen      %prec L_PAREN
1009                         { $$=$2; }
1010                 | MULT {dump("*");} declarator  
1011                         { YSNPTR dummy;
1012                           
1013                           $$=$3;dummy=$$;
1014                           while (dummy->ysn!=NULL) dummy=dummy->ysn;
1015                           dummy->ysn=GetYSN();dummy->ysn->idtype=POINTERTYPE;
1016                         }
1017                 | declarator lparen rparen      %prec L_PAREN
1018                         { YSNPTR dummy;
1019                           
1020                           $$=$1;dummy=$$;
1021                           while (dummy->ysn!=NULL) dummy=dummy->ysn;
1022                           dummy->ysn=GetYSN();dummy->ysn->idtype=FUNCTIONTYPE;
1023                         }  
1024                 | declarator lsquare rsquare    %prec L_SQUARE
1025                         { YSNPTR dummy;
1026                           
1027                           $$=$1;dummy=$$;
1028                           while (dummy->ysn!=NULL) dummy=dummy->ysn;
1029                           dummy->ysn=GetYSN();dummy->ysn->idtype=ARRAYTYPE;
1030                         }
1031                 | declarator lsquare expression rsquare %prec L_SQUARE
1032                         { YSNPTR dummy;
1033                           
1034                           $$=$1;dummy=$$;
1035                           while (dummy->ysn!=NULL) dummy=dummy->ysn;
1036                           dummy->ysn=GetYSN();dummy->ysn->idtype=ARRAYTYPE;
1037                         }
1038                 ;
1039
1040 su_spec         : Struct su_rest
1041                         { $$=GetYSN();
1042                           $$->type=GetTypeNode(0,0);
1043                           $$->type->basictype=STRUCTTYPE;
1044                           $$->type->table=$2->table;
1045                           dontfree($2);
1046                         }       
1047                 | Struct TYPE_OR_ID 
1048                         { SYMTABPTR dummy; int i;
1049
1050                           if (IMPORTFLAG) ImportStruct=TRUE;
1051                           if (!ImportStruct)
1052                                 writeoutput($2->string,NOFREE);  
1053                           else  writeoutput(Map(CurrentModule->name,"_CKTYPE",$2->string),NOFREE); 
1054                           writeoutput(" ",NOFREE);/*Feb18,1992 added by Attila*/
1055                           ImportStruct=FALSE;
1056                           $$=GetYSN();
1057                           dummy=FindInTable(CurrentTable,$2->string,&i);
1058                           if (i==0) 
1059                                 worksymtab=dummy;
1060                           else  { worksymtab=LocalFind($2->string);
1061                                   if ((worksymtab==NULL)||(worksymtab->idtype!=STRUCTNAME))
1062                                         { worksymtab =
1063                                                 Insert($2->string,CurrentTable);
1064                                           worksymtab->type=GetTypeNode(0,1);
1065                                           worksymtab->idtype=STRUCTNAME;
1066                                           worksymtab->declflag=NOTDECLARED;
1067                                           worksymtab->type->declflag=NOTDECLARED;
1068                                           worksymtab->type->type=NULL;
1069                                         }
1070                                 }
1071                                   
1072                           if (worksymtab->idtype!=STRUCTNAME)
1073                                 error("Bad Struct Name",EXIT);
1074                           $$->type=worksymtab->type; 
1075                           DestroyString($2->string);dontfree($2);
1076                         }
1077                 | Struct IDENTIFIER { if (IMPORTFLAG) ImportStruct=TRUE;
1078                                       if (ImportStruct)
1079                                                 writeoutput(Map(CurrentModule->name,"_CKTYPE",$2->string),NOFREE); 
1080                                       else      writeoutput($2->string,NOFREE); 
1081                                       writeoutput(" ",NOFREE); /* Feb 18,1992*/
1082                                       ImportStruct=FALSE;
1083                                     }
1084                   su_rest
1085                         { SYMTABPTR dummy,temp;int i;TYPEPTR type;
1086
1087                           dummy=FindInTable(CurrentTable,$2->string,&i);
1088                           if (i!=0) 
1089                                 { worksymtab=Insert($2->string,CurrentTable);
1090                                   worksymtab->type=GetTypeNode(1,0);
1091                                 }
1092                           else  { if ((dummy->declflag!=NOTDECLARED) ||
1093                                         (dummy->idtype!=STRUCTNAME))
1094                                         error("Bad Struct Name",EXIT);
1095                                   worksymtab=dummy;
1096                                   type=GetTypeNode(1+worksymtab->type->count,0);
1097                                   dummy=(SYMTABPTR)worksymtab->type->type;
1098                                   while (dummy!=NULL)
1099                                         { temp=(SYMTABPTR)dummy;
1100                                           dummy->type=type;dummy=temp;
1101                                           /* this is an infinite loop */
1102                                           /* set dummy to NULL */
1103                                           dummy = NULL;
1104                                         }
1105                                   dontfree(worksymtab->type);
1106                                   worksymtab->type=type;
1107                                 }
1108         
1109                           worksymtab->type->basictype=STRUCTTYPE;
1110                           worksymtab->idtype=STRUCTNAME;
1111                           worksymtab->declflag=DECLARED;
1112                           worksymtab->type->table=$4->table;
1113                           $$=GetYSN();$$->type=worksymtab->type;
1114                           DestroyString($2->string);dontfree($2);dontfree($4);
1115                         }
1116                 | Union su_rest
1117                         { 
1118                           { $$=GetYSN();
1119                           $$->type=GetTypeNode(0,0);
1120                           $$->type->basictype=UNIONTYPE;
1121                           $$->type->table=$2->table;
1122                           dontfree($2);
1123                           }
1124                         }       
1125                 | Union IDENTIFIER
1126                         { SYMTABPTR dummy; int i;
1127
1128                           if (IMPORTFLAG) ImportStruct=TRUE;
1129                           if (ImportStruct)
1130                                 writeoutput(Map(CurrentModule->name,"_CKTYPE",$2->string),NOFREE); 
1131                           else  writeoutput($2->string,NOFREE);  
1132                           writeoutput(" ",NOFREE); /* Feb 18 1992 */
1133                           ImportStruct=FALSE;
1134                           $$=GetYSN();
1135                           dummy=FindInTable(CurrentTable,$2->string,&i);
1136                           if (i==0) 
1137                                 worksymtab=dummy;
1138                           else  { worksymtab=LocalFind($2->string);
1139                                   if ((worksymtab==NULL)||(worksymtab->idtype!=UNIONNAME))
1140                                         { worksymtab =
1141                                                 Insert($2->string,CurrentTable);
1142                                           worksymtab->type=GetTypeNode(0,1);
1143                                           worksymtab->idtype=UNIONNAME;
1144                                           worksymtab->declflag=NOTDECLARED;
1145                                           worksymtab->type->declflag=NOTDECLARED;
1146                                           worksymtab->type->type=NULL;
1147                                         }
1148                                 }
1149                                   
1150                           if (worksymtab->idtype!=UNIONNAME)
1151                                 error("Bad Struct Name",EXIT);
1152                           $$->type=worksymtab->type; 
1153                           DestroyString($2->string);dontfree($2);
1154                         }
1155                 | Union IDENTIFIER      { if (IMPORTFLAG) ImportStruct=TRUE;
1156                                           if (ImportStruct)
1157                                                 writeoutput(Map(CurrentModule->name,"_CKTYPE",$2->string),NOFREE); 
1158                                           else  writeoutput($2->string,NOFREE); 
1159                                           writeoutput(" ",NOFREE);/*Feb18 1992*/
1160                                           ImportStruct=FALSE;
1161                                         }
1162                   su_rest
1163                         { SYMTABPTR dummy,temp;int i;TYPEPTR type;
1164
1165                           
1166                           {
1167                           dummy=FindInTable(CurrentTable,$2->string,&i);
1168                           if (i!=0) 
1169                                 { worksymtab=Insert($2->string,CurrentTable);
1170                                   worksymtab->type=GetTypeNode(1,0);
1171                                 }
1172                           else  { if ((dummy->declflag!=NOTDECLARED) ||
1173                                         (dummy->idtype!=UNIONNAME))
1174                                         error("Bad Struct Name",EXIT);
1175                                   worksymtab=dummy;
1176                                   type=GetTypeNode(1+worksymtab->type->count,0);
1177                                   dummy=(SYMTABPTR)worksymtab->type->type;
1178                                   while (dummy!=NULL)
1179                                         { temp=(SYMTABPTR)dummy;
1180                                           dummy->type=type;dummy=temp;
1181                                           /* this is an infinite loop */
1182                                           /* set dummy to NULL */
1183                                           dummy = NULL;
1184                                         }
1185                                   dontfree(worksymtab->type);
1186                                   worksymtab->type=type;
1187                                 }
1188         
1189                           worksymtab->type->basictype=UNIONTYPE;
1190                           worksymtab->idtype=UNIONNAME;
1191                           worksymtab->declflag=DECLARED;
1192                           worksymtab->type->table=$4->table;
1193                           $$=GetYSN();$$->type=worksymtab->type;
1194                           DestroyString($2->string);dontfree($2);dontfree($4); 
1195                           }
1196                         }
1197
1198                 | Enum enum_rest
1199                         { $$=GetYSN();
1200                           $$->type=GetTypeNode(0,0);
1201                           $$->type->basictype=STRUCTTYPE;
1202                           $$->type->table=$2->table;
1203                           dontfree($2);
1204                         }       
1205                 | Enum IDENTIFIER 
1206                         { SYMTABPTR dummy; int i;
1207
1208                           if (IMPORTFLAG) ImportStruct=TRUE;
1209                           if (!ImportStruct)
1210                                 writeoutput($2->string,NOFREE);  
1211                           else  writeoutput(Map(CurrentModule->name,"_CKTYPE",$2->string),NOFREE); 
1212                           writeoutput(" ",NOFREE);/*Feb18,1992 added by Attila*/
1213                           ImportStruct=FALSE;
1214                           $$=GetYSN();
1215                           dummy=FindInTable(CurrentTable,$2->string,&i);
1216                           if (i==0) 
1217                                 worksymtab=dummy;
1218                           else  { worksymtab=LocalFind($2->string);
1219                                   if ((worksymtab==NULL)||
1220                                       (worksymtab->idtype!=ENUMNAME))
1221                                         { worksymtab =
1222                                                 Insert($2->string,CurrentTable);
1223                                           worksymtab->type=GetTypeNode(0,1);
1224                                           worksymtab->idtype=ENUMNAME;
1225                                           worksymtab->declflag=NOTDECLARED;
1226                                           worksymtab->type->declflag=NOTDECLARED;
1227                                           worksymtab->type->type=NULL;
1228                                         }
1229                                 }
1230                                   
1231                           if (worksymtab->idtype!=ENUMNAME)
1232                                 error("Bad Struct Name",EXIT);
1233                           $$->type=worksymtab->type; 
1234                           DestroyString($2->string);dontfree($2);
1235                         }
1236                 | Enum IDENTIFIER { if (IMPORTFLAG) ImportStruct=TRUE;
1237                                       if (ImportStruct)
1238                                                 writeoutput(Map(CurrentModule->name,"_CKTYPE",$2->string),NOFREE); 
1239                                       else      writeoutput($2->string,NOFREE); 
1240                                       writeoutput(" ",NOFREE); /* Feb 18,1992*/
1241                                       ImportStruct=FALSE;
1242                                     }
1243                   enum_rest 
1244                         { SYMTABPTR dummy,temp;int i;TYPEPTR type;
1245
1246                           dummy=FindInTable(CurrentTable,$2->string,&i);
1247                           if (i!=0) 
1248                                 { worksymtab=Insert($2->string,CurrentTable);
1249                                   worksymtab->type=GetTypeNode(1,0);
1250                                 }
1251                           else  { if ((dummy->declflag!=NOTDECLARED) ||
1252                                         (dummy->idtype!=ENUMNAME))
1253                                         error("Bad Struct Name",EXIT);
1254                                   worksymtab=dummy;
1255                                   type=GetTypeNode(1+worksymtab->type->count,0);
1256                                   dummy=(SYMTABPTR)worksymtab->type->type;
1257                                   while (dummy!=NULL)
1258                                         { temp=(SYMTABPTR)dummy;
1259                                           dummy->type=type;dummy=temp;
1260                                           /* this is an infinite loop */
1261                                           /* set dummy to NULL */
1262                                           dummy = NULL;
1263                                         }
1264                                   dontfree(worksymtab->type);
1265                                   worksymtab->type=type;
1266                                 }
1267         
1268                           worksymtab->type->basictype=ENUMTYPE;
1269                           worksymtab->idtype=ENUMNAME;
1270                           worksymtab->declflag=DECLARED;
1271                           worksymtab->type->table=$4->table;
1272                           $$=GetYSN();$$->type=worksymtab->type;
1273                           DestroyString($2->string);dontfree($2);dontfree($4);
1274                         }
1275                 ;
1276
1277
1278 TYPE_OR_ID      : IDENTIFIER
1279                 | TYPE_IDENTIFIER
1280                 ;
1281
1282 su_rest         : L_BRACE       { if (IMPORTFLAG) ImportLevel++; 
1283                                   writeoutput("{",NOFREE); PushStack(); 
1284                                 }
1285                   s_decl_list R_BRACE   
1286                         { writeoutput("}",NOFREE); 
1287                           $$=GetYSN(); $$->table=CurrentTable;
1288                           PopStack(NOFREE);RestoreCurrentTable();
1289                           if (IMPORTFLAG) ImportLevel--;
1290                         }
1291                 ;
1292
1293 s_decl_list     : struct_decl
1294                 | s_decl_list struct_decl
1295                 ;
1296
1297 struct_decl     : type_spec s_declarator_list semicolon
1298                         { SetIdList($1->type,$2->listptr,FIELDNAME,0);
1299                           dontfree($2);dontfree($1);
1300                         }
1301                 ;
1302
1303 s_declarator_list       : s_declarator  { $$=GetYSN();
1304                                           $$->listptr=GetListNode($1);
1305                                         }
1306                 | s_declarator_list comma s_declarator
1307                         { $$=$1;InsertNode($$->listptr,$3); }
1308                 ;
1309
1310 s_declarator    : declarator                    { $$=$1; }
1311                 | declarator colon const_exp    { $$=$1; }
1312                 | colon const_exp               {  $$=GetYSN(); } 
1313                 ;
1314
1315
1316
1317
1318 enum_rest       : L_BRACE       { if (IMPORTFLAG) ImportLevel++; 
1319                                   writeoutput("{",NOFREE);
1320                                 }
1321                   enum_opt enum_list R_BRACE    
1322                         { 
1323                           SetIdList($3->type,$4->listptr,VARNAME,0);
1324                           writeoutput("}",NOFREE); 
1325                           $$=GetYSN(); $$->table=CurrentTable;
1326                           if (IMPORTFLAG) ImportLevel--;
1327                         }
1328                 ;
1329
1330 enum_opt        : {$$=GetYSN(); $$->type = INTPTR;}
1331
1332 enum_list       : enum_member { $$ = GetYSN(); $$->listptr=GetListNode($1);}
1333                 | enum_list comma enum_member
1334                       { $$ = $1;
1335                         if ($$->listptr==NULL)
1336                            error("error in enum definition ",EXIT);
1337                         InsertNode($$->listptr,$3);
1338                       } 
1339
1340 enum_member     : IDENTIFIER
1341                     { writeoutput($1->string,NOFREE);
1342                       writeoutput(" ",NOFREE);
1343                       $$ = $1;
1344                     } 
1345                 | IDENTIFIER 
1346                     {  writeoutput($1->string,NOFREE);
1347                        writeoutput(" ",NOFREE);  
1348                        $$ = $1;
1349                     }
1350                   equal base_expression
1351                 ;
1352
1353 initializer_opt :
1354                 | initializer
1355                 ;
1356
1357 initializer     : equal expression
1358                 | equal L_BRACE         {  
1359                                                 writeoutput("{",NOFREE); }
1360                   init_rest
1361                 ;
1362
1363 init_rest       : initializer_list R_BRACE      { 
1364                                                       writeoutput("}",NOFREE); }
1365                 | initializer_list comma_R_BRACE
1366                 ;
1367
1368 initializer_list        : expression
1369                         | initializer_list comma_L_BRACE initializer_list 
1370                           R_BRACE               { 
1371                                                      writeoutput("}",NOFREE); }
1372                         | L_BRACE               { 
1373                                                      writeoutput("{",NOFREE); }
1374                           initializer_list R_BRACE
1375                                 {  writeoutput("}",NOFREE); }
1376                         ;
1377
1378
1379 typename        : type_spec abstract_decl { 
1380                                             { FreeType($1->type);dontfree($1); }
1381                                           }
1382                 ;
1383
1384 abstract_decl   :
1385                 | lparen abstract_decl rparen   %prec L_PAREN
1386                 | MULT {dump("*");} abstract_decl
1387                 | abstract_decl lparen rparen   %prec L_PAREN
1388                 | abstract_decl lsquare rsquare %prec L_SQUARE
1389                 | abstract_decl lsquare expression rsquare %prec L_SQUARE
1390                 ;
1391
1392 typedef_name    : TYPE_IDENTIFIER       
1393                         { TYPEPTR typeptr;
1394
1395                           worksymtab=LocalFind($1->string);typeptr=NULL;
1396                           if (IMPORTFLAG)
1397                          /* it is a type id : MUST be at level 0 */
1398                                 { writeoutput(Map(CurrentModule->name,"0",
1399                                         $1->string),NOFREE);
1400                                   if ((worksymtab==NULL)||
1401                 /*                      (worksymtab->idtype!=TYPENAME)) */
1402                 /*  Dec 31, Attila */
1403                                         ((worksymtab->idtype!=TYPENAME) && 
1404                                         (worksymtab->idtype!=MESSAGENAME)))
1405                                         error("Bad Type Reference",EXIT);
1406                                   else  typeptr=worksymtab->type;
1407                                 }
1408                           else  /* writeoutput($1->string,NOFREE); */
1409                                 typeptr=ProcessTypeIdentifier($1);
1410                           $$=GetYSN();$$->type=typeptr;
1411                           $$->table=($1->modstring==NULL)?GlobalFind($1->string)
1412                                 :GlobalModuleSearch($1->string,$1->modstring);
1413                           DestroyString($1->modstring);
1414                           DestroyString($1->string);dontfree($1);
1415                         }
1416                 | system_types  { $$=$1;writeoutput($1->string,NOFREE);
1417                                   writeoutput(" ",NOFREE);
1418                                   $$->table=$$->type->table; }
1419                 ;
1420
1421 base_expression : primary
1422                 | unary  base_expression %prec UNARY
1423                 | SIZEOF lparen typedef_name rparen     %prec UNARY 
1424                 | SIZEOF base_expression        %prec UNARY
1425                 | lparen typename rparen base_expression %prec UNARY
1426                 | base_expression MULTDIV base_expression %prec MULT
1427                 | base_expression ADDSUB base_expression %prec PLUS
1428                 | base_expression shift base_expression %prec SHIFT
1429                 | base_expression compare base_expression       %prec COMPARE
1430                 | base_expression equalequal base_expression    %prec EQUALEQUAL
1431                 | base_expression notequal base_expression      %prec NOTEQUAL
1432                 | base_expression AND {dump("&");} base_expression
1433                 | base_expression HAT {dump("^");} base_expression
1434                 | base_expression OR { dump("|"); } base_expression
1435                 | base_expression ANDAND { dump("&&"); } base_expression
1436                 | base_expression OROR {dump("||");} base_expression
1437                 | base_expression QUESTION {dump("?");} base_expression colon base_expression
1438                 | primary asgnop base_expression        %prec ASGNOP
1439                 | primary equal base_expression %prec EQUAL
1440                 ;
1441 CKPRIO_L        : CKALLOCPRIOMSG L_PAREN
1442                 ;
1443
1444 CK_L            : CKALLOCMSG L_PAREN
1445                 ;
1446
1447 expression      : primary
1448                 | unary  expression %prec UNARY
1449                 | SIZEOF lparen typedef_name rparen     %prec UNARY 
1450                 | SIZEOF expression     %prec UNARY
1451                 | lparen typename rparen expression %prec UNARY
1452                 | expression MULTDIV expression %prec MULT
1453                 | expression ADDSUB expression %prec PLUS
1454                 | expression shift expression   %prec SHIFT
1455                 | expression compare expression %prec COMPARE
1456                 | expression equalequal expression      %prec EQUALEQUAL
1457                 | expression notequal expression        %prec NOTEQUAL
1458                 | expression AND {dump("&");} expression
1459                 | expression HAT {dump("^");} expression
1460                 | expression OR { dump("|"); } expression
1461                 | expression ANDAND { dump("&&"); } expression
1462                 | expression OROR {dump("||");} expression
1463                 | expression QUESTION {dump("?");} expression colon expression
1464                 | primary asgnop expression     %prec ASGNOP
1465                 | primary equal expression      %prec EQUAL
1466                 | expression COMMA { dump(","); } expression
1467                 | PRIVATECALL lparen IDENTIFIER 
1468                         { if (!InPass1)
1469                           { worksymtab=GlobalFind($3->string);
1470                           DestroyString($3->string);dontfree($3);
1471                           if ((worksymtab==NULL)||(worksymtab->idtype!=
1472                                         PRIVATEFNNAME))
1473                                 if (!InPass1)
1474                                         error("Bad Private Call",EXIT);
1475                           if (!InPass1)
1476                                 writeoutput(Map(CurrentModule->name,
1477                                 CurrentChare->name,worksymtab->name),NOFREE);
1478                           }
1479                         } 
1480                   lparen
1481                         {  
1482                                 writeoutput(CkLocalPtr,NOFREE);
1483                         }
1484                   expression_opt rparen rparen
1485                 | BRANCHCALL lparen { BUFFEROUTPUT=TRUE; }
1486                   base_expression   { BUFFEROUTPUT=FALSE; }
1487                   COMMA ck_primary lparen
1488                         { writeoutput("GetBocDataPtr(",NOFREE);
1489                           writeoutput(buffer.a,NOFREE);buffer.count=0;
1490                           writeoutput(")",NOFREE);
1491                         }
1492                   expression_opt rparen rparen
1493                 | CHARECALL lparen {  BUFFEROUTPUT=TRUE; }
1494                   base_expression {  BUFFEROUTPUT=FALSE; }
1495                   COMMA ck_primary lparen
1496                         { writeoutput("GetChareDataPtr(",NOFREE);
1497                           writeoutput(buffer.a,NOFREE);buffer.count=0;
1498                           writeoutput(")",NOFREE); 
1499                         }
1500                   expression_opt rparen rparen
1501                 | FNNAMETOREF L_PAREN   { FNNAMETOREFFLAG=TRUE; }
1502                   ck_primary R_PAREN    { FNNAMETOREFFLAG=FALSE; } 
1503                   /*semicolon */ /* Jan 16, 1992 Attila */
1504                 /* following rule added, Jan 16 1992, by Attila */
1505                 | FNREFTONAME L_PAREN   {
1506                     FNREFTONAMEFLAG = TRUE;
1507                     writeoutput("CsvAccess(_CK_9_GlobalFunctionTable)[",NOFREE);
1508                     }
1509                   expression R_PAREN    { 
1510                     writeoutput("]",NOFREE);
1511                     FNREFTONAMEFLAG=FALSE; 
1512                     } 
1513                 | CK_L IDENTIFIER ckallocrest
1514                         { if (!InPass1)
1515                                 { error("Bad Message Type",EXIT); }
1516                         }
1517                 | CK_L TYPE_IDENTIFIER 
1518                         { if (!InPass1)
1519
1520 /** I changed LocalFind to GlobalFind on Oct. 27, 1991. The same change
1521     has been made in Prio.. I hope it works!
1522 **/
1523
1524                           {worksymtab=($2->modstring==NULL)?GlobalFind($2->string):GlobalModuleSearch($2->string,$2->modstring);
1525                           if ((worksymtab==NULL)||(worksymtab->idtype!=MESSAGENAME))
1526                                 error("Bad Message Type",NOEXIT);
1527                           else  {
1528
1529                                   if (strcmp(CurrentModule->name,worksymtab->modname->name))
1530                                         SavedName=ModulePrefix(worksymtab->modname->name,worksymtab->name);
1531                                   else  SavedName=MyModulePrefix(worksymtab->modname->name,worksymtab->name);
1532                                   if (worksymtab->localid<=0) {
1533                                         writeoutput(CkGenericAlloc,NOFREE); 
1534                                   }
1535                                   else  { 
1536                                         writeoutput("(",NOFREE);
1537                                         writeoutput(CkVarSizeAlloc,NOFREE); 
1538                                         writeoutput("[",NOFREE);
1539                                         writeoutput(SavedName,NOFREE);
1540                                         writeoutput("].alloc)",NOFREE);
1541                                   }
1542                                   writeoutput("(",NOFREE);
1543                                   writeoutput(SavedName,FREE);
1544                                   writeoutput(",",NOFREE);
1545                                   writeoutput("sizeof(",NOFREE);
1546                                   if (strcmp(CurrentModule->name,worksymtab->modname->name))
1547                                         SavedName=Map(worksymtab->modname->name,"0",worksymtab->name);
1548                                   else  SavedName=worksymtab->name;
1549                                   writeoutput(SavedName,NOFREE);
1550                                   writeoutput("),0",NOFREE);
1551                                 }
1552                          }
1553                         }
1554                   ckallocrest
1555                 | CKPRIO_L TYPE_IDENTIFIER COMMA
1556                         { if (!InPass1)
1557                           {worksymtab=($2->modstring==NULL)?GlobalFind($2->string):GlobalModuleSearch($2->string,$2->modstring);
1558                           if ((worksymtab==NULL)||(worksymtab->idtype!=MESSAGENAME))
1559                                 error("Bad Message Type",NOEXIT);
1560                           else  {
1561                                   if (strcmp(CurrentModule->name,worksymtab->modname->name))
1562                                         SavedName=ModulePrefix(worksymtab->modname->name,worksymtab->name);
1563                                   else  SavedName=MyModulePrefix(worksymtab->modname->name,worksymtab->name);
1564                                    if (worksymtab->localid<=0) {
1565                                                 writeoutput(CkGenericAlloc,NOFREE); 
1566                                   }
1567                                   else  {
1568                                         writeoutput("(",NOFREE);
1569                                         writeoutput(CkVarSizeAlloc,NOFREE); 
1570                                         writeoutput("[",NOFREE);
1571                                         writeoutput(SavedName,NOFREE);
1572                                         writeoutput("].alloc)",NOFREE);
1573                                   }
1574                                   writeoutput("(",NOFREE);
1575                                   writeoutput(SavedName,FREE);
1576                                   writeoutput(",",NOFREE);
1577                                   writeoutput("sizeof(",NOFREE);
1578                                   if (strcmp(CurrentModule->name,worksymtab->modname->name))
1579                                         SavedName=Map(worksymtab->modname->name,"0",worksymtab->name);
1580                                   else  SavedName=worksymtab->name;
1581                                   writeoutput(SavedName,NOFREE);
1582                                   writeoutput("),",NOFREE);
1583                                 }
1584                           }
1585                         }
1586                   base_expression ckallocrest
1587                 | CKPRIO_L IDENTIFIER COMMA
1588                   base_expression ckallocrest
1589                         { if (!InPass1)
1590                                 { error("Bad Message Type",EXIT); }
1591                         }
1592                 | READMSGINIT { READMSGINITFLAG=TRUE; } 
1593                   lparen ck_primary rparen 
1594                         { READMSGINITFLAG=FALSE; }
1595                 | ACCUMULATE L_PAREN    { BUFFEROUTPUT = TRUE; }
1596                   base_expression COMMA
1597                         { BUFFEROUTPUT = FALSE;
1598                           writeoutput("\n{ _CK_4AccDataAreaType *_CK_4dptr;\n",NOFREE);
1599                           writeoutput("  _CK_4dptr=_CK_9GetAccDataArea(",NOFREE);
1600                           writeoutput(buffer.a,NOFREE);buffer.count=0;
1601                           writeoutput(");\n");
1602                           writeoutput("  _CK_9LockAccDataArea(_CK_4dptr);\n",NOFREE);
1603                           writeoutput("  _CK_9GetAccumulateFn(_CK_4dptr)(_CK_9GetAccDataPtr(_CK_4dptr)",NOFREE);
1604                         }
1605                   IDENTIFIER L_PAREN expression_R_PAREN rparen
1606                         { if (strcmp($7->string,"addfn"))
1607                                 error("addfn expected",EXIT);
1608                           writeoutput(";\n  _CK_9UnlockAccDataArea(_CK_4dptr);\n}\n",NOFREE);
1609                           MULTI_STMT_TR = 1;
1610                         }
1611                 | NEWVALUE L_PAREN      { BUFFEROUTPUT = TRUE; }
1612                   base_expression COMMA
1613                         { BUFFEROUTPUT = FALSE;
1614                           writeoutput("\n{ _CK_4MonoDataAreaType *_CK_4dptr;\n",NOFREE);
1615                           writeoutput("  _CK_4dptr=_CK_9GetMonoDataArea(",NOFREE);
1616                           writeoutput(buffer.a,NOFREE);buffer.count=0;
1617                           writeoutput(");\n");
1618                           writeoutput("  _CK_9LockMonoDataArea(_CK_4dptr);\n",NOFREE);
1619                           /*writeoutput("  _CK_9Mono(_CK_4dptr)(_CK_9GetMonoDataPtr(_CK_4dptr)",NOFREE);*/
1620                           writeoutput("  _CK_9MONO_BranchNewValue(_CK_4dptr",NOFREE);
1621                         }
1622                   IDENTIFIER L_PAREN expression_R_PAREN rparen
1623                         { if (strcmp($7->string,"updatefn"))
1624                                 error("updatefn expected",EXIT);
1625                           writeoutput(";\n  _CK_9UnlockMonoDataArea(_CK_4dptr);\n}\n",NOFREE);
1626                           MULTI_STMT_TR = 1;
1627                         }
1628                 | BLOCKEDRECV 
1629                      {writeoutput("CkBlockedRecv",NOFREE);} 
1630                      lparen
1631                      {
1632                           if ( CurrentChare == NULL )
1633                              error("CkBlockedRecv not allowed here",EXIT);
1634                           else if (CurrentChare->idtype == CHARENAME)
1635                                  writeoutput("NULL,",NOFREE);
1636                           else
1637                                  writeoutput("_CK_4mydata,",NOFREE);
1638                      }
1639                   ck_primary rparen
1640                 ;
1641
1642 expression_R_PAREN : R_PAREN 
1643                 |       { writeoutput(",",NOFREE); }
1644                   expression R_PAREN 
1645                 ;
1646
1647 ckallocrest     : R_PAREN 
1648                         { writeoutput(")",NOFREE); }
1649                 | COMMA { writeoutput(",",NOFREE); }
1650                   base_expression R_PAREN
1651                         { writeoutput(")",NOFREE); }
1652                 ;
1653
1654 expression_opt  :               
1655                 | { writeoutput(",",NOFREE); } expression       
1656                 ;
1657
1658 unary           : MULT          {dump("*");}    
1659                 | AND           {dump("&");}    
1660                 | MINUS         {dump("-");}    
1661                 | TILDE         {dump("~");}    
1662                 | EXCLAIM       {dump("!");}    
1663                 ;
1664 MULTDIV         : MULT          {dump("*");}
1665                 | DIV           {dump("/");}
1666                 | MOD           {dump("%");}
1667                 ;
1668
1669 ADDSUB          : PLUS          {dump("+");}
1670                 | MINUS         {dump("-");}
1671                 ;
1672
1673 primary         : constant 
1674                 | string
1675                 | lparen expression rparen
1676                 | primary lparen rparen                 %prec L_PAREN
1677                 | primary lparen expression rparen      %prec L_PAREN
1678                 | primary lsquare expression rsquare  %prec L_SQUARE
1679                 | primary DOT {dump(".");} IDENTIFIER
1680                         { 
1681                           { writeoutput($4->string,NOFREE);
1682                             DestroyString($4->string);dontfree($4);
1683                           }
1684                         }       
1685                 | primary POINTERREF {dump("->");} IDENTIFIER
1686                         { 
1687                           { writeoutput($4->string,NOFREE);
1688                             DestroyString($4->string);dontfree($4);
1689                           }
1690                         }       
1691                 | incdec primary        %prec INCDEC
1692                 | primary incdec        %prec INCDEC
1693                 | ck_primary
1694                 ;
1695
1696 ck_primary      : IDENTIFIER    { SYMTABPTR dummy;
1697                                   int i;
1698                                   
1699                                   if ((!InPass1)&&(!SpecialVar($1)))
1700                                   { 
1701                                   worksymtab=GlobalFind($1->string);
1702                                   if (worksymtab==NULL)
1703                                         {
1704                                         /*
1705                                         error("Undeclared Identifier: ",NOEXIT);
1706                                         PutOnScreen($1->string);
1707                                         PutOnScreen("\n");
1708                                         */
1709                                         }
1710                                   if (IsFunction(worksymtab))
1711                                         writefunction(worksymtab);
1712                                   else if (IsEntry(worksymtab))
1713                                                 writeentry(worksymtab);
1714                                        else if (IsPublic(worksymtab))
1715                                                 writepublic(worksymtab);
1716                                        else if (IsReadOnly(worksymtab))
1717                                                 writereadonly(worksymtab);
1718                                        else if (IsAccumulator(worksymtab))
1719                                                 writeaccname(worksymtab);
1720                                        else if (IsMonotonic(worksymtab))
1721                                                 writemononame(worksymtab);
1722                                        else if (IsTable(worksymtab))
1723                                                 writetable(worksymtab);
1724                                        else if (IsChare(worksymtab))
1725                                                 writechare(worksymtab);
1726                                        else { if ((worksymtab==NULL) ||
1727                                                   (worksymtab !=
1728                                                   LocalFind(worksymtab->name)))
1729                                              {if (!InPass1)
1730                                                  /*  PutOnScreen($1->string); */
1731                                               {  /*
1732                                                error("Bad Identifier: ",NOEXIT);
1733                                                PutOnScreen($1->string);
1734                                                PutOnScreen("\n"); */  }
1735                                              }
1736                                               if (InChareEnv($1->string,worksymtab))
1737                                                 writeoutput(CkMyData,NOFREE);
1738                                               writeoutput($1->string,NOFREE); 
1739                                             }
1740                                   DestroyString($1->string);dontfree($1);
1741                                   }
1742                                 }
1743                 | ID_DCOLON_ID
1744                         { if (!InPass1)
1745                           { worksymtab=ProcessIdDcolonId($1);
1746                             if (IsReadOnly(worksymtab))
1747                                 writereadonly(worksymtab);
1748                             else if (IsChare(worksymtab))
1749                                         writechare(worksymtab);
1750                                  else if (IsFunction(worksymtab))
1751                                         writefunction(worksymtab);
1752                                       else if (IsAccumulator(worksymtab))
1753                                                 writeaccname(worksymtab);
1754                                            else if (IsMonotonic(worksymtab))
1755                                                     writemononame(worksymtab);
1756                                                 else if (IsTable(worksymtab))
1757                                                         writetable(worksymtab);
1758                                                 else error("Bad Component Ref.",EXIT);
1759                             DestroyString($1->modstring);DestroyString($1->string);dontfree($1);
1760                           }
1761                         }
1762                 | ID_DCOLON_ID AT IDENTIFIER
1763                         { if (!InPass1)
1764                           { worksymtab=ProcessIdDcolonId($1);
1765                             if (!IsChare(worksymtab))
1766                                 error("Bad EP Reference",EXIT);
1767                           sym2=GlobalEntryFind($3->string,$1->string,$1->modstring);
1768                           if (IsPublic(sym2))
1769                                writepublic(sym2);
1770                           else if (IsEntry(sym2))
1771                                     writeentry(sym2);
1772                                else if (IsPrivate(sym2))
1773                                         writeprivate(sym2);
1774                                     else error("Bad Component Ref.",EXIT);
1775                           DestroyString($1->modstring);
1776                           DestroyString($1->string);dontfree($1);
1777                           DestroyString($3->string);dontfree($3);
1778                           }
1779                         }
1780                 | IDENTIFIER AT IDENTIFIER
1781                         { sym1=GlobalFind($1->string);
1782                           sym2=GlobalEntryFind($3->string,$1->string,CurrentModule->name);
1783                           if (!(IsChare(sym1)&&(IsPublic(sym2)||IsEntry(sym2))||IsPrivate(sym2)))
1784                                 error("Bad Reference",NOEXIT);
1785                           else  if (IsPublic(sym2))
1786                                         writepublic(sym2);
1787                                 else if (IsEntry(sym2))
1788                                         writeentry(sym2);
1789                                      else writeprivate(sym2);
1790                           DestroyString($1->string);dontfree($1);
1791                           DestroyString($3->string);dontfree($3);
1792                         }
1793                 ;
1794
1795 compound_statement      : L_BRACE       { 
1796                                           { writeoutput("{",NOFREE);
1797                                             PushStack();
1798                                           }
1799                                         }
1800                           decl_list_opt stmt_list_opt R_BRACE
1801                                         { 
1802                                           { writeoutput("}",NOFREE);
1803                                             PopStack(FREE);
1804                                             RestoreCurrentTable();
1805                                           }
1806                                         }
1807                         ;
1808
1809 decl_list_opt   : 
1810                 | decl_list
1811                 ;
1812
1813 decl_list       : declaration
1814                 | decl_list declaration
1815                 ;
1816
1817 stmt_list_opt   :
1818                 | stmt_list
1819                 ;
1820
1821 stmt_list       : statement
1822                 | stmt_list statement
1823                 ;
1824
1825 statement       : compound_statement
1826                 | expression SEMICOLON 
1827                     {                      /* Feb 18,1991 added by Attila */
1828                       if (MULTI_STMT_TR)   /* Accumulate, Newvalue statements*/ 
1829                          MULTI_STMT_TR = 0;/* are translated into a block.   */
1830                       else                 /* If expression is one of them   */
1831                          writeoutput(";",NOFREE); /* don't print semicolon   */
1832                     }
1833                 | IF lparen expression rparen statement 
1834                 | IF lparen expression rparen statement ELSE statement
1835                 | WHILE lparen expression rparen statement
1836                 | DO statement 
1837                   WHILE lparen expression rparen                
1838                 | FOR lparen exp_opt semicolon exp_opt semicolon
1839                         exp_opt rparen statement
1840                 | SWITCH lparen expression rparen statement
1841                 | CASE expression colon statement
1842                 | DEFAULT colon statement
1843                 | BREAK semicolon
1844                 | CONTINUE semicolon
1845                 | RETURN semicolon
1846                 | RETURN expression semicolon
1847                 | GOTO IDENTIFIER { 
1848                                     { writeoutput($2->string,NOFREE);
1849                                       DestroyString($2->string);dontfree($2);
1850                                     }
1851                                   }
1852                   semicolon 
1853                 | IDENTIFIER      { 
1854                                     writeoutput($1->string,NOFREE);
1855                                     { if (GlobalFind($1->string)!=NULL)
1856                                         error("Bad Label",EXIT);
1857                                       DestroyString($1->string);dontfree($1);
1858                                     }
1859                                   }
1860                   colon statement
1861                 | semicolon
1862                 ;
1863
1864
1865 function_decl   : IDENTIFIER    
1866                         { int i;
1867                           if (export_to_c_flag == 0) {
1868                              if (INSIDE_PRIVFUNC_PROTO ==1)
1869                                 writeoutput(" PROTO_PUB_PRIV ",NOFREE);
1870                              else
1871                                 writeoutput(" static ",NOFREE);
1872                           }
1873                           if (CurrentChare!=NULL)
1874                                 writeoutput(Map(CurrentModule->name,CurrentChare
1875                                                 ->name,$1->string),NOFREE);
1876                           else writeoutput($1->string,NOFREE);
1877                           worksymtab=FindInTable(CurrentTable,$1->string,&i);
1878                           if (i!=0)
1879                                 worksymtab=Insert($1->string,CurrentTable);
1880                           DestroyString($1->string);dontfree($1);
1881                           worksymtab->type=SetType(INTPTR);
1882                           worksymtab->idtype=FNNAME;
1883                           worksymtab->declflag=DECLARED;
1884                           PushStack();
1885                           SavedFnNode=worksymtab;
1886                         }
1887                   lparen 
1888                         { 
1889                              if (PRIVATEFLAG)
1890                                 writeoutput(CkLocalPtr,NOFREE);
1891                         }
1892                   parameter_list_opt rparen
1893                         { 
1894                           { PushStack(); $$=GetYSN();$$->table=SavedFnNode; 
1895                           if (PRIVATEFLAG) {
1896                           WriteReturn();
1897                           writeoutput("void *",NOFREE);
1898                           writeoutput(CkLocalPtr,NOFREE);
1899                           writeoutput(";",NOFREE); }
1900                           }
1901                         }
1902                 | type_spec mopt IDENTIFIER 
1903                         { int i;
1904                           if (export_to_c_flag == 0) {
1905                              if (INSIDE_PRIVFUNC_PROTO==1)
1906                                 writeoutput(" PROTO_PUB_PRIV ",NOFREE);
1907                              else
1908                                 writeoutput(" static ",NOFREE);
1909                           }
1910                           if ($2!=NULL) { writeoutput("*",NOFREE);dontfree($2); }
1911                           if (CurrentChare!=NULL)
1912                                 writeoutput(Map(CurrentModule->name,CurrentChare
1913                                                 ->name,$3->string),NOFREE);
1914                           else writeoutput($3->string,NOFREE);
1915                 /*Attila  worksymtab=FindInTable(CurrentTable,$1->string,&i);*/
1916                           worksymtab=FindInTable(CurrentTable,$3->string,&i);
1917                           if (i!=0)
1918                 /* Attila       worksymtab=Insert($1->string,CurrentTable); */
1919                                 worksymtab=Insert($3->string,CurrentTable);
1920                           DestroyString($3->string);dontfree($3);
1921                           worksymtab->type=SetType($1->type);dontfree($1);
1922                           worksymtab->idtype=FNNAME;
1923                           worksymtab->declflag=DECLARED;
1924                           PushStack();
1925                           SavedFnNode=worksymtab;
1926                         }
1927                   lparen 
1928                         { 
1929                             if (PRIVATEFLAG)
1930                                 writeoutput(CkLocalPtr,NOFREE);
1931                         }
1932                   parameter_list_opt rparen
1933                         { 
1934                           { PushStack(); $$=GetYSN();$$->table=SavedFnNode; 
1935                           if (PRIVATEFLAG) {
1936                           WriteReturn();
1937                           writeoutput("void *",NOFREE);
1938                           writeoutput(CkLocalPtr,NOFREE);
1939                           writeoutput(";",NOFREE); }
1940                           }
1941                         }
1942                 ;
1943
1944 mopt            :  MULT { $$=GetYSN(); }
1945                 | { $$=NULL; }
1946                 ;
1947
1948 parameter_list_opt      : 
1949                         | parameter_list
1950                         ;
1951
1952 parameter_list  : IDENTIFIER    { 
1953                                   { if (PRIVATEFLAG)
1954                                         writeoutput(",",NOFREE);
1955                                   writeoutput($1->string,NOFREE);
1956                                   Insert($1->string,CurrentTable);
1957                                   DestroyString($1->string);dontfree($1); 
1958                                   }
1959                                 }
1960                 | parameter_list comma IDENTIFIER
1961                         { 
1962                           { writeoutput($3->string,NOFREE);
1963                           Insert($3->string,CurrentTable);
1964                           DestroyString($3->string);dontfree($3);
1965                           }
1966                         }
1967           /* added by Robert Allan Zeh, 9/19/1993 */
1968         | typedef_name IDENTIFIER {
1969             { if (PRIVATEFLAG)
1970                 writeoutput(",", NOFREE);
1971               writeoutput($2->string, NOFREE);
1972               Insert($2->string, CurrentTable);
1973               DestroyString($2->string); dontfree($2); } }
1974                 ;
1975
1976 function_body   : decl_list_opt
1977                   { 
1978                     { worksymtab=CurrentTable;
1979                     PopStack(NOFREE);
1980                         /* Removed by Robert Allan Zeh, 9/20/1993, so that
1981                ANSI C type declarations aren't flagged as errors. */
1982             /* if (CheckDeclaration(worksymtab,CurrentTable))
1983                         error("Bad Parameter List",EXIT);
1984                     if (CheckDeclaration(CurrentTable,worksymtab))
1985                         error("Bad Parameter List",EXIT); */
1986                    FreeTree(CurrentTable);
1987                    CurrentTable=StackTop->tableptr=worksymtab;
1988                    PushStack();
1989                   }
1990                  }
1991                   function_stmt
1992                   { 
1993                     {
1994                     PopStack(FREE);
1995                     PopStack(FREE);
1996                     RestoreCurrentTable();
1997                     }
1998                   }
1999                 ;
2000
2001 function_stmt   : L_BRACE 
2002                         { 
2003                           { writeoutput("{ ",NOFREE); 
2004                           if (PRIVATEFLAG)                
2005                                 { writeoutput(CurrentChare->name,NOFREE);
2006                                   writeoutput(DataSuffix,NOFREE);
2007                                   writeoutput(AssignMyDataPtr,NOFREE);
2008                                   writeoutput(CurrentChare->name,NOFREE);
2009                                   writeoutput(DataSuffix,NOFREE);
2010                                   writeoutput(" *)",NOFREE);
2011                                   writeoutput(CkLocalPtr,NOFREE);
2012                                   writeoutput(";",NOFREE);
2013                                   writeoutput(AssignMyID,NOFREE);
2014                                   if (CurrentChare->idtype==BOCNAME)
2015                                     writeoutput(AssignMyBOC,NOFREE);
2016                                   WriteReturn();
2017                                 }
2018                           }
2019                         }
2020                   decl_list_opt stmt_list_opt R_BRACE
2021                         {  writeoutput("}",NOFREE); }
2022                 ;
2023
2024 exp_opt         :
2025                 | expression
2026                 ;
2027
2028 constant        : number
2029                 | char_const
2030                 ;
2031
2032 const_exp       : constant    /* const_exp:expression*/
2033                 ;
2034
2035 varsize_decl    : VARSIZE typedef_name IDENTIFIER L_SQUARE R_SQUARE SEMICOLON
2036                         { worksymtab=Insert($3->string,CurrentTable);
2037                           worksymtab->idtype=VARSIZENAME;
2038                           /*
2039                           worksymtab->type=ProcessTypeIdentifier($2);
2040                           worksymtab->type=(TYPEPTR)($2->modstring==NULL)?
2041                                 GlobalFind($2->string):
2042                                 GlobalModuleSearch($2->string,$2->modstring);
2043                           */
2044                           worksymtab->type = (TYPEPTR) $2->table;
2045                           writeoutput(" *",NOFREE);
2046                           writeoutput($3->string,NOFREE);
2047                           writeoutput(";",NOFREE);WriteReturn();
2048                           DestroyString($2->string);DestroyString($2->modstring);
2049                           DestroyString($3->string);dontfree($2);dontfree($3);
2050                         }
2051                 ;
2052
2053 msg_opt_su_rest : {$$=GetYSN(); writeoutput("int _CK_dummy_var;",NOFREE);}
2054                 | msg_su_rest {$$ = $1;}
2055                 ;
2056
2057 msg_su_rest     : struct_decl { $$=GetYSN(); }
2058                 | varsize_decl { $$=GetYSN();$$->count++; }
2059                 | msg_su_rest struct_decl { $$=$1; }
2060                 | msg_su_rest varsize_decl { $$=$1;$$->count++;} 
2061                 ;
2062
2063 msg_opt_id      :
2064                 | IDENTIFIER    { writeoutput($1->string,NOFREE);
2065                                   worksymtab=Insert($1->string,CurrentTable);
2066                                   worksymtab->idtype=STRUCTNAME;
2067                                   DestroyString($1->string);dontfree($1);
2068                                 }
2069                 ;
2070         
2071 optname_insquare: L_SQUARE IDENTIFIER R_SQUARE
2072                         { ForwardedMsgName=MakeString($2->string);
2073                           worksymtab=Insert($2->string,CurrentTable);
2074                           worksymtab->idtype=MESSAGENAME;
2075                           DestroyString($2->string);dontfree($2);
2076                           FORWARDEDMESSAGE=TRUE; 
2077                         }
2078                 |
2079                 ;       
2080 message_defn    : MESSAGE       { writeoutput("typedef struct ",NOFREE); }
2081                   optname_insquare
2082                   msg_opt_id 
2083                   L_BRACE       {PushStack();writeoutput(" { ",NOFREE);}
2084                   msg_opt_su_rest
2085                         { SavedTypeNode=GetTypeNode(1,0);
2086                           SavedTypeNode->table=CurrentTable;
2087                           PopStack(NOFREE);RestoreCurrentTable();
2088                           writeoutput(" } ",NOFREE);
2089                           if (!InPass1)
2090                                 { MsgCount++;
2091                                   writeoutput(SavedName=Map(CurrentModule->name,"0",
2092                                                 itoa(MsgCount)),NOFREE);
2093                                 }
2094                           writeoutput(";",NOFREE);WriteReturn();
2095                           if (FORWARDEDMESSAGE)
2096                                 { int i;
2097
2098                                   writeoutput("typedef ",NOFREE);
2099                                   writeoutput(SavedName,NOFREE);
2100                                   writeoutput(" ",NOFREE);
2101                                   writeoutput(ForwardedMsgName,NOFREE);
2102                                   writeoutput(";",NOFREE);WriteReturn();
2103                                   worksymtab=FindInTable(CurrentTable,ForwardedMsgName,&i);
2104                                   worksymtab->type=SavedTypeNode;
2105                                 }
2106                           MsgToStructFlag=TRUE;
2107                         }
2108                   msg_pu_rest TypeOrId SEMICOLON
2109                         { if (FORWARDEDMESSAGE)
2110                                 { int i;
2111
2112                                   if (strcmp($10->string,ForwardedMsgName))
2113                                         error("Message Tag Doesn't Match Name",EXIT);
2114                                   worksymtab=FindInTable(CurrentTable,$10->string,&i);
2115                                 }
2116                           else { writeoutput("typedef ",NOFREE);
2117                                  writeoutput(SavedName,NOFREE);
2118                                  writeoutput(" ",NOFREE);
2119                                  writeoutput($10->string,NOFREE);
2120                                  writeoutput(";",NOFREE);WriteReturn();
2121                                  worksymtab=Insert($10->string,CurrentTable);
2122                                }
2123                           worksymtab->localid=$7->count;
2124                           /* Added Sept. 16, 1991 */
2125                           worksymtab->msgno=MsgCount;
2126                           /* Added Sept. 16, 1991 */
2127                           if (worksymtab->localid==0)
2128                                 worksymtab->localid=$9->count;
2129                           worksymtab->userpack=$9->count;
2130                           worksymtab->idtype=MESSAGENAME;
2131                           worksymtab->type=SavedTypeNode;
2132                           DestroyString($10->string);dontfree($10);
2133                           MsgToStructFlag=FALSE;
2134                           if (FORWARDEDMESSAGE)
2135                                 DestroyString(ForwardedMsgName);
2136                           FORWARDEDMESSAGE=FALSE;
2137                         }       
2138                 ;
2139
2140 TypeOrId        : IDENTIFIER {$$=$1;}
2141                 | TYPE_IDENTIFIER { $$=$1; /* THIS IS CORRECT!! Nov. 12,'91 */}
2142                 ;
2143
2144 msg_pu_rest     : R_BRACE       { $$=GetYSN(); }
2145                 | PACK pfn
2146                         { RestoreCurrentTable(); }
2147                   UNPACK ufn R_BRACE    
2148                         { $$=GetYSN(); $$->count = -1; RestoreCurrentTable(); }
2149                 ;
2150
2151 pfn             : IDENTIFIER 
2152                         { writeoutput(" static ",NOFREE);
2153                           writeoutput(Map(CurrentModule->name,itoa(MsgCount),
2154                                                 "PACK"),NOFREE);
2155                           PushStack();
2156                         }
2157                   lparen  parameter_list_opt rparen
2158                         { PushStack(); }
2159                   function_body
2160                 ;
2161
2162 ufn             : IDENTIFIER
2163                         { writeoutput(" static ",NOFREE);
2164                           writeoutput(Map(CurrentModule->name,itoa(MsgCount),
2165                                                 "UNPACK"),NOFREE);
2166                           PushStack();
2167                         }
2168                   lparen  parameter_list_opt rparen
2169                         { PushStack(); }
2170                   function_body
2171                 ;
2172
2173 table_defn      : TABLE L_BRACE hashfn R_BRACE
2174                                 {
2175                                         if (IMPORTFLAG) writeoutput("extern ",NOFREE);
2176                         writeoutput("int ",NOFREE);
2177                                 }
2178                                 tid_list semicolon
2179                         | TABLE 
2180                                 { if (IMPORTFLAG) writeoutput("extern ",NOFREE);
2181                   writeoutput("int ",NOFREE);
2182                                   if (!InPass1) {
2183                                         SaveMsgCount = MsgCount; 
2184                                         MsgCount = 0;
2185                                   }
2186                 }
2187                                 tid_list semicolon { if (!InPass1) MsgCount = SaveMsgCount; }
2188                         ;
2189
2190 tid_list    : IDENTIFIER
2191             { worksymtab=Insert($1->string,CurrentTable);
2192               worksymtab->idtype=TABLENAME;
2193                           worksymtab->msgno=MsgCount;
2194               writeoutput(AppendMap(CurrentModule->name,$1->string),NOFREE);
2195              DestroyString($1->string);dontfree($1);
2196             }
2197         | tid_list comma IDENTIFIER
2198             { worksymtab=Insert($3->string,CurrentTable);
2199               worksymtab->idtype=TABLENAME;
2200                           worksymtab->msgno=MsgCount;
2201               writeoutput(AppendMap(CurrentModule->name,$3->string),NOFREE);
2202              DestroyString($3->string);dontfree($3);
2203             }
2204         ;
2205
2206
2207
2208 mono_defn       : MONOTONIC L_BRACE TYPE_IDENTIFIER MULT IDENTIFIER SEMICOLON
2209                         { if (!InPass1) MsgCount++; AccMonoName=$5->string; 
2210                           AccMonoTypeName=$3->string;
2211                         }
2212                   initfn updatefn R_BRACE IDENTIFIER SEMICOLON
2213                         { worksymtab=Insert($11->string,CurrentTable);
2214                           worksymtab->idtype=MONONAME;
2215                           worksymtab->msgno=MsgCount;
2216                         }
2217                 ;
2218
2219 acc_defn        : ACCUMULATOR L_BRACE TYPE_IDENTIFIER MULT IDENTIFIER SEMICOLON
2220                         { if (!InPass1) MsgCount++; AccMonoName=$5->string; 
2221                           AccMonoTypeName=$3->string;
2222                         }
2223                   initfn addfn combinefn R_BRACE IDENTIFIER SEMICOLON
2224                         { worksymtab=Insert($12->string,CurrentTable);
2225                           worksymtab->idtype=ACCNAME;
2226                           worksymtab->msgno=MsgCount;
2227                         }
2228                 ;
2229
2230 initfn          : type_spec mopt IDENTIFIER 
2231                         { if (strcmp($3->string,"initfn"))
2232                                 error("initfn expected",EXIT);
2233                           writeoutput(" static ",NOFREE);
2234                           if ($2!=NULL) { dontfree($2); writeoutput("*",NOFREE); }
2235                           writeoutput(Map(CurrentModule->name,itoa(MsgCount),
2236                                         "INIT"),NOFREE);
2237                           PushStack();
2238                           worksymtab=Insert(AccMonoName,CurrentTable);
2239                           worksymtab->idtype==VARNAME;
2240                           writeoutput("(",NOFREE);
2241                           writeoutput(AccMonoName,NOFREE);
2242                         }
2243                   L_PAREN paralist_opt_R_PAREN
2244                         { PushStack();
2245                           worksymtab=Insert(AccMonoName,CurrentTable);
2246                           worksymtab->idtype==VARNAME;
2247                           writeoutput(AccMonoTypeName,NOFREE);
2248                           writeoutput(" *",NOFREE);
2249                           writeoutput(AccMonoName,NOFREE);
2250                           writeoutput(";",NOFREE);WriteReturn();
2251                         }
2252                   function_body
2253                         { RestoreCurrentTable(); }
2254                 ;
2255
2256 hashfn          : IDENTIFIER 
2257                          {
2258                           if (!InPass1) MsgCount++; 
2259                           if (strcmp($1->string,"hashfn"))
2260                                   error("hashfn expected",EXIT);
2261                           writeoutput(" static ",NOFREE);
2262                           writeoutput(Map(CurrentModule->name,itoa(MsgCount),
2263                                         "HASH"),NOFREE);
2264                           PushStack();
2265                         }
2266                          L_PAREN IDENTIFIER
2267                          {
2268                                 writeoutput("( ",NOFREE);
2269                 writeoutput($4->string,NOFREE);
2270                 Insert($4->string,CurrentTable);
2271                 DestroyString($4->string);dontfree($4);
2272                          }
2273                          rparen { PushStack(); }
2274                          function_body { RestoreCurrentTable(); }
2275                         ;
2276
2277 paralist_opt_R_PAREN : rparen
2278                 | { writeoutput(",",NOFREE); } parameter_list rparen
2279                 ;
2280
2281 addfn           : IDENTIFIER
2282                         { if (strcmp($1->string,"addfn"))
2283                                   error("addfn expected",EXIT);
2284                           writeoutput(" static ",NOFREE);
2285                           writeoutput(Map(CurrentModule->name,itoa(MsgCount),
2286                                         "INCREMENT"),NOFREE);
2287                           PushStack();
2288                           worksymtab=Insert(AccMonoName,CurrentTable);
2289                           worksymtab->idtype==VARNAME;
2290                           writeoutput("(",NOFREE);
2291                           writeoutput(AccMonoName,NOFREE);
2292                         }
2293                   L_PAREN paralist_opt_R_PAREN
2294                         { PushStack();
2295                           worksymtab=Insert(AccMonoName,CurrentTable);
2296                           worksymtab->idtype==VARNAME;
2297                           writeoutput(AccMonoTypeName,NOFREE);
2298                           writeoutput(" *",NOFREE);
2299                           writeoutput(AccMonoName,NOFREE);
2300                           writeoutput(";",NOFREE);WriteReturn();
2301                         }
2302                   function_body
2303                         { RestoreCurrentTable(); }
2304                 ;
2305
2306 combinefn       : IDENTIFIER
2307                         { if (strcmp($1->string,"combinefn"))
2308                                 error("combinefn expected",EXIT);
2309                           writeoutput(" static ",NOFREE);
2310                           writeoutput(Map(CurrentModule->name,itoa(MsgCount),
2311                                         "COMBINE"),NOFREE);
2312                           PushStack();
2313                           worksymtab=Insert(AccMonoName,CurrentTable);
2314                           worksymtab->idtype==VARNAME;
2315                           writeoutput("(",NOFREE);
2316                           writeoutput(AccMonoName,NOFREE);
2317                         }
2318                   L_PAREN paralist_opt_R_PAREN
2319                         { PushStack();
2320                           worksymtab=Insert(AccMonoName,CurrentTable);
2321                           worksymtab->idtype==VARNAME;
2322                           writeoutput(AccMonoTypeName,NOFREE);
2323                           writeoutput(" *",NOFREE);
2324                           writeoutput(AccMonoName,NOFREE);
2325                           writeoutput(";",NOFREE);WriteReturn();
2326                         }
2327                   function_body
2328                         { RestoreCurrentTable(); }
2329                 ;
2330
2331 updatefn        : IDENTIFIER
2332                         { if (strcmp($1->string,"updatefn"))
2333                                 error("updatefn expected",EXIT);
2334                           writeoutput(" static ",NOFREE);
2335                           writeoutput(Map(CurrentModule->name,itoa(MsgCount),
2336                                         "UPDATE"),NOFREE);
2337                           PushStack();
2338                           worksymtab=Insert(AccMonoName,CurrentTable);
2339                           worksymtab->idtype==VARNAME;
2340                           writeoutput("(",NOFREE);
2341                           writeoutput(AccMonoName,NOFREE);
2342                         }
2343                   L_PAREN paralist_opt_R_PAREN
2344                         { PushStack();
2345                           worksymtab=Insert(AccMonoName,CurrentTable);
2346                           worksymtab->idtype==VARNAME;
2347                           writeoutput(AccMonoTypeName,NOFREE);
2348                           writeoutput(" *",NOFREE);
2349                           writeoutput(AccMonoName,NOFREE);
2350                           writeoutput(";",NOFREE);WriteReturn();
2351                         }
2352                   function_body
2353                         { RestoreCurrentTable(); }
2354                 ;
2355         
2356 chare_defn      : CHARE IDENTIFIER 
2357                         { 
2358                           { CurrentChare=Insert($2->string,CurrentTable);
2359                           FillSymTabNode(CurrentChare,CHARENAME,DECLARED,
2360                                 UNDEFINED,UNDEFINED,1,TRUE,NULL);
2361                           CurrentTable=CurrentChare->type->table;
2362                           DestroyString($2->string);dontfree($2);
2363                           writeoutput("typedef struct {",NOFREE);
2364                           WriteReturn();
2365                           }
2366                         }
2367                   L_BRACE c_decl_list_opt entry_or_fns R_BRACE
2368                         { 
2369                           { CurrentChare=NULL;RestoreCurrentTable(); }
2370                         }
2371                 ;
2372
2373 boc_defn        : BRANCHOFFICE IDENTIFIER 
2374                         { 
2375                           { CurrentChare=Insert($2->string,CurrentTable);
2376                           FillSymTabNode(CurrentChare,BOCNAME,DECLARED,
2377                                 UNDEFINED,UNDEFINED,1,TRUE,NULL);
2378                           CurrentTable=CurrentChare->type->table;
2379                           DestroyString($2->string);dontfree($2);
2380                           writeoutput("typedef struct {",NOFREE);
2381                           WriteReturn();
2382                           }
2383                         }
2384                   L_BRACE c_decl_list_opt entry_or_fns R_BRACE
2385                         { 
2386                                 { CurrentChare=NULL;RestoreCurrentTable(); }
2387                         }
2388                 ;
2389
2390 entry_or_fns    : entry_or_fn
2391                 | entry_or_fns entry_or_fn
2392                 ;
2393
2394 entry_head      : ENTRY IDENTIFIER 
2395                         { 
2396                           { writeoutput("void static ",NOFREE);
2397                           writeoutput(Map(CurrentModule->name,CurrentChare->name
2398                                                 ,$2->string),NOFREE);
2399                           worksymtab=Insert($2->string,CurrentTable);
2400                           worksymtab->idtype=ENTRYNAME;
2401                           worksymtab->declflag=DECLARED;
2402                           worksymtab->implicit_entry=ENTRYNAME;
2403                           SavedFnNode=worksymtab;
2404                           }
2405                         }
2406                   COLON lparen {  OUTPUTOFF=TRUE; } 
2407 /* 22 May 1992, Attila */
2408                 | ENTRY IMPLICIT IDENTIFIER
2409                         {
2410                           { writeoutput("void static ",NOFREE);
2411                           writeoutput(Map(CurrentModule->name,CurrentChare->name
2412                                                 ,$3->string),NOFREE);
2413                           worksymtab=Insert($3->string,CurrentTable);
2414                           worksymtab->idtype=ENTRYNAME;
2415                           worksymtab->declflag=DECLARED;
2416                           worksymtab->implicit_entry = ENTRYNAMEIMP;
2417                           SavedFnNode=worksymtab;
2418                           }
2419                         }
2420                 COLON lparen {  OUTPUTOFF=TRUE; }
2421                 ;
2422
2423 msg_type        : TYPE_IDENTIFIER
2424                         { $$=GetYSN();
2425                           if (($1->modstring==NULL) || 
2426                                 (!strcmp($1->modstring,CurrentModule->name)))
2427                                 { $$->table=LocalFind($1->string);
2428                                   $$->string=$1->string;
2429                                   dontfree($1);
2430                                 }
2431                           else  { $$->table=GlobalModuleSearch($1->string,
2432                                                         $1->modstring);
2433                                   $$->string=MakeString(Map($1->modstring,"0",
2434                                                         $1->string));
2435                                   DestroyString($1->modstring);
2436                                   DestroyString($1->string);dontfree($1);
2437                                 }
2438                         }
2439                 ;
2440
2441 entry_or_fn     : entry_head
2442                   MESSAGE msg_type MULT IDENTIFIER 
2443                         { 
2444                           { OUTPUTOFF=FALSE; 
2445                           writeoutput($5->string,NOFREE); 
2446                           writeoutput(",",NOFREE);
2447                           writeoutput(CkLocalPtr,NOFREE);
2448                           sym1=SavedFnNode;
2449                           sym2=$3->table;
2450                           if ((sym1==NULL)||(sym2==NULL)||(sym2->idtype!=MESSAGENAME))
2451                                 {error("Bad Identifier Near: ",NOEXIT); 
2452                                  PutOnScreen($5->string);
2453                                  PutOnScreen("\n");
2454                                 }
2455                           else { sym1->type = (TYPEPTR) sym2; }
2456                           }
2457                         }
2458                   rparen 
2459                         { 
2460                           { WriteReturn();
2461                           writeoutput("void *",NOFREE);
2462                           writeoutput(CkLocalPtr,NOFREE);
2463                           writeoutput(";",NOFREE);
2464                           WriteReturn();
2465                           writeoutput($3->string,NOFREE);
2466                           writeoutput(" *",NOFREE);
2467                           writeoutput($5->string,NOFREE);
2468                           writeoutput(";",NOFREE);
2469                           PushStack();
2470                           worksymtab=Insert($5->string,CurrentTable);
2471                           worksymtab->idtype=VARNAME;
2472                           sym1=$3->table;
2473                           if (sym1==NULL) error("Bad Type",EXIT);
2474                           else worksymtab->type=sym1->type;
2475                           }
2476                         }
2477                   entry_stmt
2478                         { 
2479                                 { PopStack(FREE);RestoreCurrentTable(); }
2480                         }
2481                 | entry_head R_PAREN
2482                         { 
2483                           { writeoutput(CkDummyPtr,NOFREE);
2484                             writeoutput(",",NOFREE);
2485                             writeoutput(CkLocalPtr,NOFREE);
2486                             writeoutput(")",NOFREE);
2487                             WriteReturn();
2488                             writeoutput("void *",NOFREE);
2489                             writeoutput(CkLocalPtr,NOFREE);
2490                             writeoutput(",*",NOFREE);writeoutput(CkDummyPtr,NOFREE);
2491                             writeoutput(";\n{\n",NOFREE);
2492                             PushStack();
2493                           }
2494                         }
2495                   entry_stmt
2496                         { 
2497                                 { PopStack(FREE);RestoreCurrentTable();
2498                                   writeoutput("CkFree(",NOFREE);
2499                                   writeoutput(CkDummyPtr,NOFREE);
2500                                   writeoutput(");\n}\n",NOFREE);
2501                                 }
2502                         }
2503                 | privpub {  
2504                                 { PRIVATEFLAG = TRUE;
2505                                  /* Now we allow public functions in Chares 
2506                                         if (($1->idtype==PUBLICFNNAME) && 
2507                                         (CurrentChare->idtype!=BOCNAME))
2508                                         error("Cannot Declare Publics",EXIT);
2509                                  */
2510                                 } 
2511                           }
2512                   function_decl 
2513                         { 
2514                           { $3->table->idtype=$1->idtype;
2515                             dontfree($1);
2516                           dontfree($3);
2517                           }
2518                         }
2519                   function_body
2520                         {  PRIVATEFLAG=FALSE; }
2521                 ; 
2522
2523 privpub         : PRIVATE       { $$=GetYSN(); $$->idtype=PRIVATEFNNAME; }
2524                 | PUBLIC        { $$=GetYSN(); $$->idtype=PUBLICFNNAME; }
2525                 ;
2526
2527 entry_stmt      : L_BRACE 
2528                         { 
2529                           { writeoutput("{ ",NOFREE); 
2530                           writeoutput(CurrentChare->name,NOFREE);
2531                           writeoutput(DataSuffix,NOFREE);
2532                           writeoutput(AssignMyDataPtr,NOFREE);
2533                           writeoutput(CurrentChare->name,NOFREE);
2534                           writeoutput(DataSuffix,NOFREE);
2535                           writeoutput(" *)",NOFREE);
2536                           writeoutput(CkLocalPtr,NOFREE);
2537                           writeoutput(";",NOFREE);
2538                           writeoutput(AssignMyID,NOFREE); 
2539                           if (CurrentChare->idtype==BOCNAME)
2540                               writeoutput(AssignMyBOC,NOFREE);
2541                           WriteReturn();
2542                           }
2543                         }
2544                   decl_list_opt stmt_list_opt R_BRACE
2545                         { 
2546                           { writeoutput("}",NOFREE); RestoreCurrentTable();}
2547                         }
2548                 ;
2549
2550 main_chare_defn : CHARE MAIN 
2551                         { 
2552                           { CurrentChare=Insert("main",CurrentTable);
2553                           FillSymTabNode(CurrentChare,CHARENAME,DECLARED,
2554                                 UNDEFINED,UNDEFINED,1,TRUE,NULL);
2555                           CurrentTable=CurrentChare->type->table;
2556                           writeoutput("typedef struct {",NOFREE);
2557                           WriteReturn();
2558                           }
2559                         }
2560                   L_BRACE c_decl_list_opt m_entry_or_fns R_BRACE
2561                         { 
2562                                 { CurrentChare=NULL;RestoreCurrentTable(); }
2563                         }
2564                 ;
2565
2566 m_entry_or_fns  : m_entry_or_fn
2567                 | m_entry_or_fns m_entry_or_fn
2568                 ;
2569
2570 m_entry_or_fn   : entry_or_fn
2571                 /* 
2572                 | ENTRY DATAINIT 
2573                         { HandleSpecialEntries(CKMAINDATAFUNCTION,"DataInit");}
2574                   COLON entry_stmt
2575                         { if (!InPass1) */
2576 /* { PopStack(FREE);RestoreCurrentTable(); } Jan 24 1992, changed by Attila*/
2577 /*                              { PopStack(FREE);PopStack(FREE);
2578                                   RestoreCurrentTable();
2579                                 } 
2580                         } */
2581                 | ENTRY QUIESCENCE 
2582                         { HandleSpecialEntries(CKMAINQUIESCENCEFUNCTION,"QUIESCENCE"); }
2583                   COLON entry_stmt
2584                         { if (!InPass1)
2585                                 { PopStack(FREE);RestoreCurrentTable(); }
2586                         }
2587                 | ENTRY CHAREINIT 
2588                         { HandleSpecialEntries(CKMAINCHAREFUNCTION,"CharmInit");}
2589                   COLON entry_stmt
2590                         { if (!InPass1)
2591     /* {PopStack(FREE);RestoreCurrentTable();} Jan 24 1992, changed by Attila */
2592                                 { PopStack(FREE);PopStack(FREE);
2593                                   RestoreCurrentTable();
2594                                 }
2595                         }
2596                 ; 
2597
2598 c_decl_list_opt :       { writeoutput(DummyField,NOFREE);WriteReturn();
2599                           writeoutput("} ",NOFREE);
2600                           writeoutput(CurrentChare->name,NOFREE);
2601                           writeoutput(DataSuffix,NOFREE);
2602                           writeoutput(";",NOFREE);WriteReturn();
2603                         }
2604                 | c_decl_list   
2605                         { WriteReturn();
2606                           writeoutput("} ",NOFREE);
2607                           writeoutput(CurrentChare->name,NOFREE);
2608                           writeoutput(DataSuffix,NOFREE);
2609                           writeoutput(";",NOFREE);WriteReturn();
2610                         }
2611                 ;
2612
2613 c_decl_list     : mod_declaration
2614                 | c_decl_list mod_declaration
2615                 ;
2616
2617 lsquare         : L_SQUARE      { writeoutput("[",NOFREE); }
2618                 ;
2619 rsquare         : R_SQUARE      { writeoutput("]",NOFREE); }
2620                 ;
2621 lparen          : L_PAREN       { writeoutput("(",NOFREE); }
2622                 ;
2623 rparen          : R_PAREN       { writeoutput(")",NOFREE); }
2624                 ;
2625 incdec          : INCDEC        { writeoutput($1->string,NOFREE);
2626                                   DestroyString($1->string);dontfree($1);
2627                                 }
2628                 ;
2629 asgnop          : ASGNOP        { writeoutput($1->string,NOFREE);
2630                                   DestroyString($1->string);dontfree($1);
2631                                 }
2632                 ;
2633 equal           : EQUAL         { writeoutput("=",NOFREE); }
2634                 ;
2635 notequal        : NOTEQUAL      { writeoutput("!=",NOFREE); }
2636                 ;
2637 equalequal      : EQUALEQUAL    { writeoutput("==",NOFREE); }
2638                 ;
2639 shift           : SHIFT         { writeoutput($1->string,NOFREE);
2640                                   DestroyString($1->string);dontfree($1);
2641                                 }
2642                 ;
2643 compare         : COMPARE       { writeoutput($1->string,NOFREE);
2644                                   DestroyString($1->string);dontfree($1);
2645                                 }
2646                 ;
2647 number          : NUMBER        { writeoutput($1->string,NOFREE);
2648                                   DestroyString($1->string);dontfree($1);
2649                                 }
2650                 ;
2651 char_const      : CHAR_CONST    { writeoutput($1->string,NOFREE);
2652                                   DestroyString($1->string);dontfree($1);
2653                                 }
2654                 ;
2655 string          : STRING        { writeoutput($1->string,NOFREE);
2656                                   DestroyString($1->string);dontfree($1);
2657                                 }
2658                 ;
2659 semicolon       : SEMICOLON     { writeoutput(";",NOFREE); }
2660                 ;
2661 colon           : COLON         { writeoutput(":",NOFREE); }
2662                 ;
2663 comma           : COMMA         { writeoutput(",",NOFREE); }
2664                 ;
2665 comma_L_BRACE   : COMMA_L_BRACE { writeoutput(",{",NOFREE); }
2666                 ;
2667 comma_R_BRACE   : COMMA_R_BRACE { writeoutput(",}",NOFREE); }
2668                 ;
2669
2670 TypeDef         : TYPEDEF       { writeoutput("typedef ",NOFREE); }
2671                 ;
2672
2673 Struct          : STRUCT        { writeoutput("struct ",NOFREE); }
2674                 ;
2675
2676 Enum            : ENUM          { writeoutput("enum ",NOFREE); }
2677                 ;
2678
2679 Union           : UNION         { writeoutput("union ",NOFREE); }
2680                 ;
2681
2682 readonly        : READONLY      { if (IMPORTFLAG)
2683                                         writeoutput("extern ",NOFREE);
2684                                   writeoutput("SHARED_DECL ",NOFREE); 
2685                                 }
2686                   typedef_name  { SavedFnNode=$3->table; } 
2687                   read_id_list semicolon
2688                 ;
2689
2690 read_id_list    : read_id
2691                 | read_id_list comma read_id
2692                 ;
2693
2694 read_id         : IDENTIFIER
2695                         { worksymtab=Insert($1->string,CurrentTable);
2696                           worksymtab->idtype=READONLYVAR;
2697                           worksymtab->type=SavedFnNode->type;
2698                           if (SavedFnNode->idtype==MESSAGENAME)
2699                                 error("Bad Read Only",EXIT);
2700                           writeoutput(AppendMap(CurrentModule->name,$1->string),NOFREE);
2701                           DestroyString($1->string);dontfree($1);
2702                         }
2703                 | MULT IDENTIFIER
2704                         { worksymtab=Insert($2->string,CurrentTable);
2705                           worksymtab->idtype=READONLYMSG;
2706                           worksymtab->type=SavedFnNode->type;
2707                           if (SavedFnNode->idtype!=MESSAGENAME)
2708                                 error("Bad ReadOnly Msg",EXIT);
2709                           writeoutput(" *",NOFREE);
2710                           writeoutput(AppendMap(CurrentModule->name,$2->string),NOFREE);
2711                           DestroyString($2->string);dontfree($2);
2712                         }
2713                 | read_array
2714                 ;
2715
2716 read_array      : IDENTIFIER 
2717                         { worksymtab=Insert($1->string,CurrentTable);
2718                           worksymtab->idtype=READONLYARRAY;
2719                           worksymtab->type=SavedFnNode->type;
2720                           if (SavedFnNode->idtype==MESSAGENAME)
2721                                 error("Bad Array",EXIT);
2722                           writeoutput(AppendMap(CurrentModule->name,$1->string),NOFREE);
2723                           DestroyString($1->string);dontfree($1);
2724                         }
2725                   lsquare expression rsquare