Typedefs | |
typedef wali::Triple < wali::Key, wali::Key, wali::Key > | KeyTriple |
READ_TRIPLE and READ_QUAD. | |
typedef wali::Quad< wali::Key, wali::Key, wali::Key, wali::Key > | KeyQuad |
Functions | |
void | discardws (std::istream &is) |
std::string | read_lit (std::istream &is, std::string const &lit) |
bool | is_lparen (int c) |
READ_TOKEN and READ_NAME. | |
bool | is_rparen (int c) |
std::string | read_token (std::istream &is) |
std::string | read_name (std::istream &is) |
KeyTriple | read_triple (std::istream &is) |
KeyQuad | read_quad (std::istream &is) |
template<typename UnitType > | |
std::vector< UnitType > | read_list (std::istream &is, UnitType(*unitParser)(std::istream &is)) |
READ_LIST. | |
std::vector< std::string > | read_name_list (std::istream &is) |
READ_NAME_LIST, READ_TRIPLE_LIST, READ_QUAD_LIST. | |
std::vector< KeyTriple > | read_triple_list (std::istream &is) |
std::vector< KeyQuad > | read_quad_list (std::istream &is) |
void | read_sigma_block (std::istream &is, NwaRefPtr nwa) |
READ_SIGMA_BLOCK, READ_STATE_BLOCK, READ_DELTA_BLOCK. | |
void | read_state_block (std::istream &is, NwaRefPtr nwa) |
void | read_delta_block (std::istream &is, NwaRefPtr nwa) |
void | read_block (std::istream &is, NwaRefPtr nwa) |
READ_BLOCK. | |
Variables | |
int | lineno |
DISCARDWS. |
READ_TRIPLE and READ_QUAD.
triple ::= '(' name ',' name ',' name ')' quad ::= '(' name ',' name ',' name ',' name ')'
Returns either a KeyTriple or a KeyQuad as appropriate; these are triples and quads of wali::Keys, not strings. Eats trailing WS.
void opennwa::parser::details::discardws | ( | std::istream & | is | ) |
References lineno.
Referenced by read_lit(), read_name(), and read_token().
std::string opennwa::parser::details::read_lit | ( | std::istream & | is, | |
std::string const & | lit | |||
) |
References discardws(), and lineno.
Referenced by read_delta_block(), read_list(), read_quad(), read_sigma_block(), read_state_block(), and read_triple().
bool opennwa::parser::details::is_lparen | ( | int | c | ) |
READ_TOKEN and READ_NAME.
token ::= ~(' ' | ',' | '(' | '}' | ')')+ name ::= token ('(' ~')'* ')')? // lookahead '(' means take opt
Both return the actual identifier as a string. In other words, in the 'name' production, the optional (blahblah) stuff is ignored. Also eats trailing WS.
TODO: fix comment to take into account matched parens and different paren types -Evan 3/4/11
Referenced by read_token().
bool opennwa::parser::details::is_rparen | ( | int | c | ) |
Referenced by read_token().
std::string opennwa::parser::details::read_token | ( | std::istream & | is | ) |
References discardws(), is_lparen(), and is_rparen().
Referenced by read_name().
std::string opennwa::parser::details::read_name | ( | std::istream & | is | ) |
References discardws(), and read_token().
Referenced by read_quad(), and read_triple().
KeyTriple opennwa::parser::details::read_triple | ( | std::istream & | is | ) |
References wali::getKey(), wali::make_triple(), read_lit(), and read_name().
KeyQuad opennwa::parser::details::read_quad | ( | std::istream & | is | ) |
References wali::getKey(), wali::make_quad(), read_lit(), and read_name().
std::vector<UnitType> opennwa::parser::details::read_list | ( | std::istream & | is, | |
UnitType(*)(std::istream &is) | unitParser | |||
) |
READ_LIST.
This is a generic method for reading something of the form ( NONTERM (',' NONTERM)* )? (You can think of it as a parser combinator.) For each instaniation, a lookahead of '}' or end-of-file at the beginning means to skip the whole thing. When deciding whether to take another iteration of the "loop", a lookahead of ',' means "yes" and a lookahead of anything else means no.
The parser calls 'unitParser' for each item in the list; the unitParser should return a 'UnitType'. (For instance, to read a list of names, pass 'stdstring' for 'UnitType' and 'read_name' for 'unitParser'.) It then returns a vector of all semantic objects read during the list.
We test a couple instantiations below; essentailly he 'read_name_list', 'read_triple_list', and 'read_quad_list' functions below are just named instantiations of this with 'unitParser' bound to the appropriate thing.
[There /may/ be a way to make this infer the 'UnitType' from the return type of 'unitParser', but I don't think that's possible until the alternate function declaration syntax in C++0x.]
References read_lit().
std::vector<std::string> opennwa::parser::details::read_name_list | ( | std::istream & | is | ) |
READ_NAME_LIST, READ_TRIPLE_LIST, READ_QUAD_LIST.
name-list ::= (name (',' name)*)? triple-list ::= (triple (',' triple)*)? quad-list ::= (quad (',' quad)*)?
Returns a vector of strings (for name-list), KeyTriples, and KeyQuads as appropriate.
Referenced by read_sigma_block(), and read_state_block().
std::vector<KeyTriple> opennwa::parser::details::read_triple_list | ( | std::istream & | is | ) |
Referenced by read_delta_block().
std::vector<KeyQuad> opennwa::parser::details::read_quad_list | ( | std::istream & | is | ) |
Referenced by read_delta_block().
void opennwa::parser::details::read_sigma_block | ( | std::istream & | is, | |
NwaRefPtr | nwa | |||
) |
READ_SIGMA_BLOCK, READ_STATE_BLOCK, READ_DELTA_BLOCK.
state-block ::= 'Q:' '{'? name-list '}'? | 'Q0:' '{'? name-list '}'? | 'Qf:' '{'? name-list '}'?
sigma-block ::= 'sigma:' '{'? name-list '}'?
delta-block ::= 'delta_i:' '{'? triple-list '}'? | 'delta_c:' '{'? triple-list '}'? | 'delta_r:' '{'? quad-list '}'?
These functions read the given block. This is where the actual semantic action to add things to an NWA are carried out. (Unfortunately this aspect is not unit tested at the moment, but it's relatively simple...)
read_sigma_block is the easiest because it doesn't have to make any decisionns. read_state_block and read_delta_block read the common prefix of the rules ("Q" and "delta_" resp.) since they are LL(k) but not LL(1), then branch to the appropriate case.
Since we don't test the semantic action of adding to the NWA, we only test the recognizing ability of these. I'd need a mock NWA to test the semantic action.
References wali::getKey(), read_lit(), and read_name_list().
Referenced by read_block().
void opennwa::parser::details::read_state_block | ( | std::istream & | is, | |
NwaRefPtr | nwa | |||
) |
References wali::getKey(), read_lit(), and read_name_list().
Referenced by read_block().
void opennwa::parser::details::read_delta_block | ( | std::istream & | is, | |
NwaRefPtr | nwa | |||
) |
References read_lit(), read_quad_list(), and read_triple_list().
Referenced by read_block().
void opennwa::parser::details::read_block | ( | std::istream & | is, | |
NwaRefPtr | nwa | |||
) |
READ_BLOCK.
block ::= state-block // lookahead = 'Q' | sigma-block // lookahead = 's' | delta-block // lookahead = 'd'
Reads a block (any kind) and as a semantic action adds the appropriate state/letter/transition to the NWA.
References read_delta_block(), read_sigma_block(), and read_state_block().
DISCARDWS.
Discards any whitespace (see std::isspace) that appears at the start of 'is'.
Referenced by discardws(), and read_lit().