powered by nequal
Home » Acme_BrainPhack » Timeline » 1571

Changeset 1571 -- 2010-01-23 23:52:06

Comment
[Package Release] Acme_BrainPhack

Diffs

Acme_BrainPhack/tags/release-1.0.0-20100123235206/LICENSE

@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/Translator.php

@@ -0,0 +1,127 @@
+<?php
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+/**
+ * BrainF*ck Translator
+ *
+ * @author msakamoto-sf <sakamoto-gsyc-3s@glamenv-septzen.net>
+ * @package Acme_BrainPhack
+ * @since 0.0.1
+ */
+class Acme_BrainPhack_Translator
+{
+    // {{{ translate()
+
+    function translate($map, $src)
+    {
+        $conv = '';
+
+        $src_len = mb_strlen($src);
+        if (0 == $src_len) {
+            return $conv;
+        }
+
+        // expand map to convert table
+        $needles = array();
+        foreach ($map as $k => $v) {
+            if (is_array($v)) {
+                foreach ($v as $_v) {
+                    $needles[$_v] = $k;
+                }
+            } else if(is_string($k)) {
+                $needles[$v] = $k;
+            }
+        }
+
+        $last_pos = $src_len;
+
+        while ($src_len > 0) {
+
+            $found = false;
+            $pos_min = $src_len;
+            $_needle = '';
+            $_v = '';
+            foreach ($needles as $needle => $v) {
+                $pos = mb_strpos($src, $needle);
+                if (false === $pos) {
+                    continue;
+                }
+                if ($pos_min > $pos) {
+                    $pos_min = $pos;
+                    $_needle = $needle;
+                    $_v = $v;
+                }
+                $found = true;
+            }
+            if (!$found) {
+                break;
+            }
+            //echo "={$_needle}/{$_v}:{$pos_min}=\n";
+            $_cut_len = mb_strlen($_needle);
+            $src = mb_substr($src, $pos_min + $_cut_len);
+            $conv .= $_v;
+            //echo ">{$src}<\n";
+        }
+
+        return $conv;
+    }
+
+    // }}}
+    // {{{ getMapper()
+
+    function &getMapper($name = 'None')
+    {
+
+        /*
+         * simple and easy implementation.
+         * don't need consideratioons about error handling and
+         * mapper instance memory performance, yet.
+         */
+
+        $__base_dir = dirname(__FILE__);
+        $_name = strtr($name, '_', '/');
+        $_filename = realpath($__base_dir . '/Translator/' . $_name . '.php');
+
+        include_once($_filename);
+
+        $klassname = 'Acme_BrainPhack_Translator_' . $name;
+
+        $ret =& new $klassname();
+
+        return $ret;
+    }
+
+    // }}}
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/Translator.php
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/MemoryStack_TestCase.php

@@ -0,0 +1,180 @@
+<?php
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+/**
+ * requires
+ */
+require_once('Acme/BrainPhack/MemoryStack.php');
+
+class MemoryStack_TestCase extends UnitTestCase
+{
+
+    function testConstructorAndPointerIncDec()
+    {
+        // create 3 sized memory stack
+        $bpms =& new Acme_BrainPhack_MemoryStack(3);
+
+        // decrement -> lesser than 0, return false
+        $r = $bpms->ptr_dec();
+        $this->assertIdentical(false, $r);
+
+        list($old, $new) = $bpms->ptr_inc();
+        $this->assertIdentical(0, $old);
+        $this->assertIdentical(1, $new);
+
+        list($old, $new) = $bpms->ptr_inc();
+        $this->assertIdentical(1, $old);
+        $this->assertIdentical(2, $new);
+
+        list($old, $new) = $bpms->ptr_inc();
+        $this->assertIdentical(2, $old);
+        $this->assertIdentical(3, $new);
+
+        // increment -> size over, return false
+        $r = $bpms->ptr_inc();
+        $this->assertIdentical(false, $r);
+
+        list($old, $new) = $bpms->ptr_dec();
+        $this->assertIdentical(3, $old);
+        $this->assertIdentical(2, $new);
+
+        list($old, $new) = $bpms->ptr_dec();
+        $this->assertIdentical(2, $old);
+        $this->assertIdentical(1, $new);
+
+        list($old, $new) = $bpms->ptr_dec();
+        $this->assertIdentical(1, $old);
+        $this->assertIdentical(0, $new);
+    }
+
+    function testGetterSetterAndMemoryInitialize()
+    {
+        // default, initialized by 0
+        $bpms =& new Acme_BrainPhack_MemoryStack(3);
+        $r = $bpms->get();
+        $this->assertIdentical(0, $r);
+        $bpms->ptr_inc();
+        $r = $bpms->get();
+        $this->assertIdentical(0, $r);
+        $bpms->ptr_inc();
+        $r = $bpms->get();
+        $this->assertIdentical(0, $r);
+
+        // initialized by 1
+        $bpms =& new Acme_BrainPhack_MemoryStack(3, 1);
+        $r = $bpms->get();
+        $this->assertIdentical(1, $r);
+        $bpms->ptr_inc();
+        $r = $bpms->get();
+        $this->assertIdentical(1, $r);
+        $bpms->ptr_inc();
+        $r = $bpms->get();
+        $this->assertIdentical(1, $r);
+
+        // initialized by 'A'
+        $bpms =& new Acme_BrainPhack_MemoryStack(3, 'A');
+        $r = $bpms->get();
+        $this->assertIdentical('A', $r);
+        $bpms->ptr_inc();
+        $r = $bpms->get();
+        $this->assertIdentical('A', $r);
+        $bpms->ptr_inc();
+        $r = $bpms->get();
+        $this->assertIdentical('A', $r);
+
+        // setter test
+        $old = $bpms->set('B');
+        $this->assertIdentical('A', $r);
+        $r = $bpms->get();
+        $this->assertIdentical('B', $r);
+
+        // get/set with pointer address
+        $r = $bpms->get(1);
+        $this->assertIdentical('A', $r);
+        $old = $bpms->set('C', 1);
+        $this->assertIdentical('A', $r);
+        $r = $bpms->get(1);
+        $this->assertIdentical('C', $r);
+        $r = $bpms->get(2);
+        $this->assertIdentical('B', $r);
+    }
+
+    function testGetterSetterNearBorder()
+    {
+        // size = 3, address range = 0 - 2.
+        $bpms =& new Acme_BrainPhack_MemoryStack(3);
+
+        // < 0
+        $r = $bpms->get(-1);
+        $this->assertIdentical(false, $r);
+        $r = $bpms->get(-2);
+        $this->assertIdentical(false, $r);
+        $r = $bpms->set(100, -1);
+        $this->assertIdentical(false, $r);
+        $r = $bpms->set(100, -2);
+        $this->assertIdentical(false, $r);
+
+        // > 3
+        $r = $bpms->get(3);
+        $this->assertIdentical(false, $r);
+        $r = $bpms->get(4);
+        $this->assertIdentical(false, $r);
+        $r = $bpms->set(100, 3);
+        $this->assertIdentical(false, $r);
+        $r = $bpms->set(100, 4);
+        $this->assertIdentical(false, $r);
+
+
+    }
+
+    function testClearReset()
+    {
+        $INIT = 2;
+        // init value = 2
+        $bpms =& new Acme_BrainPhack_MemoryStack(3, $INIT);
+        $bpms->set(9); $bpms->ptr_inc();
+        $bpms->set(8); $bpms->ptr_inc();
+        $bpms->set(7); $bpms->ptr_inc();
+        $bpms->clear_reset();
+        // test memory stack is initialized.
+        for ($i = 0; false !== ($r = $bpms->get($i)); $i++) {
+            $this->assertIdentical($INIT, $r);
+        }
+        // test pointer is reset.
+        list($old, $new) = $bpms->ptr_inc();
+        $this->assertIdentical(0, $old);
+        $this->assertIdentical(1, $new);
+    }
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/MemoryStack_TestCase.php
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/Interpreter_TestCase.php

@@ -0,0 +1,390 @@
+<?php
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+/**
+ * requires
+ */
+require_once('PEAR/ErrorStack.php');
+require_once('Acme/BrainPhack/MemoryStack.php');
+require_once('Acme/BrainPhack/Interpreter.php');
+
+class Interpreter_TestCase extends UnitTestCase
+{
+    // {{{ testConstructorAndSomeShortIllegalSrc()
+
+    function testConstructorAndSomeShortIllegalSrc()
+    {
+        $MEMORY_STACK_SZ = 5;
+        $INIT = '0';
+        $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+        $es =& new PEAR_ErrorStack('test');
+
+        $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+        $this->assertIdentical($bpi->isStdinReady(), true);
+        $bpi->disableStdin();
+        $this->assertIdentical($bpi->isStdinReady(), false);
+        $bpi->enableStdin();
+        $this->assertIdentical($bpi->isStdinReady(), true);
+
+        // empty source code
+        $s = '';
+        $r = $bpi->run($s);
+        $this->assertIdentical($r, true);
+        for ($i = 0; $i < $MEMORY_STACK_SZ; $i++) {
+            $this->assertIdentical($bpms->get($i), $INIT);
+        }
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+
+        // only illegal character
+        $s = '*';
+        $r = $bpi->run($s);
+        $this->assertIdentical($r, true);
+        $r = $es->pop();
+        $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_ILLEGAL_CHAR);
+        $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_INFO);
+        $this->assertEqual($r['params'][0], 0);
+        $this->assertEqual($r['params'][1], '*');
+        $this->assertEqual($r['message'], 'Illegal Character.');
+        // there're no other errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+
+        // only some illegal character
+        $s = '12345';
+        $r = $bpi->run($s);
+        $this->assertIdentical($r, true);
+        for ($i = 5; $i >= 1; $i--) {
+            $r = $es->pop();
+            $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_ILLEGAL_CHAR);
+            $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_INFO);
+            $this->assertEqual($r['params'][0], $i - 1);
+            $this->assertEqual($r['params'][1], $i);
+            $this->assertEqual($r['message'], 'Illegal Character.');
+        }
+        // there're no other errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+    }
+
+    // }}}
+    // {{{ testIncDecAndPrintOps()
+
+    function testIncDecAndPrintOps()
+    {
+        $MEMORY_STACK_SZ = 5;
+        $INIT = 0;
+        $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+        $es =& new PEAR_ErrorStack('test');
+
+        $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+        $s = '+>++++->+++++--<-<.>.>.';
+        $expected = sprintf('%c%c%c', 1, 2, 3);
+        ob_start();
+        $r = $bpi->run($s);
+        $r = ob_get_clean();
+        $this->assertIdentical($r, $expected);
+        // no errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+        // check memory stack
+        $this->assertIdentical($bpms->get(0), 1);
+        $this->assertIdentical($bpms->get(1), 2);
+        $this->assertIdentical($bpms->get(2), 3);
+        $this->assertIdentical($bpms->get(3), $INIT);
+        $this->assertIdentical($bpms->get(4), $INIT);
+
+        $bpms->clear_reset();
+
+        // include some illegal characters
+        $s = '+>/++++->*+++?++--<-<.>.>.';
+        $expected = sprintf('%c%c%c', 1, 2, 3);
+        ob_start();
+        $r = $bpi->run($s);
+        $r = ob_get_clean();
+        $this->assertIdentical($r, $expected);
+        // no errors
+        $r = $es->pop();
+        $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_ILLEGAL_CHAR);
+        $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_INFO);
+        $this->assertEqual($r['params'][0], 13);
+        $this->assertEqual($r['params'][1], '?');
+        $r = $es->pop();
+        $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_ILLEGAL_CHAR);
+        $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_INFO);
+        $this->assertEqual($r['params'][0], 9);
+        $this->assertEqual($r['params'][1], '*');
+        $r = $es->pop();
+        $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_ILLEGAL_CHAR);
+        $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_INFO);
+        $this->assertEqual($r['params'][0], 2);
+        $this->assertEqual($r['params'][1], '/');
+        // there're no other errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+        // check memory stack
+        $this->assertIdentical($bpms->get(0), 1);
+        $this->assertIdentical($bpms->get(1), 2);
+        $this->assertIdentical($bpms->get(2), 3);
+        $this->assertIdentical($bpms->get(3), $INIT);
+        $this->assertIdentical($bpms->get(4), $INIT);
+    }
+
+    // }}}
+    // {{{ testAddressIncDecRangeError()
+
+    function testAddressIncDecRangeError()
+    {
+        $MEMORY_STACK_SZ = 3;
+        $INIT = 0;
+        $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+        $es =& new PEAR_ErrorStack('test');
+
+        $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+        $s = '<';
+        $r = $bpi->run($s);
+        $this->assertIdentical($r, false);
+        $r = $es->pop();
+        $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_PTR_DEC);
+        $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_ERROR);
+        $this->assertEqual($r['params'][0], 0);
+
+        // there're no other errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+
+        $bpms->clear_reset();
+
+        $s = '>>>>';
+        $r = $bpi->run($s);
+        $this->assertIdentical($r, false);
+        $r = $es->pop();
+        $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_PTR_INC);
+        $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_ERROR);
+        $this->assertEqual($r['params'][0], 3);
+
+        // there're no other errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+    }
+
+    // }}}
+    // {{{ testBracket()
+
+    function testBracket()
+    {
+        $MEMORY_STACK_SZ = 5;
+        $INIT = 0;
+        $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+        $es =& new PEAR_ErrorStack('test');
+
+        $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+        $s = '+++[>+<-]>.';
+        $expected = sprintf('%c', 3);
+        ob_start();
+        $r = $bpi->run($s);
+        $r = ob_get_clean();
+        $this->assertIdentical($r, $expected);
+        // no errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+        // check memory stack
+        $this->assertIdentical($bpms->get(0), $INIT);
+        $this->assertIdentical($bpms->get(1), 3);
+        $this->assertIdentical($bpms->get(2), $INIT);
+        $this->assertIdentical($bpms->get(3), $INIT);
+        $this->assertIdentical($bpms->get(4), $INIT);
+    }
+
+    // }}}
+    // {{{ testBracketLackError()
+
+    function testBracketLackError()
+    {
+        $MEMORY_STACK_SZ = 3;
+        $INIT = 0;
+        $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+        $es =& new PEAR_ErrorStack('test');
+
+        $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+        // #1
+        $s = '[';
+        $r = $bpi->run($s);
+        $this->assertIdentical($r, false);
+        $r = $es->pop();
+        $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_LACK_RBRACKET);
+        $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_ERROR);
+        $this->assertEqual($r['params'][0], 0);
+        // there're no other errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+
+        $bpms->clear_reset();
+
+        // #2
+        $s = '+]';
+        $r = $bpi->run($s);
+        $this->assertIdentical($r, false);
+        $r = $es->pop();
+        $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_LACK_LBRACKET);
+        $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_ERROR);
+        $this->assertEqual($r['params'][0], 1);
+        // there're no other errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+
+        $bpms->clear_reset();
+
+        // #3
+        $s = '+++---[';
+        $r = $bpi->run($s);
+        $this->assertIdentical($r, false);
+        $r = $es->pop();
+        $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_LACK_RBRACKET);
+        $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_ERROR);
+        $this->assertEqual($r['params'][0], 6);
+        $this->assertEqual($r['message'], "']' not found for '[' at 6");
+        // there're no other errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+
+        $bpms->clear_reset();
+
+        // #4
+        $s = '+++]';
+        $r = $bpi->run($s);
+        $this->assertIdentical($r, false);
+        $r = $es->pop();
+        $this->assertEqual($r['code'], ACME_BRAINPHACK_EC_LACK_LBRACKET);
+        $this->assertEqual($r['level'], ACME_BRAINPHACK_EL_ERROR);
+        $this->assertEqual($r['params'][0], 3);
+        $this->assertEqual($r['message'], "'[' not found for ']' at 3");
+        // there're no other errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+
+    }
+
+    // }}}
+    // {{{ testHelloWorld1()
+
+    function testHelloWorld1()
+    {
+        $MEMORY_STACK_SZ = 1024;
+        $INIT = 0;
+        $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+        $es =& new PEAR_ErrorStack('test');
+
+        $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+        // stupid BrainF*ck "Hello, World!"
+        $s =
+            '++++++++[>++++++++<-]>++++++++.>'.     // 'H' = 72
+            '++++++++++[>++++++++++<-]>+.>'.        // 'e' = 101
+            '++++++++++[>+++++++++++<-]>--..>'.     // 'l' = 108 x 2
+            '++++++++++[>+++++++++++<-]>+.>'.       // 'o' = 111
+            '++++++++++[>++++<-]>++++.>'.           // ',' = 44
+            '++++++++++[>+++<-]>++.>'.              // ' ' = 32
+            '++++++++++[>++++++++<-]>+++++++.>'.    // 'W' = 72
+            '++++++++++[>+++++++++++<-]>+.>'.       // 'o' = 111
+            '++++++++++[>+++++++++++<-]>++++.>'.    // 'r' = 114
+            '++++++++++[>+++++++++++<-]>--.>'.      // 'l' = 108
+            '++++++++++[>++++++++++<-]>.>'.         // 'd' = 100
+            '++++++++++[>+++<-]>+++.>';             // '!' = 33
+        ob_start();
+        $r = $bpi->run($s);
+        $r = ob_get_clean();
+        $this->assertIdentical($r, 'Hello, World!');
+        // no errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+    }
+
+    // }}}
+    // {{{ testHelloWorld2()
+
+    function testHelloWorld2()
+    {
+        $MEMORY_STACK_SZ = 1024;
+        $INIT = 0;
+        $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+        $es =& new PEAR_ErrorStack('test');
+
+        $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+        // from ja.wikipedia.org
+        $s =
+            '+++++++++[>++++++++>+++++++++++>+++++<<<-]>.'.
+            '>++.+++++++..+++.>-.------------.<++++++++.'.
+            '--------.+++.------.--------.>+.';
+        ob_start();
+        $r = $bpi->run($s);
+        $r = ob_get_clean();
+        $this->assertIdentical($r, 'Hello, world!');
+        // no errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+    }
+
+    // }}}
+    // {{{ testIgnoresInputWhenStdinNotReady()
+
+    function testIgnoresInputWhenStdinNotReady()
+    {
+        $MEMORY_STACK_SZ = 5;
+        $INIT = 0;
+        $bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+        $es =& new PEAR_ErrorStack('test');
+
+        $bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+        $bpi->disableStdin();
+
+        $s = '+++,+++';
+        $r = $bpi->run($s);
+        $this->assertIdentical($r, true);
+        $this->assertIdentical($bpms->get(0), 6);
+        // no errors
+        $errors = $es->getErrors(true);
+        $this->assertIdentical(count($errors), 0);
+    }
+
+    // }}}
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/Interpreter_TestCase.php
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/stdin_test.php

@@ -0,0 +1,59 @@
+<?php
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+$include_path = ini_get('include_path');
+//$__pear_src_dir = realpath(dirname(__FILE__).'/../');
+$__pear_src_dir = realpath(dirname(__FILE__).'/../../../'); // TODO
+ini_set('include_path', $__pear_src_dir.PATH_SEPARATOR.$include_path);
+
+require_once('PEAR/ErrorStack.php');
+require_once('Acme/BrainPhack/MemoryStack.php');
+require_once('Acme/BrainPhack/Interpreter.php');
+
+// ACME_BRAINPHACK_OP_INPUT(',') manual test from php-cli
+
+$MEMORY_STACK_SZ = 5;
+$INIT = 0;
+$bpms =& new Acme_BrainPhack_MemoryStack($MEMORY_STACK_SZ, $INIT);
+$es =& new PEAR_ErrorStack('test');
+
+$bpi =& new Acme_BrainPhack_Interpreter($bpms, $es);
+
+echo "input one char:";
+$s = ',.';
+ob_start();
+$r = $bpi->run($s);
+$o = ob_get_clean();
+echo "\nconfirm: your input is [" . $o . "]\n";
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/stdin_test.php
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/testsrc/HelloWorld_Jojo_Dio.txt

表示できません: バイナリ形式としてマークされたファイルです。
svn:mime-type = application/octet-stream
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/testsrc/HelloWorld_Jojo_Dio.txt
___________________________________________________________________
追加: svn:mime-type
+ application/octet-stream

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/testsrc/HelloWorld_None.txt

@@ -0,0 +1,5 @@
+# default mapping HelloWorld and input & output a character
++++++++++[>++++++++>+++++++++++>+++++<<<-]>.
+>++.+++++++..+++.>-.------------.<++++++++.
+--------.+++.------.--------.>+.
+,.
\ No newline at end of file

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/testsrc/HelloWorld_Yaruo_Detteiu.txt

@@ -0,0 +1,80 @@
+# default mapping HelloWorld and input & output a character
+PHPでっていう
+今更っていう
+しかもBrainF*ckでっていう
+遅すぎっていう
+ネタ狙いすぎっていう
+何様っていう
+所詮自己満足っていう
+でも楽しんでくれたらラッキーっていう
+ででででっていう。
+
+ギロッ
+
+しかもパッケージが"Acme"系列ワロスっていう。
+ジョークPEARかっていう。
+折角だから草生やしてみるっていうwwwww
+半角なら問題ないっていうwwwwwww
+でででっていうでっていう
+でででででっていう
+
+でっていう大杉テラワロス。
+これでもHelloWorldかっていうwwww
+
+そうはいってもっていう
+結構難しいっていう
+"+"の数大杉っていう
+うまくつなげるのがムズイっていう
+いつまで "っていう" が続くのかっていうwwww
+でっていうマジウゼェ言われるのも納得っていうwwww
+でででっていうででっていう
+
+まだ続くワロスっていう。
+「でででっていうででっていう」で稼ぐしかないっていう。
+笑ってみるしかないっていう。
+
+ニヤニヤニヤニヤニヤニヤwww
+
+キリッ
+ワロス
+ププッ
+
+真面目顔ワロスっていうwww
+ででででっていう。
+ププッ
+でっていう。
+
+Translatorのアイデア自体は悪くないかもっていう。
+でもTranslatorの調整がめんどいっていう。
+どうしても"+"が多くなるっていう。
+"+"と"-"のバランスも難しいっていう。
+下手に「っていう」みたいな語尾を"+"にするとマジウザイっていうププッ。
+
+ププッ    ザマァっていう。
+
+ででででっていうでっていう
+
+マジウゼェ  ププッ   テラワロスwww
+
+しかも"-"の数もププッ出てくる時は大量に出過ぎwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwププッ
+ニヤニヤ
+どんだけ草生やす気っていうででででっていう。
+調整ムズスギっていう。
+ででででっていうでっていう。
+少し手抜きさせてほしいっていう。
+もう少しっていう。
+マジHelloWorldだけでウザっていう。ププッ
+wwwwwwwwwwwwwwwwwwwwwwww
+ププッ 草生やすのも大変っていう。
+でっていうででででっていう
+ププッ
+ステガノグラフィにしても手間かかりスギwwwwwwwwwwwwwwwwww
+ププッwwwwwwwwwwwwwwwwwwwwwwww
+ププッワロス
+あと少しっていう。
+ププッ
+
+以下、1文字入力して1文字表示。
+
+「や ら な い か」
+「ププッ」

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/Translator_TestCase.php

@@ -0,0 +1,330 @@
+<?php
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+/**
+ * requires
+ */
+require_once('Acme/BrainPhack/Translator.php');
+
+class Translator_TestCase extends UnitTestCase
+{
+
+    function setUp()
+    {
+        mb_internal_encoding('UTF-8');
+    }
+
+    // {{{ testOriginalBrainFuck()
+
+    function testOriginalBrainFuck()
+    {
+        $bpt =& new Acme_BrainPhack_Translator();
+
+        $map = array(
+            '+' => '+',
+            '-' => '-',
+            '>' => '>',
+            '<' => '<',
+            '.' => '.',
+            ',' => ',',
+            '[' => '[',
+            ']' => ']',
+            );
+        $src = '';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '');
+
+        $src = '?';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '');
+
+        $src = '][,.<>-+';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, $src);
+
+        $src = '+-><.,[]';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, $src);
+    }
+
+    // }}}
+    // {{{ testSimpleAlphabetTable()
+
+    function testSimpleAlphabetTable()
+    {
+        $bpt =& new Acme_BrainPhack_Translator();
+
+        $map = array(
+            '+' => 'A',
+            '-' => 'B',
+            );
+        $r = $bpt->translate($map, 'A');
+        $this->assertIdentical($r, '+');
+        $r = $bpt->translate($map, 'B');
+        $this->assertIdentical($r, '-');
+        $r = $bpt->translate($map, 'AB');
+        $this->assertIdentical($r, '+-');
+        $r = $bpt->translate($map, 'BA');
+        $this->assertIdentical($r, '-+');
+
+        $map = array(
+            '+' => 'ABC',
+            '-' => 'DEF',
+            );
+        $src = '';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '');
+
+        $src = '?';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '');
+
+        $src = 'ABC';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '+');
+
+        $src = 'DEF';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '-');
+
+        $src = 'ABCDEF';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '+-');
+
+        $src = 'DEFABC';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '-+');
+
+        $src = '?    ABC - DEF //---';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '+-');
+
+        $src = ' ABC - CDE - DEF  DEF  FABC';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '+--+');
+    }
+
+    // }}}
+    // {{{ testMultibyte()
+
+    function testMultibyte()
+    {
+        $bpt =& new Acme_BrainPhack_Translator();
+
+        $map = array(
+            '+' => 'あ',
+            '-' => 'い',
+            );
+        $src = '';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '');
+
+        $src = '?';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '');
+
+        $src = 'あ';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '+');
+
+        $src = 'い';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '-');
+
+        $src = 'あい';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '+-');
+
+        $src = 'いあ';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '-+');
+
+        $src = '?    あ - い //---';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '+-');
+
+        $src = ' あ - い  い  かあ';
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '+--+');
+    }
+
+    // }}}
+    // {{{ testMultiWords()
+
+    function testMultiWords()
+    {
+        $bpt =& new Acme_BrainPhack_Translator();
+
+        $map = array(
+            '+' => array('A', 'B'),
+            '-' => 'C',
+            );
+        $r = $bpt->translate($map, '');
+        $this->assertIdentical($r, '');
+        $r = $bpt->translate($map, 'A');
+        $this->assertIdentical($r, '+');
+        $r = $bpt->translate($map, 'B');
+        $this->assertIdentical($r, '+');
+        $r = $bpt->translate($map, 'AB');
+        $this->assertIdentical($r, '++');
+        $r = $bpt->translate($map, 'BA');
+        $this->assertIdentical($r, '++');
+        $r = $bpt->translate($map, 'C');
+        $this->assertIdentical($r, '-');
+        $r = $bpt->translate($map, 'AC');
+        $this->assertIdentical($r, '+-');
+        $r = $bpt->translate($map, 'BC');
+        $this->assertIdentical($r, '+-');
+        $r = $bpt->translate($map, 'CA');
+        $this->assertIdentical($r, '-+');
+        $r = $bpt->translate($map, 'CB');
+        $this->assertIdentical($r, '-+');
+        $r = $bpt->translate($map, 'CC');
+        $this->assertIdentical($r, '--');
+        $r = $bpt->translate($map, 'ABC');
+        $this->assertIdentical($r, '++-');
+        $r = $bpt->translate($map, 'CBA');
+        $this->assertIdentical($r, '-++');
+
+        $map = array(
+            '+' => array('AB', 'CD'),
+            '-' => array('EF', 'GH'),
+        );
+        $r = $bpt->translate($map, '? EF - A - AB .. GH G H CD /');
+        $this->assertIdentical($r, '-+-+');
+    }
+
+    // }}}
+    // {{{ testMultiWordsByMultibyte()
+
+    function testMultiWordsByMultibyte()
+    {
+        $bpt =& new Acme_BrainPhack_Translator();
+
+        $map = array(
+            '+' => array('あ', 'い'),
+            '-' => 'う',
+            );
+        $r = $bpt->translate($map, '');
+        $this->assertIdentical($r, '');
+        $r = $bpt->translate($map, 'あ');
+        $this->assertIdentical($r, '+');
+        $r = $bpt->translate($map, 'い');
+        $this->assertIdentical($r, '+');
+        $r = $bpt->translate($map, 'あい');
+        $this->assertIdentical($r, '++');
+        $r = $bpt->translate($map, 'いあ');
+        $this->assertIdentical($r, '++');
+        $r = $bpt->translate($map, 'う');
+        $this->assertIdentical($r, '-');
+        $r = $bpt->translate($map, 'あう');
+        $this->assertIdentical($r, '+-');
+        $r = $bpt->translate($map, 'いう');
+        $this->assertIdentical($r, '+-');
+        $r = $bpt->translate($map, 'うあ');
+        $this->assertIdentical($r, '-+');
+        $r = $bpt->translate($map, 'うい');
+        $this->assertIdentical($r, '-+');
+        $r = $bpt->translate($map, 'うう');
+        $this->assertIdentical($r, '--');
+        $r = $bpt->translate($map, 'あいう');
+        $this->assertIdentical($r, '++-');
+        $r = $bpt->translate($map, 'ういあ');
+        $this->assertIdentical($r, '-++');
+
+        $map = array(
+            '+' => array('あい', 'うえ'),
+            '-' => array('かき', 'くけ'),
+        );
+        $r = $bpt->translate($map, '? かき - あ - あい .. くけ く け うえ');
+        $this->assertIdentical($r, '-+-+');
+    }
+
+    // }}}
+    // {{{ testMisa()
+
+    /**
+     * @see http://homepage2.nifty.com/kujira_niku/okayu/misa.html
+     */
+    function testMisa()
+    {
+        $bpt =& new Acme_BrainPhack_Translator();
+
+        $map = array(
+            '>' => array('>', '→', '~', 'ー'),
+            '>' => array('<', '←', '★', '☆'),
+            '+' => array('+', 'あ', 'ぁ', 'お', 'ぉ'),
+            '-' => array('-', 'っ', 'ッ'),
+            '.' => array('.', '!'),
+            ',' => array(',', '?'),
+            '[' => array('[', '「', '『'),
+            ']' => array(']', '」', '』'),
+        );
+
+        $src =<<<TEXT
+あおあおあお「~ああぁおおぉ☆っ」
+ここまでで6x8=48=アスキーコードとすれば文字列0!
+あ!あ!あ!あ!あ!あ!あ!あ!あ!
+TEXT;
+        $r = $bpt->translate($map, $src);
+        $this->assertIdentical($r, '++++++[++++++>-].+.+.+.+.+.+.+.+.+.');
+    }
+
+    // }}}
+    // {{{ testGetMapping()
+
+    function testGetMapping()
+    {
+        $bpt =& new Acme_BrainPhack_Translator();
+
+        // default
+        $bptm =& $bpt->getMapper();
+        $r = $bptm->getName();
+        $this->assertIdentical($r, 'Default BrainF*ck Translator mapping');
+
+        // JOJO's DIO
+        $bptm =& $bpt->getMapper('JOJO_Dio');
+        $r = $bptm->getName();
+        $this->assertIdentical($r, "JOJO's DIO mapping");
+
+        // Yaruo's Detteiu
+        $bptm =& $bpt->getMapper('Yaruo_Detteiu');
+        $r = $bptm->getName();
+        $this->assertIdentical($r, "Yaruo's 'でっていう' mapping");
+
+    }
+
+    // }}}
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/Translator_TestCase.php
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/scripts_test.php

