Selaa lähdekoodia

Significantly improved the parser.

- Thought over and reconfigured precedences. These are now also synchronized
  with precedences in the line printer.
- The subscript operator ("_") has been added to the grammar similarly to
  exponentiation ("^"). This resolved some issues with the use of operators in
  integral bounds.
- Unary negation now has a higher precedence, but the parser moves negations up
  in the tree as far as possible (within the bounds of correctness and without
  causing cycles during reduction).
- All unit tests have been updated using the new syntax.
- graph_drawing has been updated to include the new syntax of the line printer.
Taddeus Kroes 13 vuotta sitten
vanhempi
sitoutus
82d83f5aa3
3 muutettua tiedostoa jossa 3 lisäystä ja 3 poistoa
  1. 0 1
      src/parser.py
  2. 1 1
      tests/test_leiden_oefenopgave.py
  3. 2 1
      tests/test_parser.py

+ 0 - 1
src/parser.py

@@ -116,7 +116,6 @@ class Parser(BisonParser):
         ('left', ('MINUS', 'PLUS')),
         ('nonassoc', ('INTEGRAL', 'DERIVATIVE')),
         ('left', ('TIMES', )),
-        ('left', ('PRIME', )),
         ('left', ('DIVIDE', )),
         ('nonassoc', ('PRIME', )),
         ('nonassoc', ('NEG', )),

+ 1 - 1
tests/test_leiden_oefenopgave.py

@@ -12,7 +12,7 @@
 #
 # You should have received a copy of the GNU Affero General Public License
 # along with TRS.  If not, see <http://www.gnu.org/licenses/>.
-from tests.rulestestcase import RulesTestCase as TestCase, rewrite
+from tests.rulestestcase import RulesTestCase as TestCase
 
 
 class TestLeidenOefenopgave(TestCase):

+ 2 - 1
tests/test_parser.py

@@ -101,7 +101,8 @@ class TestParser(RulesTestCase):
 
         self.assertEqual(tree('sin cos x'), sin(cos(x)))
         self.assertEqual(tree('sin cos x ^ 2'), sin(cos(x ** 2)))
-        self.assertEqual(tree('sin cos(x) ^ 2'), sin(cos(x) ** 2))
+        self.assertEqual(tree('sin cos(x) ^ 2'), sin(cos(x ** 2)))
+        self.assertEqual(tree('sin (cos x) ^ 2'), sin(cos(x) ** 2))
 
         self.assertEqual(tree('sin (cos x) ^ 2'), sin(cos(x)) ** 2)
         self.assertEqual(tree('sin((cos x) ^ 2)'), sin(cos(x) ** 2))