Skip to content
Permalink
Browse files

Updated to newer rule table format: variables now permitted inside la…

…ter variables, single-state variables allowed as output, comments allowed after variable declarations.
  • Loading branch information...
tim.hutton
tim.hutton committed Apr 6, 2010
1 parent 546d3c4 commit 858d0bb979395060f4cd2da6e498af7ba5b00441
Showing with 30 additions and 12 deletions.
  1. +30 −12 src/ruletable.cpp
@@ -180,6 +180,9 @@ string ruletable::ReadFromFile(const string& filename)
oss << "Error reading " << filename << ": one or more of n_states, neighborhood or symmetries missing\nbefore first variable";
return oss.str();
}
// snip off any trailing comment
if(line.find('#')!=string::npos)
line.assign(line.begin(),line.begin()+line.find('#'));
// parse the rest of the line for the variable
vector<string> tokens = tokenize(line,"= {,}");
string variable_name = tokens[1];
@@ -192,22 +195,31 @@ string ruletable::ReadFromFile(const string& filename)
}
for(unsigned int i=2;i<tokens.size();i++)
{
unsigned int s;
if(sscanf(tokens[i].c_str(),"%d",&s)!=1)
if(variables.find(tokens[i])!=variables.end())
{
ostringstream oss;
oss << "Error reading " << filename << " on line " << lineno << ": " << line;
return oss.str();
// variables permitted inside later variables
states.insert(states.end(),variables[tokens[i]].begin(),variables[tokens[i]].end());
}
if(s<0 || s>=this->n_states)
else
{
ostringstream oss;
oss << "Error reading " << filename << " on line " << lineno << ": " << line << " - state value out of range";
return oss.str();
}
states.push_back((state)s);
unsigned int s;
if(sscanf(tokens[i].c_str(),"%d",&s)!=1)
{
ostringstream oss;
oss << "Error reading " << filename << " on line " << lineno << ": " << line;
return oss.str();
}
if(s<0 || s>=this->n_states)
{
ostringstream oss;
oss << "Error reading " << filename << " on line " << lineno << ": " << line << " - state value out of range";
return oss.str();
}
states.push_back((state)s);
}
}
variables[variable_name] = states;

}
else
{
@@ -306,7 +318,13 @@ string ruletable::ReadFromFile(const string& filename)
else
{
unsigned int s;
if(sscanf(tokens[n_inputs].c_str(),"%d",&s)!=1) // if not a bound variable, output must be a state
if(variables.find(tokens[n_inputs])!=variables.end() &&
variables[tokens[n_inputs]].size()==1)
{
// single-state variables are permitted as the output
s = variables[tokens[n_inputs]][0];
}
else if(sscanf(tokens[n_inputs].c_str(),"%d",&s)!=1) // if not a bound variable, output must be a state
{
ostringstream oss;
oss << "Error reading " << filename << " on line " << lineno << ": " << line;

0 comments on commit 858d0bb

Please sign in to comment.
You can’t perform that action at this time.