The new Asf+Sdf Meta-Environment is based on a new version of Sdf (syntax definition formalism). If you have an Asf+Sdf language definition developed with the old Asf+Sdf Meta-Environment you have to perform some (simple) modifications. For details concerning Sdf2 we refer to the PhD-thesis of Eelco Visser.
The main differences between Sdf1 and Sdf2 are in the range of lexical disambiguation.
module M ...
Sdf1: [!@#$%^] -> StrangeChar
Sdf2: [\!\@\#\$\%\^] -> StrangeChar
This has also effect on the way the layout characters are defined, the space character must be escaped.
Sdf1: [ \n\t\r] -> LAYOUT
Sdf2: [\ \n\t\r] -> LAYOUT
Sdf1: [\012] -> NL
Sdf2: [\010] -> NL
For example the priority definition section in Sdf1:
priorities "|" < "&"becomes
context-free priorities Bool "&" Bool -> Bool > Bool "|" Bool -> Bool
variables Bool [0-9']* -> BOOLbecomes
variables "Bool" [0-9\']* -> BOOL
module Layout exports lexical syntax [\ \t\n] -> LAYOUT "%%" ~[\n]* "\n" -> LAYOUT "%" ~[\%\n]+ "%" -> LAYOUT context-free restrictions LAYOUT? -/- [\ \t\n]
Besides the extra back-slash before the space symbol in the character class the main difference is the extra section "context-free restrictions". The purpose of this extra section is to force the parser to go on with recognizing layout as long as possible. The question mark behind "LAYOUT" is a new feature of Sdf2 and represents optional LAYOUT. Even if there is an empty recognizing non-terminal between two optional layouts.
Note that the use of these new features may prove to be problematic in combination with complilation and interpretation.
exports sorts Id lexical syntax [a-zA-Z][a-zA-Z0-9\_]* -> IdThe lexical token "Program" can be recognized in several ways, but by the prefer longest match rule only one interpretation is possible.
This longest match rule is enforced in Sdf2 as follows:
exports sorts Id lexical syntax [a-zA-Z][a-zA-Z0-9\_]* -> Id lexical restrictionsThe keyword "lexical" for "restrictions" is optional, the definition can also be written down as follows:-/- [a-zA-Z0-9\_]
exports sorts Id lexical syntax [a-zA-Z][a-zA-Z0-9\_]* -> Id context-free restrictions Id -/- [a-zA-Z0-9\_]When discussing the prefer keywords disambiguation rule we will come back to the prefer longest match rule.
To enforce this in Sdf2 we have to use the ``reject''-mechanism. Suppose we have the following context-free grammar rule
exports context-free syntax "if" Bool "then" Series "else" Series "fi" -> StatementThan there is an overlap between these keywords and the ``Id'' definition above. This problem is solved as follows in Sdf2:
exports context-free syntax "if" Bool "then" Series "else" Series "fi" -> Statement context-free syntax "if" -> Id {reject} "then" -> Id {reject} "else" -> Id {reject} "fi" -> Id {reject}In order to enforce that a list of characters like ``ifIdentifier'' is recognized as two separate Ids it may be wise to add also the following restrictions section:
restrictions "if" "then" "else" "fi" -/- [a-zA-Z0-9\_]This forces the parser not to stop after the "if" but to go on.