https://svn.lrde.epita.fr/svn/xrm/trunk
Index: ChangeLog
from SIGOURE Benoit <sigoure.benoit(a)lrde.epita.fr>
Add static const arrays.
* src/str/array-decl-desugar.str: Add static const arrays.
* src/syn/xrm/XRM-Formula.sdf: New.
* src/syn/xrm/XRM-Constant.sdf: New.
* src/syn/xrm/XRM-Main.sdf: Import XRM-Formula and XRM-Constant.
* src/syn/xrm/Makefile.am: Update $(SDFS) and $(EXTRA_DIST)
* src/syn/prism/Makefile.am: Ditto.
* tests/xrm/consts.xpm: New.
* tests/test-parse-xrm.sh.in: Add missing line.
* TODO: Bring up to date.
TODO | 11 ++++++--
src/str/array-decl-desugar.str | 50 +++++++++++++++++++++++++++++++++++++
src/syn/prism/Makefile.am | 14 ++++++----
src/syn/xrm/Makefile.am | 25 ++++++++++++++----
src/syn/xrm/XRM-Constant.sdf | 55 +++++++++++++++++++++++++++++++++++++++++
src/syn/xrm/XRM-Formula.sdf | 10 +++++++
src/syn/xrm/XRM-Main.sdf | 2 +
tests/test-parse-xrm.sh.in | 1
tests/xrm/consts.xpm | 10 +++++++
9 files changed, 166 insertions(+), 12 deletions(-)
Index: src/str/array-decl-desugar.str
--- src/str/array-decl-desugar.str (revision 35)
+++ src/str/array-decl-desugar.str (working copy)
@@ -76,6 +76,8 @@
[ IntDec(ArrayAccess(idf, dims'), low, up, value) ])
where update-dimensions(|dims) => (x, current-dim', dims')
+
+
array-decl-desugar:
BoolDecNoInit(ArrayAccess(idf, dims))
//-> |[ for x from 0 to ~dim step 1 do x[i] : bool; end ]|
@@ -89,3 +91,51 @@
-> MetaFor(Identifier(x), Int("0"), current-dim',
Int("1"),
[ BoolDec(ArrayAccess(idf, dims'), value) ])
where update-dimensions(|dims) => (x, current-dim', dims')
+
+
+
+ array-decl-desugar:
+ ConstInt(ArrayAccess(idf, dims), value)
+ //-> |[ for x from 0 to ~dim step 1 do const int x[i] = ~value; end ]|
+ -> MetaFor(Identifier(x), Int("0"), current-dim',
Int("1"),
+ [ ConstInt(ArrayAccess(idf, dims'), value) ])
+ where update-dimensions(|dims) => (x, current-dim', dims')
+
+ array-decl-desugar:
+ ConstIntNoInit(ArrayAccess(idf, dims))
+ //-> |[ for x from 0 to ~dim step 1 do const int x[i]; end ]|
+ -> MetaFor(Identifier(x), Int("0"), current-dim',
Int("1"),
+ [ ConstIntNoInit(ArrayAccess(idf, dims')) ])
+ where update-dimensions(|dims) => (x, current-dim', dims')
+
+
+
+ array-decl-desugar:
+ ConstDouble(ArrayAccess(idf, dims), value)
+ //-> |[ for x from 0 to ~dim step 1 do const double x[i] = ~value; end ]|
+ -> MetaFor(Identifier(x), Int("0"), current-dim',
Int("1"),
+ [ ConstDouble(ArrayAccess(idf, dims'), value) ])
+ where update-dimensions(|dims) => (x, current-dim', dims')
+
+ array-decl-desugar:
+ ConstDoubleNoInit(ArrayAccess(idf, dims))
+ //-> |[ for x from 0 to ~dim step 1 do const double x[i]; end ]|
+ -> MetaFor(Identifier(x), Int("0"), current-dim',
Int("1"),
+ [ ConstDoubleNoInit(ArrayAccess(idf, dims')) ])
+ where update-dimensions(|dims) => (x, current-dim', dims')
+
+
+
+ array-decl-desugar:
+ ConstBool(ArrayAccess(idf, dims), value)
+ //-> |[ for x from 0 to ~dim step 1 do const bool x[i] = ~value; end ]|
+ -> MetaFor(Identifier(x), Int("0"), current-dim',
Int("1"),
+ [ ConstBool(ArrayAccess(idf, dims'), value) ])
+ where update-dimensions(|dims) => (x, current-dim', dims')
+
+ array-decl-desugar:
+ ConstBoolNoInit(ArrayAccess(idf, dims))
+ //-> |[ for x from 0 to ~dim step 1 do const bool x[i]; end ]|
+ -> MetaFor(Identifier(x), Int("0"), current-dim',
Int("1"),
+ [ ConstBoolNoInit(ArrayAccess(idf, dims')) ])
+ where update-dimensions(|dims) => (x, current-dim', dims')
Index: src/syn/xrm/XRM-Formula.sdf
--- src/syn/xrm/XRM-Formula.sdf (revision 0)
+++ src/syn/xrm/XRM-Formula.sdf (revision 0)
@@ -0,0 +1,10 @@
+module XRM-Formula
+imports PRISM-to-XRM
+exports
+
+ %% EBNF Grammar: Extended Formulas
+ %% FormulaDef ::= "formula" ArrayAccess "=" Expression
";"
+
+ context-free syntax
+ "formula" ArrayAccess "=" Expression ";"
+ -> FormulaDef {cons("FormulaDef")}
Index: src/syn/xrm/XRM-Main.sdf
--- src/syn/xrm/XRM-Main.sdf (revision 35)
+++ src/syn/xrm/XRM-Main.sdf (working copy)
@@ -9,3 +9,5 @@
XRM-Declaration
XRM-Update
XRM-Command
+ XRM-Formula
+ XRM-Constant
Index: src/syn/xrm/XRM-Constant.sdf
--- src/syn/xrm/XRM-Constant.sdf (revision 0)
+++ src/syn/xrm/XRM-Constant.sdf (revision 0)
@@ -0,0 +1,55 @@
+module XRM-Constant
+imports PRISM-to-XRM
+exports
+
+ %% EBNF Grammar: Extended Constants
+ %% ConstantDef ::= "const" "int" ArrayAccess ["="
Expression] ";"
+ %% | "const" "double" ArrayAccess ["="
Expression] ";"
+ %% | "const" "bool" ArrayAccess ["="
Expression] ";"
+ %%
+ %% (* old style constant defs for backwards compat *)
+ %% (* no type explicitly given => integers *)
+ %% | "const" ArrayAccess ["=" Expression]
";"
+ %% (* doubles *)
+ %% | "rate" ArrayAccess ["=" Expression]
";"
+ %% | "prob" ArrayAccess ["=" Expression]
";"
+
+ %% FIXME: This might not be the most efficiant way of using although it
+ %% should work thanks to the SGLR parser.
+
+ context-free syntax
+ "const" "int" ArrayAccess "=" Expression ";"
+ -> ConstantDef {cons("ConstInt")}
+
+ "const" ArrayAccess "=" Expression ";"
+ -> ConstantDef {cons("ConstInt")}
+
+
+
+ "const" "int" ArrayAccess ";" -> ConstantDef
{cons("ConstIntNoInit")}
+ "const" ArrayAccess ";" -> ConstantDef
{cons("ConstIntNoInit")}
+
+
+
+ "const" "double" ArrayAccess "=" Expression
";"
+ -> ConstantDef {cons("ConstDouble")}
+
+ "rate" ArrayAccess "=" Expression ";"
+ -> ConstantDef {cons("ConstDouble")}
+
+ "prob" ArrayAccess "=" Expression ";"
+ -> ConstantDef {cons("ConstDouble")}
+
+
+
+ "const" "double" ArrayAccess ";" -> ConstantDef
{cons("ConstDoubleNoInit")}
+ "rate" ArrayAccess ";" -> ConstantDef
{cons("ConstDoubleNoInit")}
+ "probe" ArrayAccess ";" -> ConstantDef
{cons("ConstDoubleNoInit")}
+
+
+
+ "const" "bool" ArrayAccess "=" Expression
";"
+ -> ConstantDef {cons("ConstBool")}
+
+ "const" "bool" ArrayAccess ";"
+ -> ConstantDef {cons("ConstBoolNoInit")}
Index: src/syn/xrm/Makefile.am
--- src/syn/xrm/Makefile.am (revision 35)
+++ src/syn/xrm/Makefile.am (working copy)
@@ -5,7 +5,7 @@
## Mail <sigoure.benoit(a)lrde.epita.fr>
##
## Started on Thu Apr 27 17:40:41 2006 SIGOURE Benoit
-## Last update Thu May 25 17:28:59 2006 SIGOURE Benoit
+## Last update Fri May 26 02:12:42 2006 SIGOURE Benoit
##
include $(top_srcdir)/config/Transformers.mk
@@ -41,12 +41,27 @@
XRM-StartSymbols.def \
XRM-Prefixed.def
-SDFS = XRM-Expression.sdf \
+SDFS = \
+ PRISM-to-XRM.sdf \
+ StrategoXRM.sdf \
+ XRM-Arrays.sdf \
+ XRM-Command.sdf \
+ XRM-Constant.sdf \
+ XRM-Declaration.sdf \
+ XRM-Expression.sdf \
+ XRM-Formula.sdf \
+ XRM-Literals.sdf \
XRM-Main.sdf \
- XRM.sdf \
- XRM-StartSymbols.sdf
+ XRM-MetaCongruences.sdf \
+ XRM-MetaFor.sdf \
+ XRM-MetaIf.sdf \
+ XRM-MetaVars.sdf \
+ XRM-Module.sdf \
+ XRM-StartSymbols.sdf \
+ XRM-Update.sdf \
+ XRM.sdf
-EXTRA_DIST = $(wildcard *.sdf)
+EXTRA_DIST = $(SDFS)
XRM.def: $(SDFS)
XRM-StartSymbols.def: $(SDFS)
Index: src/syn/prism/Makefile.am
--- src/syn/prism/Makefile.am (revision 35)
+++ src/syn/prism/Makefile.am (working copy)
@@ -5,7 +5,7 @@
## Mail <sigoure.benoit(a)lrde.epita.fr>
##
## Started on Thu Apr 27 17:40:41 2006 SIGOURE Benoit
-## Last update Thu May 25 17:28:59 2006 SIGOURE Benoit
+## Last update Fri May 26 02:12:29 2006 SIGOURE Benoit
##
include $(top_srcdir)/config/Transformers.mk
@@ -39,7 +39,8 @@
PRISM-StartSymbols.def \
PRISM-Prefixed.def
-SDFS = PRISM-Command.sdf \
+SDFS = \
+ PRISM-Command.sdf \
PRISM-Constant.sdf \
PRISM-Declaration.sdf \
PRISM-Expression.sdf \
@@ -51,17 +52,20 @@
PRISM-Label.sdf \
PRISM-Layout.sdf \
PRISM-Literals.sdf \
+ PRISM-Main.sdf \
+ PRISM-MetaCongruences.sdf \
+ PRISM-MetaVars.sdf \
PRISM-Module.sdf \
PRISM-ModulesFile.sdf \
PRISM-ModulesFileType.sdf \
PRISM-Reward.sdf \
+ PRISM-StartSymbols.sdf \
PRISM-SystemComposition.sdf \
PRISM-Update.sdf \
- PRISM-Main.sdf \
PRISM.sdf \
- PRISM-StartSymbols.sdf
+ StrategoPRISM.sdf
-EXTRA_DIST = $(wildcard *.sdf)
+EXTRA_DIST = $(SDFS)
PRISM.def: $(SDFS)
PRISM-StartSymbols.def: $(SDFS)
Index: tests/xrm/consts.xpm
--- tests/xrm/consts.xpm (revision 0)
+++ tests/xrm/consts.xpm (revision 0)
@@ -0,0 +1,10 @@
+for i from 0 to 4 do
+ const int x[i] = 2*i;
+end
+
+const int y[5];
+const z[5] = 42;
+const double d[3] = 3.14;
+rate c[4] = 42 > 3.14;
+probe d[4];
+const bool b[3] = true;
Index: tests/test-parse-xrm.sh.in
--- tests/test-parse-xrm.sh.in (revision 35)
+++ tests/test-parse-xrm.sh.in (working copy)
@@ -16,6 +16,7 @@
for file in `find "@srcdir@" -name '*.pm' -o -name '*.nm' -o
-name '*.sm' -o -name '*.xpm' | sort`; do
echo @ECHO_N@ " Parsing `basename $file` ... "
"@top_builddir@/src/tools/parse-xrm" -i "$file" -o /dev/null
+ rv=$?
if [ $? -eq 0 ]; then
echo 'OK, no ambiguities found'
test_pass=$((test_pass + 1))
Index: TODO
--- TODO (revision 35)
+++ TODO (working copy)
@@ -4,6 +4,9 @@
## Misc. ##
## ----- ##
+ * Check why make distcheck fails because of autom4te.cache ?!
+ ./configure && make # runs configure twice!?? (probably related)
+
* PRISM's parser has a ForLoop node:
Identifier "=" Expression ":" Expression [":"
Expression]
What the hell is this?
@@ -22,6 +25,12 @@
const int y = x;
Is it even possible to define a static const variable from another one?
+ * Improve the error messages using locations provided by addPosInfo when
+ they are available (xrm-front invoked with --add-pos|-P).
+ Some cases are very hard to handle for example array[N] where N is
+ static const int N = -1; will issue an error such as "undeclared meta
+ variable N" whereas the real problem is that array[N] couldn't be expanded.
+
## ---------- ##
## Extensions ##
## ---------- ##
@@ -62,8 +71,6 @@
x[1..3]?=0 => x_1=0 | x_2=0 | x_3=0
NOTE: x[5]?=0 should be considered as an error.
- NOTE: arrays should behave like in C (array[N] is ranging from 0 to N-1)
- I'm not sure it's really always handled this way ATM :/
* Add non-static array accesses (as suggested by Micha). For instance:
module test