You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should add support for writing specifications in the nanopass style in Silver. This is also motivated for being able to explore extensions that use closed nonterminals and translation attributes instead of forwarding.
My proposal is that we just represent different languages in the nanopass form as grammars in Silver, with nonterminal/production/equation declarations copied from one language to the next. This requires two main features - a way to include a grammar in another grammar with some modifications, and a way to define and propagate the equations for translation passes.
For example, one may define the host language specification using regular nonterminals in grammar my:lang:host. If using the translation pass model for extensions, one can define their "pre-host" extended syntax language:
grammar my:lang:ext;
imports my:lang:host as h;
include my:lang:host {
close nonterminals Expr, Stmt, Type;
exclude productions intAdd, floatAdd, ...;
}
translation pass toHost from my:lang:ext to my:lang:host;
propagate toHost on Expr, Stmt, Type excluding someExtProd;
production addOp
top::Expr ::= e1::Expr e2::Expr
{ top.toHost = e1.typerep.addProd(@e1, @e2); }
dispatch AddOp = Expr ::= h:Expr h:Expr;
synthesized attribute addProd::AddOp occurs on Type;
...
Here the include declaration includes all the nonterminals, productions, attributes, occurrences and equations from my:lang:host, aside from those explicitly filtered out. One can specify close nonterminals or open nonterminals to change the closedness of included nonterminals. Excluding an attribute filters out its occurrences and equations.
The translation pass declaration defines the toHost translation attribute. This is also a new sort of automatic attribute that can be propagated. A translation pass attribute automatically occurs on all nonterminals in the source language that also appear in the target language. Translation pass attributes are automatically excluded from the include specifications.
One can also change attributes into annotations, for example a pass that does desugaring of for loops into while loops after the host language:
grammar my:lang:l1;
imports my:lang:host as h;
include my:lang:host {
exclude productions forLoop;
exclude attributes defs, errors;
annotate attributes env, typerep;
}
translation pass toL1 from my:lang:host to my:lang:l1;
propagate toL1 on Expr, Stmt, Type excluding h:forLoop;
aspect production h:forLoop
top::h:Stmt ::= i::h:Name l::h:Expr u::h:Expr b::h:Stmt
{
top.tol1 = seq(varDecl(@i.toL1, @l.tol1, env=top.env.toL1), whileLoop(...)), env=top.env.toL1;
}
Here the propagate for toL1 will supply any annotations with the same name as the attributes occuring on the host nonterminals.
The text was updated successfully, but these errors were encountered:
We should add support for writing specifications in the nanopass style in Silver. This is also motivated for being able to explore extensions that use closed nonterminals and translation attributes instead of forwarding.
My proposal is that we just represent different languages in the nanopass form as grammars in Silver, with nonterminal/production/equation declarations copied from one language to the next. This requires two main features - a way to include a grammar in another grammar with some modifications, and a way to define and propagate the equations for translation passes.
For example, one may define the host language specification using regular nonterminals in grammar
my:lang:host
. If using the translation pass model for extensions, one can define their "pre-host" extended syntax language:Here the
include
declaration includes all the nonterminals, productions, attributes, occurrences and equations frommy:lang:host
, aside from those explicitly filtered out. One can specifyclose nonterminals
oropen nonterminals
to change the closedness of included nonterminals. Excluding an attribute filters out its occurrences and equations.The
translation pass
declaration defines thetoHost
translation attribute. This is also a new sort of automatic attribute that can bepropagate
d. A translation pass attribute automatically occurs on all nonterminals in the source language that also appear in the target language. Translation pass attributes are automatically excluded from theinclude
specifications.One can also change attributes into annotations, for example a pass that does desugaring of for loops into while loops after the
host
language:Here the
propagate
fortoL1
will supply any annotations with the same name as the attributes occuring on the host nonterminals.The text was updated successfully, but these errors were encountered: