1

restructure + syntactic sugar implementation

This commit is contained in:
Christoph
2021-08-11 21:11:35 +02:00
parent 7365c41e11
commit 3a6814a850
27 changed files with 145 additions and 86 deletions

View File

@ -1,7 +1,5 @@
import py
from simpleparser import parse
from objmodel import W_NormalObject, W_Integer
from objmodel import W_Integer
from interpreter import Interpreter

View File

@ -1,7 +1,4 @@
import py
from simpleparser import parse
from objmodel import W_NormalObject, W_Integer
from interpreter import Interpreter

13
mytest/test_sugar_lex.py Normal file
View File

@ -0,0 +1,13 @@
from rply import Token
from simplelexer import lex
def test_lexing():
token = lex("+ - * / ++ %")
assert Token("Plus", "+") == token[0]
assert Token("Minus", "-") == token[1]
assert Token("Multiply", "*") == token[2]
assert Token("Divide", "/") == token[3]
assert Token("Increment", "++") == token[4]
assert Token("Modulo", "%") == token[5]

View File

@ -0,0 +1,14 @@
from simpleparser import parse
def test_parsing():
assert parse("1 + 2") == parse("1 $int_add(2)")
assert parse("1 + 2 + 3") == parse("1 $int_add(2) $int_add(3)")
assert parse("1 + 2 * 3") == parse("1 $int_add(2 $int_mul(3))")
assert parse("1 - 2 - 3") == parse("1 $int_sub(2) $int_sub(3)")
assert parse("1 + 2 % 3 / 4 - 5 * 6 + 7++") \
== parse("1 $int_add(2 $int_mod(3) $int_div(4)) $int_sub(5 $int_mul(6)) $int_add(7 $int_inc)")
def test_parsing_parenthesis():
pass

Binary file not shown.