1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
/*
bisonc++.cc
*/
#include "main.ih"
using namespace std;
using namespace FBB;
namespace
{
Arg::LongOption longOptions[] =
{
Arg::LongOption{"analyze-only", 'A'},
Arg::LongOption{"baseclass-header", 'b'}, // also directive
Arg::LongOption{"baseclass-preinclude", 'H'}, // also directive
{"baseclass-skeleton", 'B'},
Arg::LongOption{"class-header", 'c'}, // also directive
Arg::LongOption{"class-name", Arg::Required}, // also directive
Arg::LongOption{"class-skeleton", 'C'},
Arg::LongOption{"construction"},
// implies verbose, but also shows
// FIRST and FOLLOW sets as well as
// the full set of states, including
// the non-kernel items
Arg::LongOption{"debug"}, // also directive
Arg::LongOption{"default-actions", 'd'}, // also directive
Arg::LongOption{"error-verbose"}, // also directive
Arg::LongOption{"filenames", 'f'}, // also directive
Arg::LongOption{"flex"}, // also directive
Arg::LongOption{"help", 'h'},
Arg::LongOption{"implementation-header", 'i'}, // also directive
Arg::LongOption{"implementation-skeleton", 'I'},
Arg::LongOption{"insert-stype"},
Arg::LongOption{"max-inclusion-depth", Arg::Required},
Arg::LongOption{"namespace", 'n'}, // also directive
Arg::LongOption{"no-baseclass-header"},
Arg::LongOption{"no-decoration", 'D'},
Arg::LongOption{"no-lines"}, // also directive
Arg::LongOption{"no-parse-member"},
Arg::LongOption{"own-debug"},
Arg::LongOption{"own-tokens", 'T'},
Arg::LongOption{"parsefun-skeleton", 'P'},
Arg::LongOption{"parsefun-source", 'p'}, // also directive
Arg::LongOption{"polymorphic-code-skeleton", 'L'},
Arg::LongOption{"polymorphic-skeleton", 'M'},
Arg::LongOption{"print-tokens", 't'}, // also directive
Arg::LongOption{"prompt"}, // also directive
Arg::LongOption{"required-tokens", Arg::Required}, // also directive
Arg::LongOption{"scanner", 's'}, // also directive
// also directive
Arg::LongOption{"scanner-class-name", Arg::Required},
Arg::LongOption{"scanner-debug"},
// also directive
Arg::LongOption{"scanner-matched-text-function", Arg::Required},
// also directive
Arg::LongOption{"scanner-token-function", Arg::Required},
Arg::LongOption{"show-filenames"},
Arg::LongOption{"skeleton-directory", 'S'},
Arg::LongOption{"stack-expansion", Arg::Required},
Arg::LongOption{"tag-mismatches", Arg::Required}, // also directive
Arg::LongOption{"target-directory", Arg::Required}, // also directive
Arg::LongOption{"thread-safe"}, // also directive
Arg::LongOption{"token-path", 'F'}, // also directive
Arg::LongOption{"token-class", 'K'}, // also directive
Arg::LongOption{"token-namespace", 'N'}, // also directive
Arg::LongOption{"usage", 'h'},
Arg::LongOption{"verbose", 'V'},
// shows rules, tokens, final states and kernel
// items, and describes conflicts when found
Arg::LongOption{"version", 'v'},
};
auto longEnd = longOptions +
sizeof(longOptions) / sizeof(Arg::LongOption);
}
int main(int argc, char **argv)
try
{
Arg &arg = Arg::initialize(
"AB:b:C:c:d:DF:f:H:hI:i:K:L:M:n:N:p:P:Qs:S:tTVv",
longOptions, longEnd, argc, argv);
arg.versionHelp(usage, version, 1);
Rules rules;
Parser parser(rules);
// parser.setDebug(Parser::ACTIONCASES | Parser::ON);
int ret = parser.parse(); // parses the input, fills the data in the
// Rules read the grammar file, build required
// data structures.
if (arg.option('Q'))
{
cout << "parsing returns " << ret << '\n';
return 0;
}
parser.cleanup(); // do cleanup actions following parse()
// (terminate if parsing produced errors)
rules.updatePrecedences(); // update production rule precedences
rules.showRules();
rules.showTerminals();
rules.determineFirst();
rules.showFirst();
// define the startproduction
Production::setStart(rules.startProduction());
State::define(rules); // define all states
rules.assignNonTerminalNumbers();
rules.showUnusedTerminals();
rules.showUnusedNonTerminals();
rules.showUnusedRules();
State::allStates();
Grammar grammar;
grammar.deriveSentence();
if (emsg.count())
return 1;
if (arg.option('A')) // Analyze only
return 0;
Generator generator(rules, parser.releasePolymorphic());
if (generator.conflicts())
return 1;
generator.baseClassHeader();
generator.classHeader();
generator.implementationHeader();
generator.parseFunction();
}
catch(exception const &err)
{
cerr << err.what() << '\n';
return 1;
}
catch(int x)
{
return Arg::instance().option("hv") ? 0 : x;
}
|