aboutsummaryrefslogtreecommitdiffstats
path: root/test/littlesemantics/little_syntax.mly
diff options
context:
space:
mode:
authorlrg <lrg@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2006-10-20 10:38:22 +0000
committerlrg <lrg@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2006-10-20 10:38:22 +0000
commitf0198ebf9430d286ce7c9a53b703e967ce86481c (patch)
treeac069673f4a94e079bf12505c4f0a58baeea34ef /test/littlesemantics/little_syntax.mly
parenteb7c8587f462adca878088ef5f610c81734efc70 (diff)
downloadcompcert-f0198ebf9430d286ce7c9a53b703e967ce86481c.tar.gz
compcert-f0198ebf9430d286ce7c9a53b703e967ce86481c.zip
interpreter for "little"
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@119 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test/littlesemantics/little_syntax.mly')
-rw-r--r--test/littlesemantics/little_syntax.mly42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/littlesemantics/little_syntax.mly b/test/littlesemantics/little_syntax.mly
new file mode 100644
index 00000000..65575776
--- /dev/null
+++ b/test/littlesemantics/little_syntax.mly
@@ -0,0 +1,42 @@
+%{
+ open List;;
+ open Little;;
+%}
+%token T_VARIABLES T_IN T_END T_WHILE T_DO T_DONE T_ASSIGN T_PLUS
+%token T_SCOLUMN T_OPEN T_CLOSE T_OPEN_B T_CLOSE_B T_SKIP T_GT
+%token <int> NUM
+%token <string> ID
+%left T_PLUS
+%right T_SCOLUMN
+%type <unit> main
+%type <Little.inst> inst
+%start main
+%type <int> num
+%type <string> identifier
+%%
+main : T_VARIABLES environment T_IN inst T_END
+{ (print_env(execute(rev $2) $4); exit(0)) }
+;
+num : NUM { $1 }
+;
+identifier : ID { $1 }
+;
+variable_value : identifier num { ($1, $2) }
+;
+environment : { [] }
+| environment variable_value { $2::$1 }
+;
+inst: identifier T_ASSIGN exp { Assignment($1,$3) }
+| inst T_SCOLUMN inst { Sequence($1,$3) }
+| T_WHILE b_exp T_DO inst T_DONE { While($2,$4) }
+| T_SKIP { Skip }
+| T_OPEN_B inst T_CLOSE_B { $2 }
+;
+exp: num { Numeral($1) }
+| identifier { Variable($1) }
+| exp T_PLUS exp { Addition($1, $3); }
+| T_OPEN exp T_CLOSE { $2 }
+;
+b_exp: exp T_GT exp { Greater($1, $3) }
+;
+%%