Changing domain name
[llvm-complete.git] / utils / Burg / main.c
blob19b62a3debf0b2169e39d8bba6812c7d4af3905f
1 char rcsid_main[] = "$Id$";
3 #include <math.h>
4 #include <stdio.h>
5 #include "b.h"
6 #include "fe.h"
8 int debugTables = 0;
9 static int simpleTables = 0;
10 static int internals = 0;
11 static int diagnostics = 0;
13 static char *inFileName;
14 static char *outFileName;
16 static char version[] = "BURG, Version 1.0";
18 extern int main ARGS((int argc, char **argv));
20 int
21 main(argc, argv) int argc; char **argv;
23 int i;
24 extern int atoi ARGS((const char *));
26 for (i = 1; argv[i]; i++) {
27 char **needStr = 0;
28 int *needInt = 0;
30 if (argv[i][0] == '-') {
31 switch (argv[i][1]) {
32 case 'V':
33 fprintf(stderr, "%s\n", version);
34 break;
35 case 'p':
36 needStr = (char**)&prefix;
37 break;
38 case 'o':
39 needStr = &outFileName;
40 break;
41 case 'I':
42 internals = 1;
43 break;
44 case 'T':
45 simpleTables = 1;
46 break;
47 case '=':
48 #ifdef NOLEX
49 fprintf(stderr, "'%s' was not compiled to support lexicographic ordering\n", argv[0]);
50 #else
51 lexical = 1;
52 #endif /* NOLEX */
53 break;
54 case 'O':
55 needInt = &principleCost;
56 break;
57 case 'c':
58 needInt = &prevent_divergence;
59 break;
60 case 'e':
61 needInt = &exceptionTolerance;
62 break;
63 case 'd':
64 diagnostics = 1;
65 break;
66 case 'S':
67 speedflag = 1;
68 break;
69 case 't':
70 trimflag = 1;
71 break;
72 case 'G':
73 grammarflag = 1;
74 break;
75 default:
76 fprintf(stderr, "Bad option (%s)\n", argv[i]);
77 exit(1);
79 } else {
80 if (inFileName) {
81 fprintf(stderr, "Unexpected Filename (%s) after (%s)\n", argv[i], inFileName);
82 exit(1);
84 inFileName = argv[i];
86 if (needInt || needStr) {
87 char *v;
88 char *opt = argv[i];
90 if (argv[i][2]) {
91 v = &argv[i][2];
92 } else {
93 v = argv[++i];
94 if (!v) {
95 fprintf(stderr, "Expection argument after %s\n", opt);
96 exit(1);
99 if (needInt) {
100 *needInt = atoi(v);
101 } else if (needStr) {
102 *needStr = v;
107 if (inFileName) {
108 if(freopen(inFileName, "r", stdin)==NULL) {
109 fprintf(stderr, "Failed opening (%s)", inFileName);
110 exit(1);
114 if (outFileName) {
115 if ((outfile = fopen(outFileName, "w")) == NULL) {
116 fprintf(stderr, "Failed opening (%s)", outFileName);
117 exit(1);
119 } else {
120 outfile = stdout;
124 yyparse();
126 if (!rules) {
127 fprintf(stderr, "ERROR: No rules present\n");
128 exit(1);
131 findChainRules();
132 findAllPairs();
133 doGrammarNts();
134 build();
136 debug(debugTables, foreachList((ListFn) dumpOperator_l, operators));
137 debug(debugTables, printf("---final set of states ---\n"));
138 debug(debugTables, dumpMapping(globalMap));
141 startBurm();
142 makeNts();
143 if (simpleTables) {
144 makeSimple();
145 } else {
146 makePlanks();
149 startOptional();
150 makeLabel();
151 makeKids();
153 if (internals) {
154 makeChild();
155 makeOpLabel();
156 makeStateLabel();
158 endOptional();
160 makeOperatorVector();
161 makeNonterminals();
162 if (internals) {
163 makeOperators();
164 makeStringArray();
165 makeRuleDescArray();
166 makeCostArray();
167 makeDeltaCostArray();
168 makeStateStringArray();
169 makeNonterminalArray();
171 makeLHSmap();
174 makeClosureArray();
176 if (diagnostics) {
177 reportDiagnostics();
180 yypurge();
181 exit(0);