if ( machineSpec == 0 && machineName == 0 )
outputBuffer << "</host>\n";
- checkMachines();
-
if ( gblErrorCount > 0 )
return 1;
using namespace std;
-char machineMain[] = "main";
+char mainMachine[] = "main";
void Token::set( char *str, int len )
{
/* Make all the instantiations, we know that main exists in this list. */
initNameWalk();
for ( GraphList::Iter glel = instanceList; glel.lte(); glel++ ) {
- if ( strcmp( glel->key, machineMain ) == 0 ) {
+ if ( strcmp( glel->key, mainMachine ) == 0 ) {
/* Main graph is always instantiated. */
mainGraph = makeInstance( glel );
}
}
}
+ if ( mainGraph == 0 )
+ mainGraph = graphs[--numOthers];
+
if ( numOthers > 0 ) {
/* Add all the other graphs into main. */
mainGraph->globOp( graphs, numOthers );
pdel->value->token( loc, _eof, 0, 0 );
}
-void checkMachines( )
-{
- for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
- ParseData *pd = parser->value->pd;
- if ( pd->instanceList.length() > 0 ) {
- /* There must be a main graph defined. */
- /* No machine name. Need to have a main. Make sure it was given. */
- GraphDictEl *mainEl = pd->graphDict.find( machineMain );
- if ( mainEl == 0 ) {
- error(pd->sectionLoc) << "main graph not defined in \"" <<
- pd->sectionName << "\"" << endl;
- }
- }
- }
-}
-
void writeLanguage( std::ostream &out )
{
out << " lang=\"";
extern bool printStatistics;
extern int gblErrorCount;
-extern char machineMain[];
+extern char mainMachine[];
/* Location in an input file. */
struct InputLoc
void scan( char *fileName, std::istream &input, std::ostream &output );
void terminateAllParsers( );
-void checkMachines( );
void writeMachines( std::ostream &out, std::string hostData, char *inputFileName );
void xmlEscapeHost( std::ostream &out, char *data, int len );
opt_export machine_name '=' join ';' final {
/* Main machine must be an instance. */
bool isInstance = false;
- if ( strcmp($2->token.data, machineMain) == 0 ) {
+ if ( strcmp($2->token.data, mainMachine) == 0 ) {
warning($2->token.loc) <<
"main machine will be implicitly instantiated" << endl;
isInstance = true;
writeConditions();
/* Start state. */
- out << " <start_state>" << fsm->startState->alg.stateNum <<
- "</start_state>\n";
+ GraphDictEl *mainEl = pd->graphDict.find( mainMachine );
+ if ( mainEl != 0 ) {
+ out << " <start_state>" << fsm->startState->alg.stateNum <<
+ "</start_state>\n";
+ }
/* Error state. */
if ( fsm->errState != 0 ) {
redFsm->stateList.append( allStates+s );
/* We get the start state as an offset, set the pointer now. */
- assert( startState >= 0 );
- redFsm->startState = allStates + startState;
+ if ( startState >= 0 )
+ redFsm->startState = allStates + startState;
if ( errState >= 0 )
redFsm->errState = allStates + errState;
for ( EntryIdVect::Iter en = entryPointIds; en.lte(); en++ )
forcedErrorState(false),
nextActionId(0),
nextTransId(0),
+ startState(0),
errState(0),
errTrans(0),
firstFinState(0),
/* Add back to the state list from the start state and all other entry
* points. */
- depthFirstOrdering( startState );
+ if ( startState != 0 )
+ depthFirstOrdering( startState );
for ( RedStateSet::Iter en = entryPoints; en.lte(); en++ )
depthFirstOrdering( *en );
if ( forcedErrorState )
void FsmCodeGen::writeInit()
{
out << " {\n";
- out << "\t" << CS() << " = " << START() << ";\n";
+
+ if ( redFsm->startState != 0 )
+ out << "\t" << CS() << " = " << START() << ";\n";
/* If there are any calls, then the stack top needs initialization. */
if ( redFsm->anyActionCalls() || redFsm->anyActionRets() )
void FsmCodeGen::STATE_IDS()
{
- STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n";
+ if ( redFsm->startState != 0 )
+ STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n";
if ( writeFirstFinal )
STATIC_VAR( "int" , FIRST_FINAL() ) << " = " << FIRST_FINAL_STATE() << ";\n";
"\n";
}
- STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n";
+ if ( redFsm->startState != 0 )
+ STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n";
if ( writeFirstFinal )
STATIC_VAR( "int" , FIRST_FINAL() ) << " = " << FIRST_FINAL_STATE() << ";\n";
void JavaTabCodeGen::writeInit()
{
out << " {\n";
- out << "\t" << CS() << " = " << START() << ";\n";
+
+ if ( redFsm->startState != 0 )
+ out << "\t" << CS() << " = " << START() << ";\n";
/* If there are any calls, then the stack top needs initialization. */
if ( redFsm->anyActionCalls() || redFsm->anyActionRets() )
void RubyCodeGen::writeInit()
{
- out << INDENT_U() << "begin"
- << INDENT_S() << CS() << " = " << START();
+ out << INDENT_U() << "begin";
+
+ if ( redFsm->startState != 0 )
+ out << INDENT_S() << CS() << " = " << START();
/* If there are any calls, then the stack top needs initialization. */
if ( redFsm->anyActionCalls() || redFsm->anyActionRets() )
"\n";
}
- STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n";
+ if ( redFsm->startState != 0 )
+ STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n";
if ( writeFirstFinal )
STATIC_VAR( "int" , FIRST_FINAL() ) << " = " << FIRST_FINAL_STATE() << ";\n";
c3 . '.'* '\n' @{ printf( "c3\n" );}
)*;
- main := any*;
+ some_other := any*;
}%%
%% write exports;
int test( const char *data, int len )
{
- int cs;
+ int cs = test_en_commands;
const char *p = data, *pe = data + len;
- cs = test_en_commands;
+ %% write init;
%% write exec;
if ( cs >= test_first_final )
c3 . '.'* '\n' @{ System.out.println( "c3" );}
)*;
- main := any*;
+ other := any*;
}%%
%% write exports;
static void test( char data[] )
{
- int cs, p = 0, pe = data.length;
+ int cs = test_en_commands, p = 0, pe = data.length;
int top;
- cs = test_en_commands;
+ %% write init;
%% write exec;
if ( cs >= test_first_final )
c3 . '.'* '\n' @{ puts "c3"; }
)*;
- main := any*;
+ other := any*;
}%%
%% write exports;
def run_machine( data )
p = 0;
pe = data.length
- cs = 0
- cs = 0
+ cs = test_en_commands
val = 0;
neg = false;
- cs = test_en_commands;
%% write exec;
%% write eof;
if cs >= test_first_final