2 * main.c -- main program for PCCTS ANTLR.
6 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
7 * Set (PCCTS) -- PCCTS is in the public domain. An individual or
8 * company may do whatever they wish with source code distributed with
9 * PCCTS or the code generated by PCCTS, including the incorporation of
10 * PCCTS, or its output, into commerical software.
12 * We encourage users to develop software with PCCTS. However, we do ask
13 * that credit is given to us for developing PCCTS. By "credit",
14 * we mean that if you incorporate our source code into one of your
15 * programs (commercial product, research project, or otherwise) that you
16 * acknowledge this fact somewhere in the documentation, research report,
17 * etc... If you like PCCTS and have developed a nice tool with the
18 * output, please mention that you developed it using PCCTS. In
19 * addition, we ask that this header remain intact in our source code.
20 * As long as these guidelines are kept, we expect to continue enhancing
21 * this system and expect to make other tools available as they are
26 * Parr Research Corporation
27 * with Purdue University and AHPCRC, University of Minnesota
31 /* To set a breakpoint just before exit look for "cleanUp". */
32 /* To set a breakpoint for fatal error look for "fatal_intern" */
39 #define MAX_INT_STACK 50
40 static int istack
[MAX_INT_STACK
]; /* Int stack */
41 static int isp
= MAX_INT_STACK
;
43 static int DontAcceptFiles
= 0; /* if stdin, don't read files */
44 static int DontAcceptStdin
= 0; /* if files seen first, don't accept stdin */
46 static int tnodes_used_in_guard_predicates_etc
; /* MR10 */
48 /* C m d - L i n e O p t i o n S t r u c t & F u n c s */
62 extern void ProcessArgs(int, char **, Opt
*);
64 extern void ProcessArgs();
68 int ci_strequ(char *a
,char *b
)
75 for ( ;*a
!= 0 && *b
!= 0; a
++, b
++) {
76 if (toupper(*a
) != toupper(*b
)) return 0;
88 if ( DontAcceptStdin
)
90 warnNoFL("'-' (stdin) ignored as files were specified first");
94 require(NumFiles
<MaxNumFiles
,"exceeded max # of input files");
95 FileStr
[NumFiles
++] = "stdin";
107 if ( *s
=='-' ) { warnNoFL( eMsg1("invalid option: '%s'",s
) ); return; }
108 if ( DontAcceptFiles
)
110 warnNoFL(eMsg1("file '%s' ignored as '-' (stdin option) was specified first",s
));
114 require(NumFiles
<MaxNumFiles
,"exceeded max # of input files");
115 FileStr
[NumFiles
++] = s
;
120 Allow input to be a file containing a list of files
121 Bernard Giroud (b_giroud@decus.ch)
126 pFileList( char *s
, char *t
)
133 #define MaxFLArea 1024
135 static char Fn_in_Fl
[MaxFLArea
] = "";
136 char one_fn
[MaxFileName
];
137 char *flp
= &Fn_in_Fl
[0];
138 int fnl
, left
= MaxFLArea
, i
;
140 if ( *t
=='-' ) { warnNoFL( eMsg1("invalid option: '%s'",t
) ); return; }
141 if ( DontAcceptFiles
)
143 warnNoFL(eMsg1("file '%s' ignored as '-' (stdin option) was specified first",t
));
147 if ((fl
= fopen(t
, "r")) == NULL
)
149 warnNoFL(eMsg1("file '%s' can't be opened", t
));
154 if (fgets(one_fn
, 128 - 1, fl
) == NULL
)
156 fnl
= strlen(one_fn
);
157 require(fnl
<=left
, "no more room in File List Area");
158 /* drop the trailing LF */
159 if (one_fn
[fnl
- 1] == 0x0a) one_fn
[fnl
- 1] = ' ';
160 strcat(Fn_in_Fl
, one_fn
);
162 require(NumFiles
<MaxNumFiles
,"exceeded max # of input files");
163 FileStr
[NumFiles
++] = flp
;
167 for (i
=0;i
< MaxFLArea
;i
++) if (Fn_in_Fl
[i
] == ' ') Fn_in_Fl
[i
] = '\0';
173 pLLK( char *s
, char *t
)
182 warnNoFL("must have at least one token of lookahead (setting to 1)");
189 pCk( char *s
, char *t
)
198 warnNoFL("must have at least one token of look-ahead (setting to 1)");
203 static void /* MR6 */
205 pTab( char *s
, char *t
) /* MR6 */
207 pTab( s
, t
) /* MR6 */
212 TabWidth
= atoi(t
); /* MR6 */
213 if ( TabWidth
< 0 || TabWidth
> 8 ) { /* MR6 */
214 warnNoFL("tab width must be between 1 and 8"); /* MR6 */
215 TabWidth
=0; /* MR6 */
219 static int ambAidDepthSpecified
=0; /* MR11 */
221 static void /* MR11 */
223 pAAd( char *s
, char *t
) /* MR11 */
225 pAAd( s
, t
) /* MR11 */
230 ambAidDepthSpecified
=1; /* MR11 */
231 MR_AmbAidDepth
= atoi(t
); /* MR11 */
234 static void /* MR11 */
236 pTreport( char *s
, char *t
) /* MR11 */
238 pTreport( s
, t
) /* MR11 */
243 TnodesReportThreshold
= atoi(t
); /* MR11 */
247 void chkGTFlag(void) /* 7-Apr-97 MR1 */
249 void chkGTFlag() /* 7-Apr-97 MR1 */
253 warn("#-variable or other AST item referenced w/o -gt option");
258 static void pInfo(char *s
, char *t
) /* MR10 */
260 static void pInfo(s
,t
) /* MR10 */
267 for (p
=t
; *p
!= 0; p
++) {
282 warnNoFL(eMsgd("unrecognized -info option \"%c\"",(int)*p
));
288 static void pCGen(void) { CodeGen
= FALSE
; LexGen
= FALSE
; }
289 static void pLGen(void) { LexGen
= FALSE
; }
290 static void pXTGen(void){ MR_Inhibit_Tokens_h_Gen
= TRUE
; }
291 static void pTGen(void) { TraceGen
= TRUE
; }
292 static void pSGen(void) { GenExprSetsOpt
= FALSE
; }
293 static void pPrt(void) { PrintOut
= TRUE
; pCGen(); pLGen(); }
294 static void pPrtA(void) { PrintOut
= TRUE
; PrintAnnotate
= TRUE
; pCGen(); pLGen(); }
295 static void pAst(void) { GenAST
= TRUE
; }
296 static void pANSI(void) { GenANSI
= TRUE
; }
297 static void pCr(void) { GenCR
= TRUE
; }
298 static void pNOPURIFY(void) { PURIFY
= FALSE
; }
299 /*static void pCt(void) { warnNoFL("-ct option is now the default"); }*/
300 static void pLI(void) { GenLineInfo
= TRUE
; GenLineInfoMS
= FALSE
; } /* MR14 */
301 static void pLIms(void) { GenLineInfo
= TRUE
; GenLineInfoMS
= TRUE
; } /* MR14 */
302 static void pFr(char *s
, char *t
) {RemapFileName
= t
;}
303 static void pFe(char *s
, char *t
) {ErrFileName
= t
;}
304 static void pFl(char *s
, char *t
) {DlgFileName
= t
;}
305 static void pFm(char *s
, char *t
) {ModeFileName
= t
;}
306 static void pFt(char *s
, char *t
) {DefFileName
= t
;}
308 static void pE1(void) { elevel
= 1; }
309 static void pE2(void) { elevel
= 2; }
310 static void pE3(void) { elevel
= 3; }
311 static void pEGen(void) { GenEClasseForRules
= 1; }
312 static void pDL(void)
316 warnNoFL("-gk does not work currently in C++ mode; -gk turned off");
321 static void pAA(char *s
,char *t
) {MR_AmbAidRule
= t
;} /* MR11 */
322 static void pAAm(char *s
){MR_AmbAidMultiple
= 1;} /* MR11 */
323 static void pGHdr(void) { GenStdPccts
= 1; }
324 static void pFHdr(char *s
, char *t
) { stdpccts
= t
; pGHdr(); }
325 static void pW1(void) { WarningLevel
= 1; }
326 static void pNewAST(void) { NewAST
= 1; } /* MR13 */
327 static void ptmakeInParser(void) { tmakeInParser
= 1; } /* MR23 */
328 static void pAlpha(void) { AlphaBetaTrace
= 1; } /* MR14 */
329 static void pMR_BlkErr(void) { MR_BlkErr
= 1; } /* MR21 */
330 static void pStdout(void) {UseStdout
= 1; } /* MR6 */
331 static void pW2(void) { WarningLevel
= 2; }
332 static void pCC(void) { GenCC
= TRUE
; }
334 static void pCGen() { CodeGen
= FALSE
; LexGen
= FALSE
; }
335 static void pLGen() { LexGen
= FALSE
; }
336 static void pXTGen(){ MR_Inhibit_Tokens_h_Gen
= TRUE
; } /* MR14 */
337 static void pTGen() { TraceGen
= TRUE
; }
338 static void pSGen() { GenExprSetsOpt
= FALSE
; }
339 static void pPrt() { PrintOut
= TRUE
; pCGen(); pLGen(); }
340 static void pPrtA() { PrintOut
= TRUE
; PrintAnnotate
= TRUE
; pCGen(); pLGen(); }
341 static void pAst() { GenAST
= TRUE
; }
342 static void pANSI() { GenANSI
= TRUE
; }
343 static void pCr() { GenCR
= TRUE
; }
344 static void pNOPURIFY() { PURIFY
= FALSE
; }
346 /*static void pCt() { warnNoFL("-ct option is now the default"); }*/
347 static void pLI() { GenLineInfo
= TRUE
; GenLineInfoMS
= FALSE
; } /* MR14 */
348 static void pLIms() { GenLineInfo
= TRUE
; GenLineInfoMS
= TRUE
; } /* MR14 */
349 static void pFr(s
,t
) char *s
, *t
; {RemapFileName
= t
;}
350 static void pFe(s
,t
) char *s
, *t
; {ErrFileName
= t
;}
351 static void pFl(s
,t
) char *s
, *t
; {DlgFileName
= t
;}
352 static void pFm(s
,t
) char *s
, *t
; {ModeFileName
= t
;}
353 static void pFt(s
,t
) char *s
, *t
; {DefFileName
= t
;}
355 static void pE1() { elevel
= 1; }
356 static void pE2() { elevel
= 2; }
357 static void pE3() { elevel
= 3; }
358 static void pEGen() { GenEClasseForRules
= 1; }
363 warnNoFL("-gk does not work currently in C++ mode; -gk turned off");
368 static void pAA(s
,t
) char *s
; char *t
; {MR_AmbAidRule
= t
;} /* MR11 BJS 20-Mar-98 */
369 static void pAAm(s
) char *s
; {MR_AmbAidMultiple
= 1;} /* MR11 BJS 20-Mar-98 */
370 static void pGHdr() { GenStdPccts
= 1; }
371 static void pFHdr(s
,t
) char *s
, *t
; { stdpccts
= t
; pGHdr(); }
372 static void pW1() { WarningLevel
= 1; }
373 static void pNewAST() { NewAST
= 1; } /* MR13 */
374 static void ptmakeInParser() { tmakeInParser
= 1; } /* MR23 */
375 static void pAlpha() { AlphaBetaTrace
= 1; } /* MR14 */
376 static void pMR_BlkErr() { MR_BlkErr
= 1; } /* MR21 */
377 static void pStdout() {UseStdout
= 1; } /* MR6 */
378 static void pW2() { WarningLevel
= 2; }
379 static void pCC() { GenCC
= TRUE
; }
384 pPre( char *s
, char *t
)
396 pOut( char *s
, char *t
)
413 warnNoFL("-pr is no longer used (predicates employed if present); see -prc, -mrhoist, -mrhoistk");
415 ** if ( DemandLookahead )
416 ** warnNoFL("-gk conflicts with -pr; -gk turned off");
417 ** DemandLookahead = 0;
418 ** HoistPredicateContext = 0;
424 pPredCtx( char *s
, char *t
)
431 if ( ci_strequ(t
,"on")) HoistPredicateContext
= 1;
432 else if ( ci_strequ(t
,"off")) HoistPredicateContext
= 0;
433 if ( DemandLookahead
)
435 warnNoFL("-gk incompatible with semantic predicate usage; -gk turned off");
442 pMRhoist( char *s
, char *t
)
449 if ( ci_strequ(t
,"on")) MRhoisting
= 1;
450 else if ( ci_strequ(t
,"off")==0 ) MRhoisting
= 0;
452 fprintf(stderr
,"Maintenance Release style hoisting enabled for predicates with lookahead depth = 1\n");
453 fprintf(stderr
," No longer considered experimental\n");
454 fprintf(stderr
," Can't consider suppression for predicates with lookahead depth > 1\n");
455 fprintf(stderr
," Implies -prc on but does *not* imply -mrhoistk for k>1 predicates\n");
456 fprintf(stderr
," This is a reminder, not a warning or error.\n");
462 pMRhoistk( char *s
, char *t
)
469 if ( ci_strequ(t
,"on")) MRhoistingk
= 1;
470 else if ( ci_strequ(t
,"off")==0 ) MRhoistingk
= 0;
472 fprintf(stderr
,"EXPERIMENTAL Maintenance Release style hoisting enabled\n");
473 fprintf(stderr
," Applies to predicates with lookahead depth > 1\n");
474 fprintf(stderr
," Implies -prc on and -mrhoist on\n");
480 pTRes( char *s
, char *t
)
487 TreeResourceLimit
= atoi(t
);
488 if ( TreeResourceLimit
<= 0 )
490 warnNoFL("analysis resource limit (# of tree nodes) must be greater than 0");
491 TreeResourceLimit
= -1; /* set to no limit */
497 { "-CC", 0, (void (*)(...)) pCC
, "Generate C++ output (default=FALSE)"},
498 { "-ck", 1, (void (*)(...)) pCk
, "Set compressed lookahead depth; fast approximate lookahead"},
499 { "-cr", 0, (void (*)(...)) pCr
, "Generate cross reference (default=FALSE)"},
500 { "-e1", 0, (void (*)(...)) pE1
, "Ambiguities/errors shown in low detail (default)"},
501 { "-e2", 0, (void (*)(...)) pE2
, "Ambiguities/errors shown in more detail"},
502 { "-e3", 0, (void (*)(...)) pE3
,
503 "Ambiguities for k>1 grammars shown with exact tuples (not lookahead sets)"},
504 { "-f", 1, (void (*)(...)) pFileList
,"Read names of grammar files from specified file"}, /* MR14 */
505 { "-fe", 1, (void (*)(...)) pFe
, "Rename err.c"},
506 { "-fh", 1, (void (*)(...)) pFHdr
, "Rename stdpccts.h header (turns on -gh)"},
507 { "-fl", 1, (void (*)(...)) pFl
, "Rename lexical output--parser.dlg"},
508 { "-fm", 1, (void (*)(...)) pFm
, "Rename mode.h"},
509 { "-fr", 1, (void (*)(...)) pFr
, "Rename remap.h"},
510 { "-ft", 1, (void (*)(...)) pFt
, "Rename tokens.h"},
511 { "-ga", 0, (void (*)(...)) pANSI
, "Generate ANSI-compatible code (default=FALSE)"},
512 { "-gc", 0, (void (*)(...)) pCGen
, "Do not generate output parser code (default=FALSE)"},
513 { "-gd", 0, (void (*)(...)) pTGen
, "Generate code to trace rule invocation (default=FALSE)"},
514 { "-ge", 0, (void (*)(...)) pEGen
, "Generate an error class for each non-terminal (default=FALSE)"},
515 { "-gh", 0, (void (*)(...)) pGHdr
, "Generate stdpccts.h for non-ANTLR-generated-files to include"},
516 { "-gk", 0, (void (*)(...)) pDL
, "Generate parsers that delay lookahead fetches until needed"},
517 { "-gl", 0, (void (*)(...)) pLI
, "Generate line info about grammar actions in parser"},
518 { "-glms", 0, (void (*)(...)) pLIms
,"Like -gl but replace '\\' with '/' in #line filenames for MS C/C++ systems"},
519 { "-gp", 1, (void (*)(...)) pPre
, "Prefix all generated rule functions with a string"},
520 { "-gs", 0, (void (*)(...)) pSGen
, "Do not generate sets for token expression lists (default=FALSE)"},
521 { "-gt", 0, (void (*)(...)) pAst
, "Generate code for Abstract-Syntax-Trees (default=FALSE)"},
522 { "-gx", 0, (void (*)(...)) pLGen
, "Do not generate lexical (dlg-related) files (default=FALSE)"},
523 { "-gxt",0, (void (*)(...)) pXTGen
, "Do not generate tokens.h (default=FALSE)"},
524 { "-k", 1, (void (*)(...)) pLLK
, "Set full LL(k) lookahead depth (default==1)"},
525 { "-o", 1, (void (*)(...)) pOut
, OutputDirectoryOption
},
526 { "-p", 0, (void (*)(...)) pPrt
, "Print out the grammar w/o actions (default=no)"},
527 { "-pa", 0, (void (*)(...)) pPrtA
, "Print out the grammar w/o actions & w/FIRST sets (default=no)"},
528 { "-pr",0, (void (*)(...)) pPred
, "no longer used; predicates employed if present"},
529 { "-prc", 1, (void (*)(...)) pPredCtx
,"Turn on/off computation of context for hoisted predicates"},
530 { "-rl", 1, (void (*)(...)) pTRes
, "Limit max # of tree nodes used by grammar analysis"},
531 { "-stdout",0, (void (*)(...)) pStdout
,"Send grammar.c/grammar.cpp to stdout"}, /* MR6 */
532 { "-tab", 1, (void (*)(...)) pTab
, "Width of tabs (1 to 8) for grammar.c/grammar.cpp files"}, /* MR6 */
533 { "-w1", 0, (void (*)(...)) pW1
, "Set the warning level to 1 (default)"},
534 { "-w2", 0, (void (*)(...)) pW2
, "Ambiguities yield warnings even if predicates or (...)? block"},
535 { "-", 0, (void (*)(...)) pStdin
, "Read grammar from stdin" },
536 { "-mrhoist",1, (void (*)(...)) pMRhoist
, /* MR9 */
537 "Turn on/off k=1 Maintenance Release style hoisting"}, /* MR9 */
538 { "-mrhoistk",1, (void (*)(...)) pMRhoistk
, /* MR9 */
539 "Turn on/off EXPERIMENTAL k>1 Maintenance Release style hoisting"}, /* MR13 */
540 { "-aa" , 1, (void (*)(...)) pAA
, "Ambiguity aid for a rule (rule name or line number)"}, /* MR11 */
541 { "-aam" , 0, (void (*)(...)) pAAm
,
542 "Lookahead token may appear multiple times in -aa listing"}, /* MR11 */
543 { "-aad" , 1, (void (*)(...)) pAAd
,
544 "Limits exp growth of -aa listing - default=1 (max=ck value)"}, /* MR11 */
545 { "-info", 1, (void (*)(...)) pInfo
,
546 "Extra info: p=pred t=tnodes f=first/follow m=monitor o=orphans 0=noop"}, /* MR12 */
547 { "-treport",1,(void (*)(...)) pTreport
,
548 "Report when tnode usage exceeds value during ambiguity resolution"}, /* MR11 */
549 { "-newAST", 0, (void (*)(...)) pNewAST
,
550 "In C++ mode use \"newAST(...)\" rather than \"new AST(...)\""}, /* MR13 */
551 { "-tmake", 0, (void (*)(...)) ptmakeInParser
,
552 "In C++ mode use parser's tmake method rather than \"ASTBase::tmake(...)\""}, /* MR23 */
553 { "-alpha",0,(void (*)(...)) pAlpha
,
554 "Provide additional information for \"(alpha)? beta\" error messages"}, /* MR14 */
555 { "-mrblkerr",0,(void (*)(...)) pMR_BlkErr
, /* MR21 */
556 "EXPERIMENTAL change to (...)* and (...)+ syntax error sets"}, /* MR21 */
557 { "-nopurify",0,(void (*)(...)) pNOPURIFY
,
558 "Don't use the notorious PURIFY macro (replaced by MR23 initial value syntax) to zero return arguments of rules"}, /* MR23 */
559 { "*", 0, (void (*)(...)) pFile
, "" }, /* anything else is a file */
561 { "-CC", 0, pCC
, "Generate C++ output (default=FALSE)"},
562 { "-cr", 0, pCr
, "Generate cross reference (default=FALSE)"},
563 { "-ck", 1, pCk
, "Set compressed lookahead depth; fast approximate lookahead"},
564 { "-e1", 0, pE1
, "Ambiguities/errors shown in low detail (default)"},
565 { "-e2", 0, pE2
, "Ambiguities/errors shown in more detail"},
566 { "-e3", 0, pE3
, "Ambiguities for k>1 grammars shown with exact tuples (not lookahead sets)"},
567 { "-f", 1, pFileList
,"Read names of grammar files from specified file"}, /* MR14 */
568 { "-fe", 1, pFe
, "Rename err.c"},
569 { "-fh", 1, pFHdr
, "Rename stdpccts.h header (turns on -gh)"},
570 { "-fl", 1, pFl
, "Rename lexical output--parser.dlg"},
571 { "-fm", 1, pFm
, "Rename mode.h"},
572 { "-fr", 1, pFr
, "Rename remap.h"},
573 { "-ft", 1, pFt
, "Rename tokens.h"},
574 { "-ga", 0, pANSI
, "Generate ANSI-compatible code (default=FALSE)"},
575 { "-gc", 0, pCGen
, "Do not generate output parser code (default=FALSE)"},
576 { "-gd", 0, pTGen
, "Generate code to trace rule invocation (default=FALSE)"},
577 { "-ge", 0, pEGen
, "Generate an error class for each non-terminal (default=FALSE)"},
578 { "-gh", 0, pGHdr
, "Generate stdpccts.h for non-ANTLR-generated-files to include"},
579 { "-gk", 0, pDL
, "Generate parsers that delay lookahead fetches until needed"},
580 { "-gl", 0, pLI
, "Generate line info about grammar actions in C parser"},
581 { "-glms", 0, pLIms
,"Like -gl but replace '\\' with '/' in #line filenames for MS C/C++ systems"},
582 { "-gp", 1, pPre
, "Prefix all generated rule functions with a string"},
583 { "-gs", 0, pSGen
, "Do not generate sets for token expression lists (default=FALSE)"},
584 { "-gt", 0, pAst
, "Generate code for Abstract-Syntax-Trees (default=FALSE)"},
585 { "-gx", 0, pLGen
, "Do not generate lexical (dlg-related) files (default=FALSE)"},
586 { "-gxt",0, pXTGen
, "Do not generate tokens.h (default=FALSE)"},
587 { "-k", 1, pLLK
, "Set full LL(k) lookahead depth (default==1)"},
588 { "-o", 1, pOut
, OutputDirectoryOption
},
589 { "-p", 0, pPrt
, "Print out the grammar w/o actions (default=no)"},
590 { "-pa", 0, pPrtA
, "Print out the grammar w/o actions & w/FIRST sets (default=no)"},
591 { "-pr",0, pPred
, "no longer used; predicates employed if present"},
592 { "-prc", 1, pPredCtx
,"Turn on/off computation of context for hoisted predicates"},
593 { "-rl", 1, pTRes
, "Limit max # of tree nodes used by grammar analysis"},
594 { "-stdout",0, pStdout
, "Send grammar.c/grammar.cpp to stdout"}, /* MR6 */
595 { "-tab", 1, pTab
, "Width of tabs (1 to 8) for grammar.c/grammar.cpp files"}, /* MR6 */
596 { "-w1", 0, pW1
, "Set the warning level to 1 (default)"},
597 { "-w2", 0, pW2
, "Ambiguities yield warnings even if predicates or (...)? block"},
598 { "-mrhoist",1,pMRhoist
, /* MR9 */
599 "Turn on/off k=1 Maintenance Release style hoisting"}, /* MR9 */
600 { "-mrhoistk",1,pMRhoistk
, /* MR13 */
601 "Turn on/off k>1 EXPERIMENTAL Maintenance Release style hoisting"}, /* MR13 */
602 { "-aa" ,1,pAA
, "Ambiguity aid for a rule (rule name or line number)"}, /* MR11 */
604 "Lookahead token may appear multiple times in -aa listing"}, /* MR11 */
606 "Limits exp growth of -aa listing - default=1 (max=ck value)"}, /* MR11 */
608 "Extra info: p=pred t=tnodes f=first/follow m=monitor o=orphans 0=noop"}, /* MR11 */
609 { "-treport",1,pTreport
,
610 "Report when tnode usage exceeds value during ambiguity resolution"}, /* MR11 */
611 { "-newAST", 0, pNewAST
,
612 "In C++ mode use \"newAST(...)\" rather than \"new AST(...)\""}, /* MR13 */
613 { "-tmake", 0, ptmakeInParser
,
614 "In C++ mode use parser's tmake method rather than \"ASTBase::tmake(...)\""}, /* MR23 */
615 { "-alpha",0, pAlpha
,
616 "Provide additional information for \"(alpha)? beta\" error messages"}, /* MR14 */
617 { "-mrblkerr",0,pMR_BlkErr
, /* MR21 */
618 "EXPERIMENTAL change to (...)* and (...)+ syntax error sets"}, /* MR21 */
619 { "-nopurify",0,pNOPURIFY
,
620 "Don't use the notorious PURIFY macro (replaced by MR23 initial value syntax) to zero return arguments of rules"}, /* MR23 */
621 { "-", 0, pStdin
, "Read grammar from stdin" },
622 { "*", 0, pFile
, "" }, /* anything else is a file */
631 static void buildRulePtr( void );
632 static void help( void );
633 static void init( void );
634 static void CompleteTokenSetRefs( void );
635 static void ensure_no_C_file_collisions(char *);
636 static void CompleteContextGuards(void);
638 static void buildRulePtr( );
641 static void CompleteTokenSetRefs( );
642 static void ensure_no_C_file_collisions();
643 static void CompleteContextGuards();
647 #ifdef __USE_PROTOS /* <BJS> */
648 report_numericPredLabels(ActionNode
*a
)
650 report_numericPredLabels(a
)
654 warnFL("numeric references to attributes (e.g. $i or $i.j) in semantic pred will be null during guess mode", /* MR10 */
655 FileStr
[a
->file
],a
->line
); /* MR10 */
662 main( int argc
, char *argv
[] )
670 static char EPSTR
[] = "[Ep]";
672 Save_argc
=argc
; /* MR10 */
673 Save_argv
=argv
; /* MR10 */
675 /* malloc_debug(8);*/
678 special_inits(); /* MR1 */
680 fprintf(stderr
, "Antlr parser generator Version %s 1989-2001\n", Version
);
681 if ( argc
== 1 ) { help(); zzDIE
; }
682 ProcessArgs(argc
-1, &(argv
[1]), options
);
684 /* MR14 */ if (MR_AmbAidRule
&& AlphaBetaTrace
) {
685 /* MR14 */ fatal("Can't specify both -aa (ambiguity aid) and -alpha (\"(alpha)? beta\" aid)");
688 if (MRhoistingk
) { /* MR13 */
689 HoistPredicateContext
=1; /* MR13 */
690 MRhoisting
=1; /* MR13 */
692 if (MRhoisting
&& ! HoistPredicateContext
) {
693 /*** warnNoFL("Using \"-mrhoist\" forces \"-prc on\""); ***/
694 HoistPredicateContext
=1;
696 if (HoistPredicateContext
&& ! MRhoisting
) {
697 warnNoFL("When using predicate context (-prc on) -mrhoist on is recommended");
699 /* Fix lookahead depth */
700 /* Compressed lookahead must always be larger than or equal to full lookahead */
701 if ( CLL_k
< LL_k
&& CLL_k
>0 )
703 warnNoFL("must have compressed lookahead >= full LL(k) lookahead (setting -ck to -k)");
706 if ( CLL_k
== -1 ) CLL_k
= LL_k
;
708 if ( ((CLL_k
-1)&CLL_k
)!=0 ) { /* output ll(k) must be power of 2 */
710 for(n
=1; n
<CLL_k
; n
<<=1) {;}
715 warnNoFL("The -mrblkerr option is EXPERIMENTAL");
717 warnNoFL("The -mrblkerr option is designed only for k=1 ck=1 grammars");
721 if ( ! ambAidDepthSpecified
) {
724 if (MR_AmbAidDepth
> CLL_k
|| MR_AmbAidDepth
<= 0) {
726 "Ambiguity aid depth (\"-aad ...\") must be a number between 1 and max(k,ck)=%d",CLL_k
));
729 if (MR_AmbAidDepth
== 0) {
734 if (MR_AmbAidRule
!= NULL
) MR_AmbAidLine
=atoi(MR_AmbAidRule
);
736 fpTrans
= &(C_Trans
[0]); /* Translate to C Language */
737 fpJTrans
= &(C_JTrans
[0]);
739 lexclass(LexStartSymbol
);
742 LastTokenCounted
= TokenNum
;
744 if ( CannotContinue
) {cleanUp(); zzDIE
;}
745 if ( GenCC
&& no_classes_found
) fatal("required grammar class not found (exiting...)");
746 if ( WarningLevel
>1 && HdrAction
== NULL
)
747 warnNoFL("no #header action was found");
748 if ( FoundAtOperator
&& ! FoundExceptionGroup
) {
749 warnNoFL("found the exception operator '@' - but no exception group was found");
751 EpToken
= addTname(EPSTR
); /* add imaginary token epsilon */
752 set_orel(EpToken
, &imag_tokens
);
754 /* this won't work for hand-built scanners since EofToken is not
755 * known. Forces EOF to be token type 1.
757 set_orel(EofToken
, &imag_tokens
);
759 set_size(NumWords(TokenNum
-1));
761 /* compute the set of all known token types
762 * It represents the set of tokens from 1 to last_token_num + the
763 * reserved positions above that (if any). Don't include the set of
764 * imaginary tokens such as the token/error classes or EOF.
768 a
= set_dup(reserved_positions
);
769 for (i
=1; i
<TokenNum
; i
++) { set_orel(i
, &a
); }
770 all_tokens
= set_dif(a
, imag_tokens
);
774 ComputeTokSets(); /* Compute #tokclass sets */
775 CompleteTokenSetRefs(); /* Change complex nodes in syn diag */
776 CompleteContextGuards(); /* MR13 */
778 if ( CodeGen
) genDefFile(); /* create tokens.h */
779 if ( LexGen
) genLexDescr(); /* create parser.dlg */
783 FILE *f
= fopen(OutMetaName(stdpccts
), "w");
784 if ( f
==NULL
) {warnNoFL( eMsg1("can't create %s",OutMetaName(stdpccts
)) );}
788 special_fopen_actions(OutMetaName(stdpccts
)); /* MR1 */
790 if (strcmp(stdpccts
,"stdpccts.h") == 0) { /* MR10 */
791 genStdPCCTSIncludeFile(f
,NULL
); /* MR10 */
793 genStdPCCTSIncludeFile(f
,pcctsBaseName(stdpccts
)); /* MR32 */
799 buildRulePtr(); /* create mapping from rule # to RuleBlk junction */
801 FoLink( (Node
*)SynDiag
); /* add follow links to end of all rules */
803 if ( GenCR
) GenCrossRef( SynDiag
);
807 if ( SynDiag
== NULL
)
809 warnNoFL("no grammar description recognized");
814 ErrFile
= fopen(OutMetaName(ErrFileName
), "w");
815 require(ErrFile
!= NULL
, "main: can't open err file");
817 special_fopen_actions(OutMetaName(ErrFileName
)); /* MR1 */
821 TRANS(SynDiag
); /* Translate to the target language */
823 DumpRemainingTokSets();
827 strcpy(Parser_h_Name
, CurrentClassName
);
828 strcat(Parser_h_Name
, ".h");
829 strcpy(Parser_c_Name
, CurrentClassName
);
830 strcat(Parser_c_Name
, CPP_FILE_SUFFIX
);
831 ensure_no_C_file_collisions(Parser_c_Name
);
832 Parser_h
= fopen(OutMetaName(Parser_h_Name
), "w");
833 require(Parser_h
!= NULL
, "main: can't open class Parserx.h file");
835 special_fopen_actions(OutMetaName(Parser_h_Name
)); /* MR1 */
837 Parser_c
= fopen(OutMetaName(Parser_c_Name
), "w");
838 require(Parser_c
!= NULL
, "main: can't open class Parserx.c file");
840 special_fopen_actions(OutMetaName(Parser_c_Name
)); /* MR1 */
843 if ( class_before_actions
!= NULL
)
846 for (p
= class_before_actions
->next
; p
!=NULL
; p
=p
->next
)
848 UserAction
*ua
= (UserAction
*)p
->elem
;
849 dumpAction( ua
->action
, Parser_h
, 0, ua
->file
, ua
->line
, 1);
853 fprintf(Parser_h
, "protected:\n"); /* MR20 */
855 TRANS(SynDiag
); /* Translate to the target language */
857 GenRuleMemberDeclarationsForCC(Parser_h
, SynDiag
);
858 if ( class_after_actions
!= NULL
)
861 for (p
= class_after_actions
->next
; p
!=NULL
; p
=p
->next
)
863 UserAction
*ua
= (UserAction
*)p
->elem
;
864 dumpAction( ua
->action
, Parser_h
, 0, ua
->file
, ua
->line
, 1);
867 DumpRemainingTokSets();
868 fprintf(Parser_h
, "};\n");
869 fprintf(Parser_h
, "\n#endif /* %s_h */\n", CurrentClassName
);
875 MR_orphanRules(stderr
);
876 if (LTinTokenAction
&& WarningLevel
>= 2) {
878 warnNoFL("At least one <<action>> following a token match contains a reference to LT(...)\n this will reference the immediately preceding token,\n not the one which follows as is the case with semantic predicates.");
880 warnNoFL("At least one <<action>> following a token match contains a reference to LA(...) or LATEXT(...)\n this will reference the immediately preceding token,\n not the one which follows as is the case with semantic predicates.");
885 if ( SynDiag
== NULL
) {warnNoFL("no grammar description recognized");}
891 GenRemapFile(); /* create remap.h */
892 /* MR10 */ if (FoundGuessBlk
) {
894 /* MR10 */ list_apply(NumericPredLabels
, (void (*)(void *))report_numericPredLabels
);
897 /* MR10 */ list_apply(NumericPredLabels
, (void (*)(void *))report_numericPredLabels
);
899 /* MR10 */ list_apply(NumericPredLabels
,report_numericPredLabels
);
904 if (InfoT
&& TnodesAllocated
> 0) {
905 if (TnodesPeak
> 10000) {
906 fprintf(stdout
,"\nTree Nodes: peak %dk created %dk lost %d\n",
908 (TnodesAllocated
/1000),
909 TnodesInUse
-tnodes_used_in_guard_predicates_etc
);
911 fprintf(stdout
,"\nTree Nodes: peak %d created %d lost %d\n",
914 TnodesInUse
-tnodes_used_in_guard_predicates_etc
);
920 if (MR_skipped_e3_report
) {
921 fprintf(stderr
,"note: use -e3 to get exact information on ambiguous tuples\n");
923 if (MR_BadExprSets
!= 0) {
924 fprintf(stderr
,"note: Unreachable C or C++ code was generated for empty expression sets,\n");
925 fprintf(stderr
," probably due to undefined rules or infinite left recursion.\n");
926 fprintf(stderr
," To locate: search the generated code for \"empty set expression\"\n");
928 if (MR_AmbAidRule
!= NULL
&& MR_matched_AmbAidRule
==0) {
929 RuleEntry
*q
= (RuleEntry
*) hash_get(Rname
,MR_AmbAidRule
);
930 if (MR_AmbAidLine
== 0 && q
== NULL
) {
931 warnNoFL(eMsg2("there is no rule \"%s\" so \"-aa %s\" will never match",
932 MR_AmbAidRule
,MR_AmbAidRule
));
934 warnNoFL(eMsg1("there was no ambiguity that matched \"-aa %s\"",MR_AmbAidRule
));
937 if (AlphaBetaTrace
) {
939 if (MR_AlphaBetaMessageCount
== 0) {
940 fprintf(stderr
,"note: there were no messages about \"(alpha)? beta\" blocks added to the generated code\n");
942 fprintf(stderr
,"note: there were %d messages about \"(alpha)? beta\" blocks added to the generated code\n",
943 MR_AlphaBetaMessageCount
);
946 if (set_null(MR_CompromisedRules
)) {
947 fprintf(stderr
,"note: the list of rules with compromised follow sets is empty\n");
949 fprintf(stderr
,"note: the following is a list of rules which *may* have incorrect\n");
950 fprintf(stderr
," follow sets computed as a result of an \"(alpha)? beta\" block\n");
951 fprintf(stderr
,"\n");
952 MR_dumpRuleSet(MR_CompromisedRules
);
953 fprintf(stderr
,"\n");
957 exit(PCCTS_EXIT_SUCCESS
);
958 return 0; /* MR11 make compilers happy */
970 Tname
= newHashTable();
971 Rname
= newHashTable();
972 Fcache
= newHashTable();
973 Tcache
= newHashTable();
974 Sname
= newHashTable();
975 Pname
= newHashTable(); /* MR11 */
977 /* Add default signal names */
978 q
= (SignalEntry
*)hash_add(Sname
,
980 (Entry
*)newSignalEntry("NoViableAlt"));
981 require(q
!=NULL
, "cannot alloc signal entry");
982 q
->signum
= sigNoViableAlt
;
983 q
= (SignalEntry
*)hash_add(Sname
,
985 (Entry
*)newSignalEntry("MismatchedToken"));
986 require(q
!=NULL
, "cannot alloc signal entry");
987 q
->signum
= sigMismatchedToken
;
988 q
= (SignalEntry
*)hash_add(Sname
,
990 (Entry
*)newSignalEntry("NoSemViableAlt"));
991 require(q
!=NULL
, "cannot alloc signal entry");
992 q
->signum
= sigNoSemViableAlt
;
994 reserved_positions
= empty
;
998 TokenStr
= (char **) calloc(TSChunk
, sizeof(char *));
999 require(TokenStr
!=NULL
, "main: cannot allocate TokenStr");
1000 FoStack
= (int **) calloc(CLL_k
+1, sizeof(int *));
1001 require(FoStack
!=NULL
, "main: cannot allocate FoStack");
1002 FoTOS
= (int **) calloc(CLL_k
+1, sizeof(int *));
1003 require(FoTOS
!=NULL
, "main: cannot allocate FoTOS");
1004 Cycles
= (ListNode
**) calloc(CLL_k
+1, sizeof(ListNode
*));
1005 require(Cycles
!=NULL
, "main: cannot allocate Cycles List");
1006 MR_CompromisedRules
=empty
; /* MR14 */
1017 fprintf(stderr
, "antlr [options] f1 f2 ... fn\n");
1018 while ( *(p
->option
) != '*' )
1020 fprintf(stderr
, " %-9s%s %s\n",
1028 /* The RulePtr array is filled in here. RulePtr exists primarily
1029 * so that sets of rules can be maintained for the FOLLOW caching
1030 * mechanism found in rJunc(). RulePtr maps a rule num from 1 to n
1031 * to a pointer to its RuleBlk junction where n is the number of rules.
1035 buildRulePtr( void )
1041 Junction
*p
= SynDiag
;
1042 RulePtr
= (Junction
**) calloc(NumRules
+1, sizeof(Junction
*));
1043 require(RulePtr
!=NULL
, "cannot allocate RulePtr array");
1047 require(r
<=NumRules
, "too many rules???");
1049 p
= (Junction
*)p
->p2
;
1055 dlgerror(const char *s
)
1061 fprintf(stderr
, ErrHdr
, FileStr
[CurFile
], zzline
);
1062 fprintf(stderr
, " lexical error: %s (text was '%s')\n",
1063 ((s
== NULL
) ? "Lexical error" : s
), zzlextext
);
1075 if ( input
==NULL
) fatal("No grammar description found (exiting...)");
1076 ANTLR(grammar(), input
);
1077 tnodes_used_in_guard_predicates_etc
=TnodesInUse
; /* MR10 */
1092 if ( CurFile
>= NumFiles
) return(NULL
);
1093 if ( ci_strequ(FileStr
[CurFile
],"stdin")) return stdin
;
1094 f
= fopen(FileStr
[CurFile
], "r");
1097 warnNoFL( eMsg1("file %s doesn't exist; ignored", FileStr
[CurFile
]) );
1107 * Return a string corresponding to the output file name associated
1108 * with the input file name passed in.
1110 * Observe the following rules:
1117 * Where f,e,g are arbitrarily long sequences of characters in a file
1120 * In other words, if a ".x" appears on the end of a file name, make it
1121 * ".c". If no ".x" appears, append ".c" to the end of the file name.
1123 * C++ mode using .cpp not .c.
1125 * Use malloc() for new string.
1137 return outnameX(fs
,CPP_FILE_SUFFIX
);
1139 return outnameX(fs
,".c");
1145 outnameX( char *fs
,char *suffix
)
1147 outnameX( fs
, suffix
)
1152 static char buf
[MaxFileName
+1];
1154 require(fs
!=NULL
&&*fs
!='\0', "outname: NULL filename");
1158 while ( *p
!= '\0' ) {p
++;} /* Stop on '\0' */
1159 while ( *p
!= '.' && p
!= buf
) {--p
;} /* Find '.' */
1160 if ( p
!= buf
) *p
= '\0'; /* Found '.' */
1161 require(strlen(buf
) + 2 < (size_t)MaxFileName
, "outname: filename too big");
1168 fatalFL( char *err_
, char *f
, int l
)
1170 fatalFL( err_
, f
, l
)
1176 fprintf(stderr
, ErrHdr
, f
, l
);
1177 fprintf(stderr
, " %s\n", err_
);
1179 exit(PCCTS_EXIT_FAILURE
);
1184 fatal_intern( char *err_
, char *f
, int l
)
1186 fatal_intern( err_
, f
, l
)
1192 fprintf(stderr
, ErrHdr
, f
, l
);
1193 fprintf(stderr
, " #$%%*&@# internal error: %s\n", err_
);
1194 fprintf(stderr
, ErrHdr
, f
, l
);
1195 fprintf(stderr
, " [complain to nearest government official\n");
1196 fprintf(stderr
, ErrHdr
, f
, l
);
1197 fprintf(stderr
, " or send hate-mail to parrt@parr-research.com;\n");
1198 fprintf(stderr
, ErrHdr
, f
, l
);
1199 fprintf(stderr
, " please pray to the ``bug'' gods that there is a trival fix.]\n");
1201 exit(PCCTS_EXIT_FAILURE
);
1211 if ( DefFile
!= NULL
) fclose( DefFile
);
1214 /* sprintf up to 3 strings */
1217 eMsg3( char *s
, char *a1
, char *a2
, char *a3
)
1219 eMsg3( s
, a1
, a2
, a3
)
1226 static char buf
[250]; /* DANGEROUS as hell !!!!!! */
1228 sprintf(buf
, s
, a1
, a2
, a3
);
1232 /* sprintf a decimal */
1235 eMsgd( char *s
, int d
)
1242 static char buf
[250]; /* DANGEROUS as hell !!!!!! */
1250 eMsgd2( char *s
, int d1
,int d2
)
1258 static char buf
[250]; /* DANGEROUS as hell !!!!!! */
1260 sprintf(buf
, s
, d1
, d2
);
1266 s_fprT( FILE *f
, set e
)
1273 register unsigned *p
;
1276 if ( set_nil(e
) ) return;
1277 if ( (q
=p
=set_pdq(e
)) == NULL
) fatal_internal("Can't alloc space for set_pdq");
1281 fprintf(f
, " %s", TerminalString(*p
));
1288 /* Return the token name or regular expression for a token number. */
1291 TerminalString( int token
)
1293 TerminalString( token
)
1298 static char imag_name
[20];
1300 /* look in all lexclasses for the token */
1301 if ( TokenString(token
) != NULL
) return TokenString(token
);
1302 for (j
=0; j
<NumLexClasses
; j
++)
1305 if ( ExprString(token
) != NULL
) return ExprString(token
);
1309 sprintf(imag_name
,"UnknownToken#%d",token
); /* MR13 */
1310 return imag_name
; /* MR13 */
1313 require(j
<NumLexClasses
, eMsgd("No label or expr for token %d",token
));
1317 /* S i m p l e I n t S t a c k */
1327 require(isp
>0, "pushint: stack overflow");
1338 require(isp
<MAX_INT_STACK
, "popint: stack underflow");
1339 return istack
[isp
++];
1349 return MAX_INT_STACK
-isp
;
1359 isp
= MAX_INT_STACK
;
1369 return isp
==MAX_INT_STACK
;
1379 require(isp
<MAX_INT_STACK
, "topint: stack underflow");
1385 ProcessArgs( int argc
, char **argv
, Opt
*options
)
1387 ProcessArgs( argc
, argv
, options
)
1394 require(argv
!=NULL
, "ProcessArgs: command line NULL");
1396 while ( argc
-- > 0 )
1399 while ( p
->option
!= NULL
)
1401 if ( strcmp(p
->option
, "*") == 0 ||
1402 ci_strequ(p
->option
, *argv
) == 1 )
1406 /* MR9 26-Sep-97 Check for argv valid */
1408 (*p
->process
)( *argv
, *(argv
+1) );
1411 fprintf(stderr
,"error: required argument for option %s omitted\n",*argv
);
1412 exit(PCCTS_EXIT_FAILURE
);
1416 (*p
->process
)( *argv
);
1427 CompleteContextGuards(void)
1429 CompleteContextGuards()
1435 if (ContextGuardPredicateList
== NULL
) return;
1437 for (p
=ContextGuardPredicateList
->next
; p
!= NULL
; p
=p
->next
) {
1438 pred
=(Predicate
*)p
->elem
;
1439 recomputeContextGuard(pred
);
1443 /* Go back into the syntax diagram and compute all meta tokens; i.e.
1444 * turn all '.', ranges, token class refs etc... into actual token sets
1448 CompleteTokenSetRefs(void)
1450 CompleteTokenSetRefs()
1455 if ( MetaTokenNodes
==NULL
) return;
1456 for (p
= MetaTokenNodes
->next
; p
!=NULL
; p
=p
->next
)
1460 TokNode
*q
= (TokNode
*)p
->elem
;
1463 q
->tset
= all_tokens
;
1465 else if ( q
->tclass
!=NULL
)
1467 if ( q
->complement
) q
->tset
= set_dif(all_tokens
, q
->tclass
->tset
);
1468 else q
->tset
= q
->tclass
->tset
;
1470 else if ( q
->upper_range
!=0 )
1472 /* we have a range on our hands: make a set from q->token .. q->upper_range */
1475 for (i
=q
->token
; i
<=q
->upper_range
; i
++) { set_orel(i
, &a
); } /* MR13 */
1477 /* MR13 */ if (q
->complement
) {
1478 /* MR13 */ q
->tset
= set_dif(all_tokens
, a
);
1479 /* MR13 */ set_free(a
);
1481 /* MR13 */ q
->tset
= a
;
1486 /* at this point, it can only be a complemented single token */
1487 else if ( q
->complement
)
1489 a
= set_of(q
->token
);
1490 b
= set_dif(all_tokens
, a
);
1494 else fatal("invalid meta token");
1498 /* MR10: Jeff Vincent
1499 MR10: Changed to remove directory information from n only if
1500 MR10: if OutputDirectory was changed by user (-o option)
1505 OutMetaName(char *n
)
1511 static char *dir_sym
= DirectorySymbol
;
1512 static char newname
[MaxFileName
+1];
1515 /* If OutputDirectory is same as TopDirectory (platform default) then leave n alone. */
1516 if (strcmp(OutputDirectory
, TopDirectory
) == 0) /* TopDirectory is "." on Unix. */
1519 /* p will point to filename without path information */
1520 if ((p
= strrchr(n
, *dir_sym
)) != NULL
) /* Directory symbol is "/" on Unix. */
1525 /* Copy new output directory into newname[] */
1526 strcpy(newname
, OutputDirectory
);
1528 /* if new output directory does not have trailing dir_sym, add it! */
1529 if (newname
[strlen(newname
)-1] != *dir_sym
) {
1530 strcat(newname
, dir_sym
);
1538 pcctsBaseName(char *n
) /* MR32 */
1544 static char newname
[MaxFileName
+1];
1545 static char* dir_sym
= DirectorySymbol
;
1551 while ( *p
!= '\0' ) {p
++;} /* go to end of string */
1552 while ( (*p
!= *dir_sym
) && (p
!= n
) ) {--p
;} /* Find last DirectorySymbol */
1553 while ( *p
== *dir_sym
) p
++; /* step forward if we're on a dir symbol */
1554 while ( *p
!= '\0' && *p
!= '.')
1556 newname
[count
++] = *p
;
1558 } /* create a new name */
1559 newname
[count
] = '\0';
1565 ensure_no_C_file_collisions(char *class_c_file
)
1567 ensure_no_C_file_collisions(class_c_file
)
1573 for (i
=0; i
<NumFiles
; i
++)
1576 #ifdef PCCTS_CASE_INSENSITIVE_FILE_NAME
1577 /* assume that file names are case insensitive */
1578 if ( STRICMP(outname(FileStr
[i
]), class_c_file
)==0 )
1580 if ( strcmp(outname(FileStr
[i
]), class_c_file
)==0 )
1583 fatal(eMsg1("class def output file conflicts with parser output file: %s",
1584 outname(FileStr
[i
])));
1597 fprintf(stderr
, "warning: %s\n", err
);
1602 warnFL(char *err
,char *f
,int l
)
1610 fprintf(stderr
, ErrHdr
, f
, l
);
1611 fprintf(stderr
, " warning: %s\n", err
);
1622 /* back up the file number if we hit an error at the end of the last file */
1623 if ( CurFile
>= NumFiles
&& CurFile
>= 1 ) CurFile
--;
1624 fprintf(stderr
, ErrHdr
, FileStr
[CurFile
], zzline
);
1625 fprintf(stderr
, " warning: %s\n", err
);
1630 warnNoCR( char *err
)
1636 /* back up the file number if we hit an error at the end of the last file */
1637 if ( CurFile
>= NumFiles
&& CurFile
>= 1 ) CurFile
--;
1638 fprintf(stderr
, ErrHdr
, FileStr
[CurFile
], zzline
);
1639 fprintf(stderr
, " warning: %s", err
);
1650 fprintf(stderr
, "error: %s\n", err
);
1655 errFL(char *err
,char *f
,int l
)
1663 fprintf(stderr
, ErrHdr
, f
, l
);
1664 fprintf(stderr
, " error: %s\n", err
);
1675 /* back up the file number if we hit an error at the end of the last file */
1676 if ( CurFile
>= NumFiles
&& CurFile
>= 1 ) CurFile
--;
1677 fprintf(stderr
, ErrHdr
, FileStr
[CurFile
], zzline
);
1678 fprintf(stderr
, " error: %s\n", err
);
1683 errNoCR( char *err
)
1689 /* back up the file number if we hit an error at the end of the last file */
1690 if ( CurFile
>= NumFiles
&& CurFile
>= 1 ) CurFile
--;
1691 fprintf(stderr
, ErrHdr
, FileStr
[CurFile
], zzline
);
1692 fprintf(stderr
, " error: %s", err
);
1697 newUserAction(char *s
)
1703 UserAction
*ua
= (UserAction
*) calloc(1, sizeof(UserAction
));
1704 require(ua
!=NULL
, "cannot allocate UserAction");
1706 ua
->action
= (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
1707 strcpy(ua
->action
, s
);
1711 /* Added by TJP September 1994 */
1712 /* Take in file.h and return file_h; names w/o '.'s are left alone */
1715 gate_symbol(char *name
)
1721 static char buf
[100];
1723 sprintf(buf
, "%s", name
);
1725 for (p
=buf
; *p
!='\0'; p
++)
1727 if ( *p
=='.' ) *p
= '_';
1734 makeAltID(int blockid
, int altnum
)
1736 makeAltID(blockid
, altnum
)
1741 static char buf
[100];
1743 sprintf(buf
, "_blk%d_alt%d", blockid
, altnum
);
1744 p
= (char *)malloc(strlen(buf
)+1);