[antlr-interest] Semantic Predicates inside syntactic ones?
Ric Klaren
klaren at cs.utwente.nl
Tue Dec 9 03:59:54 PST 2003
On Tue, Dec 09, 2003 at 11:55:06AM +0100, Ric Klaren wrote:
> assignment:
> ( #( "=" id:IDENTIFIER { isClock(#id->getSymbol() ) }? (INT|FLOAT) ) ) =>
> #( "=" IDENTIFIER ( INT | FLOAT ) )
> {
> // generate clock reset code
> }
> | #( "=" write_expr[output,false] { output << "->setValue( "; }
> write_expr[output,true] )
> {
> output << " )";
> }
> | ... ;
Actually.. it can be solved quite nice without antlr tampering by adding an
extra rule:
isClockReset returns [bool ok]:
#( "=" id:IDENTIFIER ( i:INT | f:FLOAT ) )
{
double val;
if( #i )
{
std::istringstream rf(#i->getText());
rf >> val;
}
if( #f )
{
std::istringstream rf(#f->getText());
rf >> val;
}
SymbolInformation* si = data.getModel()->getSymbolInformation();
ok = si->is_clock(#id->getSymbol()) && val == 0;
}
;
exception
catch [antlr::RecognitionException &ex]
{
// prevent exceptions from obstructing things
ok = false;
}
assignment:
{ isClockReset(#assignment_in) }? #( "=" lhs0:write_expr[output,false] ( INT | FLOAT ) )
{
output << "->setValue( model->getGlobalClock() )";
varname_collector->execute( lhs0, vars );
}
| #( "=" lhs1:write_expr[output,false] { output << "->setValue( "; }
rhs1:write_expr[output,true] )
{ output << " )"; }
| ...;
Guess the motto is if one predicate does not the work the other will, it's
only tedious that antlr does not help very much with this..
Cheers,
Ric
--
-----+++++*****************************************************+++++++++-------
---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722 ----
-----+++++*****************************************************+++++++++-------
"You know how to use that thing?" [pointing to the sword]
"Sure.. The pointy end goes into the other guy."
--- The Mask of Zorro
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list