https://svn.lrde.epita.fr/svn/xrm/trunk
Index: ChangeLog
from SIGOURE Benoit <sigoure.benoit(a)lrde.epita.fr>
Fix boxing of meta-if at Expression level.
The new test fails because of an ambiguity. This ambiguity is a bit
tricky and (IMHO) must be resolved at the grammar level.
Basically we have:
test1 ? test1-true : test2 ? test2-true : test2-false
The ambiguity is:
(test1 ? test1-true : test2) ? test2-true : test2-false
-or-
test1 ? test1-true : (test2 ? test2-true : test2-false)
The second choice seems more natural and that's how it works in C.
Obviously we can't keep this ambiguity in the grammar.
* tests/xrm/amb-if-exp.xpm: New.
* src/lib/xrm/pp/xrm-meta-if.str: Fix boxing of meta-if.
src/lib/xrm/pp/xrm-meta-if.str | 29 +++++++++++++++++++++++++++++
tests/xrm/amb-if-exp.xpm | 14 ++++++++++++++
2 files changed, 43 insertions(+)
Index: tests/xrm/amb-if-exp.xpm
--- tests/xrm/amb-if-exp.xpm (revision 0)
+++ tests/xrm/amb-if-exp.xpm (revision 0)
@@ -0,0 +1,14 @@
+for y from 0 to height - 1 do
+ module sensor
+ [] true -> (s'=test1 ? test1-true : test2 ? test2-true : test2-false);
+ endmodule
+end
+
+// amb
+
+//bad:
+// (test1 ? test1-true : test2) ? test2-true : test2-false
+
+//good:
+// test1 ? test1-true : (test2 ? test2-true : test2-false)
+//at least that's how it works in C and it feels more natural.
Index: src/lib/xrm/pp/xrm-meta-if.str
--- src/lib/xrm/pp/xrm-meta-if.str (revision 56)
+++ src/lib/xrm/pp/xrm-meta-if.str (working copy)
@@ -2,11 +2,16 @@
rules
+ /* Boxing for if statements at top level or inside modules.
+ * Their then-part and else-part are lists.
+ */
+
prism-to-box:
MetaIf(condition, then-part)
-> V[ V is=2 [ H hs=1 [ KW["if"] ~condition KW["then"] ]
~*then-part ]
KW["end"]]
+ where <is-list> then-part
prism-to-box:
MetaIf(condition, then-part, else-part)
@@ -14,3 +19,27 @@
~*then-part ]
V is=2 [ KW["else"] ~*else-part ]
KW["end"]]
+ where <is-list> then-part
+ ; <is-list> else-part
+
+ /* Boxing for if statements at the Expression level.
+ * Their then-part and else-part are not list but instead simple elements.
+ * This is due to the fact that the language as no way to express
+ * statements nor expression sequences at Expression level.
+ */
+
+ prism-to-box:
+ MetaIf(condition, then-part)
+ -> V[ V is=2 [ H hs=1 [ KW["if"] ~condition KW["then"] ]
+ ~then-part ]
+ KW["end"]]
+ where <not(is-list)> then-part
+
+ prism-to-box:
+ MetaIf(condition, then-part, else-part)
+ -> V[ V is=2 [ H hs=1 [ KW["if"] ~condition KW["then"] ]
+ ~then-part ]
+ V is=2 [ KW["else"] ~else-part ]
+ KW["end"]]
+ where <not(is-list)> then-part
+ ; <not(is-list)> else-part