@@ -0,0 +1,48 @@
+<?php
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+// script file manual test bootstrap
+
+$include_path = ini_get('include_path');
+$__base_dir = realpath(dirname(__FILE__));
+//$__pear_src_dir = realpath($__base_dir.'/../');
+$__pear_src_dir = realpath($__base_dir.'/../../../'); // TODO
+ini_set('include_path',
+    $__base_dir.PATH_SEPARATOR.$__pear_src_dir.PATH_SEPARATOR.$include_path);
+
+// load and invoke script file
+$_script = realpath($__base_dir.'/../../../scripts/brainphack.sh');
+require_once($_script);
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
+
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/scripts_test.php
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/README

@@ -0,0 +1,18 @@
+* Acme_BrainPhack test code README
+
+Acme_BrainPhack test codes require "simpletest" php unit test library.
+see: http://simpletest.sourceforge.net/
+
+- all_test.php : Run unit tests for all Acme_BrainPhack classes,
+                 except ","(read a char from stdin) instruction.
+
+- stdin_test.php : Run only "," instruction. Confirm input and output by hand..
+
+- scripts_test.php : Run scripts/brainphack.sh wrapper.
+                     Try sample helloworlds in "testsrc" directory.
+
+For more details, read source codes.
+
+Thank you.
+
+Copyright 2010 sakamoto-gsyc-3s@glamenv-septzen.net

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/all_test.php

@@ -0,0 +1,52 @@
+<?php
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+require_once('simpletest/unit_tester.php');
+require_once('simpletest/reporter.php');
+
+$include_path = ini_get('include_path');
+$__base_dir = realpath(dirname(__FILE__));
+//$__pear_src_dir = realpath($__base_dir.'/../');
+$__pear_src_dir = realpath($__base_dir.'/../../../'); // TODO
+ini_set('include_path',
+    $__base_dir.PATH_SEPARATOR.$__pear_src_dir.PATH_SEPARATOR.$include_path);
+
+$test = &new TestSuite('All tests');
+$test->addTestFile('MemoryStack_TestCase.php');
+$test->addTestFile('Interpreter_TestCase.php');
+$test->addTestFile('Translator_TestCase.php');
+$test->run(new TextReporter());
+
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
+
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/test/all_test.php
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/MemoryStack.php

@@ -0,0 +1,209 @@
+<?php
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+/**
+ * BrainF*ck MemoryStack
+ *
+ * @author msakamoto-sf <sakamoto-gsyc-3s@glamenv-septzen.net>
+ * @package Acme_BrainPhack
+ * @since 0.0.1
+ */
+class Acme_BrainPhack_MemoryStack
+{
+    // {{{ properties
+
+    /**
+     * maximum stack size
+     *
+     * @var integer
+     * @access protected
+     */
+    var $_stack_size = 0;
+
+    /**
+     * memory stack
+     *
+     * @var array
+     * @access protected
+     */
+    var $_stack;
+
+    /**
+     * memory pointer address
+     *
+     * @var integer
+     * @access protected
+     */
+    var $_curr_ptr = 0;
+
+    /**
+     * initial value
+     *
+     * @var mixed
+     * @access protected
+     */
+    var $_initval = 0;
+
+    // }}}
+    // {{{ constructor
+
+    /**
+     * Constructor
+     *
+     * @access public
+     * @param integer maximum stack size
+     * @param mixed initial memory value (optional)
+     *              If omitted, memory stack is initialized by 0(zero).
+     */
+    function Acme_BrainPhack_MemoryStack($sz, $init = 0)
+    {
+        $this->_stack = array();
+        $this->_stack_size = $sz;
+        for ($i = 0; $i < $sz; $i++) {
+            $this->_stack[$i] = $init;
+        }
+        $this->_initval = $init;
+    }
+
+    // }}}
+    // {{{ memory value getter/setter
+
+    /**
+     * return memory value
+     *
+     * @access public
+     * @param integer memory address(optional)
+     *                If omitted, current pointer address is used.
+     * @return mixed pointed memory value.
+     *  If memory address < 0 or maximum stack size < memory address,
+     *  return false.
+     */
+    function get($i = null)
+    {
+        if (is_null($i)) {
+            return $this->_stack[$this->_curr_ptr];
+        }
+        if (0 > $i) {
+            return false;
+        }
+        if ($i >= $this->_stack_size) {
+            return false;
+        }
+        return $this->_stack[$i];
+    }
+
+    /**
+     * set new memory value
+     *
+     * @access public
+     * @param mixed new value
+     * @param integer memory address(optional)
+     *                If omitted, current pointer address is used.
+     * @return mixed pointed old memory value.
+     *  If memory address < 0 or maximum stack size < memory address,
+     *  return false and nothing changes.
+     */
+    function set($v, $i = null)
+    {
+        if (is_null($i)) {
+            $old = $this->_stack[$this->_curr_ptr];
+            $this->_stack[$this->_curr_ptr] = $v;
+            return $old;
+        }
+        if (0 > $i) {
+            return false;
+        }
+        if ($i >= $this->_stack_size) {
+            return false;
+        }
+        $old = $this->_stack[$i];
+        $this->_stack[$i] = $v;
+        return $old;
+    }
+
+    // }}}
+    // {{{ pointer address increment/decrement
+
+    /**
+     * increment pointer address
+     *
+     * @access public
+     * @return array array('old pointer address', 'new pointer address')
+     *  If incremented memory address WILL BE lesser than < 0 or
+     *  oversized maximum stack size, memory address doesn't be incremented
+     *  (nothing changed), and return false
+     */
+    function ptr_inc()
+    {
+        $old = $this->_curr_ptr;
+        if ($this->_curr_ptr == $this->_stack_size) {
+            return false;
+        }
+        $this->_curr_ptr++;
+        return array($old, $this->_curr_ptr);
+    }
+
+    /**
+     * decrement pointer address
+     *
+     * @access public
+     * @return array array('old pointer address', 'new pointer address')
+     *  If decremented memory address WILL BE lesser than < 0 or
+     *  oversized maximum stack size, memory address doesn't be incremented
+     *  (nothing changed), and return false
+     */
+    function ptr_dec()
+    {
+        $old = $this->_curr_ptr;
+        if (0 == $this->_curr_ptr) {
+            return false;
+        }
+        $this->_curr_ptr--;
+        return array($old, $this->_curr_ptr);
+    }
+
+    // }}}
+    // {{{ clear_reset()
+
+    function clear_reset()
+    {
+        for ($i = 0; $i < $this->_stack_size; $i++) {
+            $this->_stack[$i] = $this->_initval;
+        }
+        $this->_curr_ptr = 0;
+    }
+
+    // }}}
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/MemoryStack.php
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/Interpreter.php

@@ -0,0 +1,212 @@
+<?php
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+/**
+ * BrainF*ck MemoryStack
+ *
+ * @author msakamoto-sf <sakamoto-gsyc-3s@glamenv-septzen.net>
+ * @package Acme_BrainPhack
+ * @since 0.0.1
+ */
+
+define('ACME_BRAINPHACK_OP_PTR_INC', '>');
+define('ACME_BRAINPHACK_OP_PTR_DEC', '<');
+define('ACME_BRAINPHACK_OP_VAL_INC', '+');
+define('ACME_BRAINPHACK_OP_VAL_DEC', '-');
+define('ACME_BRAINPHACK_OP_PRINT', '.');
+define('ACME_BRAINPHACK_OP_INPUT', ',');
+define('ACME_BRAINPHACK_OP_JMP_Z', '[');
+define('ACME_BRAINPHACK_OP_JMP_NZ', ']');
+
+// error levels
+define('ACME_BRAINPHACK_EL_INFO',  'info');
+define('ACME_BRAINPHACK_EL_WARN',  'warn');
+define('ACME_BRAINPHACK_EL_ERROR', 'error');
+
+// error codes
+define('ACME_BRAINPHACK_EC_ILLEGAL_CHAR', 100);
+define('ACME_BRAINPHACK_EC_PTR_INC', 200);
+define('ACME_BRAINPHACK_EC_PTR_DEC', 300);
+define('ACME_BRAINPHACK_EC_LACK_RBRACKET', 400);
+define('ACME_BRAINPHACK_EC_LACK_LBRACKET', 500);
+
+class Acme_BrainPhack_Interpreter
+{
+    var $_memoryStack;
+    var $_errorStack;
+    var $_stdinReady = false;
+
+    function Acme_BrainPhack_Interpreter(&$memoryStack, &$errorStack)
+    {
+        $this->_memoryStack =& $memoryStack;
+        $this->_errorStack =& $errorStack;
+        if ('cli' == php_sapi_name()) {
+            $this->_stdinReady = true;
+        }
+    }
+
+    function isStdinReady()
+    {
+        return $this->_stdinReady;
+    }
+    function enableStdin()
+    {
+        $this->_stdinReady = true;
+    }
+    function disableStdin()
+    {
+        $this->_stdinReady = false;
+    }
+    function run($src)
+    {
+        $src_i = 0;
+        $src_sz = strlen($src);
+
+        while ($src_i < $src_sz) {
+            $src_curr = $src_i;
+            $op = $src[$src_i];
+            $src_i++;
+
+            switch ($op) {
+            case ACME_BRAINPHACK_OP_PTR_INC:
+                $r = $this->_memoryStack->ptr_inc();
+                if (false === $r) {
+                    $this->_errorStack->push(
+                        ACME_BRAINPHACK_EC_PTR_INC,
+                        ACME_BRAINPHACK_EL_ERROR,
+                        array($src_curr),
+                        'Pointer Increment Error(maybe out of range).'
+                    );
+                    return false;
+                }
+                break;
+            case ACME_BRAINPHACK_OP_PTR_DEC:
+                $r = $this->_memoryStack->ptr_dec();
+                if (false === $r) {
+                    $this->_errorStack->push(
+                        ACME_BRAINPHACK_EC_PTR_DEC,
+                        ACME_BRAINPHACK_EL_ERROR,
+                        array($src_curr),
+                        'Pointer Decrement Error(maybe minus address).'
+                    );
+                    return false;
+                }
+                break;
+            case ACME_BRAINPHACK_OP_VAL_INC:
+                $v = $this->_memoryStack->get();
+                $this->_memoryStack->set($v + 1);
+                break;
+            case ACME_BRAINPHACK_OP_VAL_DEC:
+                $v = $this->_memoryStack->get();
+                $this->_memoryStack->set($v - 1);
+                break;
+            case ACME_BRAINPHACK_OP_PRINT:
+                $v = $this->_memoryStack->get();
+                    printf('%c', $v);
+                break;
+            case ACME_BRAINPHACK_OP_INPUT:
+                if (!$this->_stdinReady) {
+                    // skip
+                    break;
+                }
+                $c = fgetc(STDIN);
+                if ($c === false) {
+                    // EOF
+                    $c = 0;
+                } else {
+                    $c = ord($c);
+                }
+                $this->_memoryStack->set($c);
+                break;
+            case ACME_BRAINPHACK_OP_JMP_Z:
+                $v = $this->_memoryStack->get();
+                if (0 == $v) { // ambiguous compares... '0' == 0, 0 == 0.
+                    $_found = false;
+                    while ($src_i < $src_sz) {
+                        if (ACME_BRAINPHACK_OP_JMP_NZ == $src[$src_i]) {
+                            $_found = true;
+                            break;
+                        }
+                        $src_i++;
+                    }
+                    if (!$_found) {
+                        $this->_errorStack->push(
+                            ACME_BRAINPHACK_EC_LACK_RBRACKET,
+                            ACME_BRAINPHACK_EL_ERROR,
+                            array($src_curr),
+                            "']' not found for '[' at {$src_curr}"
+                        );
+                        return false;
+                    } else {
+                        $src_i++;
+                    }
+                }
+                break;
+            case ACME_BRAINPHACK_OP_JMP_NZ:
+                $v = $this->_memoryStack->get();
+                if (0 != $v) { // ambiguous compares... '0' == 0, 0 == 0.
+                    $_found = false;
+                    while (0 < $src_i) {
+                        $src_i--;
+                        if (ACME_BRAINPHACK_OP_JMP_Z == $src[$src_i]) {
+                            $_found = true;
+                            break;
+                        }
+                    }
+                    if (!$_found) {
+                        $this->_errorStack->push(
+                            ACME_BRAINPHACK_EC_LACK_LBRACKET,
+                            ACME_BRAINPHACK_EL_ERROR,
+                            array($src_curr),
+                            "'[' not found for ']' at {$src_curr}"
+                        );
+                        return false;
+                    } else {
+                        $src_i++;
+                    }
+                }
+                break;
+            default:
+                $this->_errorStack->push(
+                    ACME_BRAINPHACK_EC_ILLEGAL_CHAR,
+                    ACME_BRAINPHACK_EL_INFO,
+                    array($src_curr, $op),
+                    'Illegal Character.'
+                );
+            }
+        }
+        return true;
+    }
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/Interpreter.php
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/Translator/Yaruo/Detteiu.php

@@ -0,0 +1,70 @@
+<?php
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack_Translator_Yaruo
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+/**
+ * Yaruo's 'でっていう' mapping
+ *
+ * @author msakamoto-sf <sakamoto-gsyc-3s@glamenv-septzen.net>
+ * @package Acme_BrainPhack_Translator_Yaruo
+ * @since 0.0.2
+ */
+class Acme_BrainPhack_Translator_Yaruo_Detteiu
+{
+    // {{{ getName()
+
+    function getName()
+    {
+        return "Yaruo's 'でっていう' mapping";
+    }
+
+    // }}}
+    // {{{ getMap()
+
+    function getMap()
+    {
+        return array(
+            '+' => array('っていう'),
+            '-' => array('www'),
+            '>' => array('ワロス'),
+            '<' => array('ニヤニヤ'),
+            '.' => array('ププッ'),
+            ',' => array('や ら な い か'),
+            '[' => array('ギロッ'),
+            ']' => array('キリッ'),
+            );
+    }
+
+    // }}}
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: utf-8
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/Translator/Yaruo/Detteiu.php
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/Translator/Jojo/Dio.php

@@ -0,0 +1,70 @@
+<?php
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack_Translator_Jojo
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+/**
+ * JOJO's DIO mapping
+ *
+ * @author msakamoto-sf <sakamoto-gsyc-3s@glamenv-septzen.net>
+ * @package Acme_BrainPhack_Translator_Jojo
+ * @since 0.0.2
+ */
+class Acme_BrainPhack_Translator_Jojo_Dio
+{
+    // {{{ getName()
+
+    function getName()
+    {
+        return "JOJO's DIO mapping";
+    }
+
+    // }}}
+    // {{{ getMap()
+
+    function getMap()
+    {
+        return array(
+            '+' => array('無駄'),
+            '-' => array('ムダ'),
+            '>' => array('AAAAA'), // KUAAAAAAAAAAAAA!!!!!!!
+            '<' => array('YYYYY'), // WRYYYYYYYYYYYYY!!!!!!!
+            '.' => array('ロードローラーだッ!'),
+            ',' => array('お前は今まで食ったパンの枚数を覚えているか?'),
+            '[' => array('時よ止まれ「ザ・ワールド」!'),
+            ']' => array('そして時は動き出す'),
+            );
+    }
+
+    // }}}
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: utf-8
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/Translator/Jojo/Dio.php
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/Translator/None.php

@@ -0,0 +1,70 @@
+<?php
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack_Translator
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+/**
+ * Default BrainF*ck Translator Mapping
+ *
+ * @author msakamoto-sf <sakamoto-gsyc-3s@glamenv-septzen.net>
+ * @package Acme_BrainPhack_Translator
+ * @since 0.0.2
+ */
+class Acme_BrainPhack_Translator_None
+{
+    // {{{ getName()
+
+    function getName()
+    {
+        return "Default BrainF*ck Translator mapping";
+    }
+
+    // }}}
+    // {{{ getMap()
+
+    function getMap()
+    {
+        return array(
+            '+' => array('+'),
+            '-' => array('-'),
+            '>' => array('>'),
+            '<' => array('<'),
+            '.' => array('.'),
+            ',' => array(','),
+            '[' => array('['),
+            ']' => array(']'),
+            );
+    }
+
+    // }}}
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4:
+ */
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/Acme/BrainPhack/Translator/None.php
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/scripts/brainphack.bat

@@ -0,0 +1,2 @@
+@echo off
+"@php_bin@" "@bin_dir@\brainphack" %*
\ No newline at end of file

Acme_BrainPhack/tags/release-1.0.0-20100123235206/scripts/brainphack.sh

@@ -0,0 +1,138 @@
+#!@php_bin@
+<?php
+
+/*
+ *   Copyright (c) 2010 msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.*
+ */
+
+/**
+ * @package Acme_BrainPhack
+ * @author msakamoto-sf <msakamoto-sf@users.sourceforge.net>
+ * @version $Id$
+ */
+
+require_once('Console/GetOpt.php');
+require_once('PEAR/ErrorStack.php');
+require_once('Acme/BrainPhack/Translator.php');
+require_once('Acme/BrainPhack/MemoryStack.php');
+require_once('Acme/BrainPhack/Interpreter.php');
+
+function usage()
+{
+    $_this = basename(__FILE__);
+    echo "usage: {$_this} [options] filename\n";
+    echo "\tfilename: you can give only 1 filename.\n";
+    echo "\t\tmultiple filenames invokes error and show this help.\n";
+    echo "\toptions:\n";
+    echo "\t-b : convert to BrainF*ck code and display it(not executed).\n";
+    echo "\t-h : show this help.\n";
+    echo "\t-m size : memory stack size by KB (default is 32).\n";
+    echo "\t-t translator : BrainF*ck translator.\n";
+    echo "\t\tex: Acme/BrainPhack/Translator/Foo.php : \"-t Foo\"\n";
+    echo "\t\tex: Acme/BrainPhack/Translator/Bar/Baz.php : \"-t Bar_Baz\"\n";
+    echo "\t\t(default: Acme_BrainPhack_Translator_None.php)\n";
+}
+
+$cg =& new Console_GetOpt();
+$argv = $cg->readPHPArgv();
+array_shift($argv);
+
+$params = $cg->getopt2($argv, 'bhm:t:');
+if (PEAR::isError($params)) {
+    echo 'Error: ' . $params->getMessage() . "\n";
+    usage();
+    exit(1);
+}
+list($options, $remains) = $params;
+
+$settings = array(
+    'convert_not_run' => false,
+    'stack_size' => 32,
+    'translator' => 'None',
+    );
+
+foreach ($options as $option) {
+    list($k, $v) = $option;
+    switch ($k) {
+    case 'b':
+        $settings['convert_not_run'] = true;
+        break;
+    case 'h':
+        usage();
+        exit(0);
+    case 'm':
+        $_v = intval($v);
+        if (0 == $_v) {
+            echo "Error: memory stack size (-m) is zero.\n";
+            usage();
+            exit(1);
+        }
+        $settings['stack_size'] = $_v;
+        break;
+    case 't':
+        $settings['translator'] = $v;
+        break;
+    default:
+    }
+}
+
+if (1 != count($remains)) {
+    echo "Error: filename is not given, or, multiple files are given.\n";
+    usage();
+    exit(1);
+}
+
+$src = file_get_contents($remains[0]);
+if (false === $src) {
+    echo "Error: can't read from '{$remains[0]}'.\n";
+    exit(1);
+}
+
+$bpt =& new Acme_BrainPhack_Translator();
+$bptm =& $bpt->getMapper($settings['translator']);
+$map = $bptm->getMap();
+$bpsrc = $bpt->translate($map, $src);
+
+if (true === $settings['convert_not_run']) {
+    echo $bpsrc;
+    echo "\n";
+    exit(0);
+}
+
+$sz = 1024 * $settings['stack_size'];
+$bpms =& new Acme_BrainPhack_MemoryStack($sz, 0);
+$errorStack =& new PEAR_ErrorStack('Acme_BrainPhack CUI ErrorStack');
+$bpi =& new Acme_BrainPhack_Interpreter($bpms, $errorStack);
+$bpi->run($bpsrc);
+$errors = $errorStack->getErrors(true);
+foreach ($errors as $e) {
+    $_l = $e['level'];
+    $_m = $e['message'];
+    $_c = $e['code'];
+    $_p = '(' . implode(', ', $e['params']) . ')';
+    echo "{$_l} {$_m} {$_p} (code={$_c})\n";
+}
+
+/**
+ * Local Variables:
+ * mode: php
+ * coding: iso-8859-1
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * indent-tabs-mode: nil
+ * End:
+ * vim: set expandtab tabstop=4 shiftwidth=4 filetype=php:
+ */
属性に変更があったパス: Acme_BrainPhack/tags/release-1.0.0-20100123235206/scripts/brainphack.sh
___________________________________________________________________
追加: svn:keywords
+ Id

Acme_BrainPhack/tags/release-1.0.0-20100123235206/README

@@ -0,0 +1,15 @@
+* README
+
+Thank you for downloading, enjoying "Acme_BrainPhack"!
+
+* What is "Acme_BrainPhack" ?
+
+"Acme_BrainPhack"(this) is "BrainF*ck" programming language interpreter
+sample implementation by PHP language.
+
+* Joke package ?
+
+Yes, it is. Let's enjoy!
+
+Copyright 2010 sakamoto-gsyc-3s@glamenv-septzen.net
+