Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69774 - trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples
From: joel_at_[hidden]
Date: 2011-03-09 11:41:49


Author: djowel
Date: 2011-03-09 11:41:47 EST (Wed, 09 Mar 2011)
New Revision: 69774
URL: http://svn.boost.org/trac/boost/changeset/69774

Log:
The conjure PL
Added:
   trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/error.cnj (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/factorial.cnj (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/pow2.cnj (contents, props changed)
   trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/precedence.cnj (contents, props changed)

Added: trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/error.cnj
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/error.cnj 2011-03-09 11:41:47 EST (Wed, 09 Mar 2011)
@@ -0,0 +1,16 @@
+/* mini program with syntax error */
+
+int foo(n)
+{
+ int a = 2;
+ if (n @ 3) /* we don't have @ operator in conjure */
+ {
+ a = 3
+ }
+ return a;
+}
+
+int main()
+{
+ return foo(10);
+}
\ No newline at end of file

Added: trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/factorial.cnj
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/factorial.cnj 2011-03-09 11:41:47 EST (Wed, 09 Mar 2011)
@@ -0,0 +1,15 @@
+/* The factorial */
+
+int factorial(n)
+{
+ if (n <= 0)
+ return 1;
+ else
+ return n * factorial(n-1);
+}
+
+int main(n)
+{
+ return factorial(n);
+}
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/pow2.cnj
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/pow2.cnj 2011-03-09 11:41:47 EST (Wed, 09 Mar 2011)
@@ -0,0 +1,19 @@
+/* My first conjure program */
+
+int pow2(n)
+{
+ int a = 2;
+ int i = 1;
+ while (i < n)
+ {
+ a = a * 2;
+ i = i + 1;
+ }
+ return a;
+}
+
+int main()
+{
+ return pow2(10);
+}
+

Added: trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/precedence.cnj
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/compiler_tutorial/conjure_samples/precedence.cnj 2011-03-09 11:41:47 EST (Wed, 09 Mar 2011)
@@ -0,0 +1,8 @@
+/* testing the shunting yard operator precedence algorithm */
+
+int main()
+{
+ return 1 + 2 + 3 + 5 * 4 * 6 + 5; /* answer is 131 */
+}
+
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk