def test_raw_eval2(self):
     newTokens = ['(', 'lambda', 'x', '.', 'x', 'y', ')', 't']
     parsed = Parser.full_parse(newTokens)
     self.assertEqual(Evaluator.raw_eval(parsed),
                      {'type': 'application',
                       'left': {'type': 'variable', 'value': 't'},
                       'right': {'type': 'variable', 'value': 'y'}})
 def test_parse3(self):
     self.assertEqual(Parser.full_parse(self.application_tokens),
                      {'type': 'application',
                       'left':
                          {'type': 'lambda', 'binder': 'x',
                           'body': [{'type': 'variable', 'value': 'x'}]},
                       'right':
                          {'type': 'variable', 'value': 't'}})
Example #3
0
 def test_nested_scope(self):
     string = "(lambda x. x) ((lambda x. x) (lambda z. (lambda x. x) x))"
     tokens = Lexer.tokenize(string)
     self.assertEqual(
         Parser.scope(tokens),
         [['lambda', 'x', '.', 'x'],
          [['lambda', 'x', '.', 'x'],
           ['lambda', 'z', '.', ['lambda', 'x', '.', 'x'], 'x']]])
 def test_nested_scope(self):
     string = "(lambda x. x) ((lambda x. x) (lambda z. (lambda x. x) x))"
     tokens = Lexer.tokenize(string)
     self.assertEqual(Parser.scope(tokens),
                      [['lambda', 'x', '.', 'x'],
                       [['lambda', 'x', '.', 'x'], ['lambda', 'z', '.',
                                                    ['lambda', 'x',
                                                     '.', 'x'], 'x']]])
 def test_parse_list_of_variables(self):
     self.assertEqual(Parser.full_parse(Lexer.tokenize("x y z")),
                      {'type': 'application',
                       'left': {'type': 'variable', 'value': 'x'},
                       'right': {'type': 'application',
                                 'left': {'type': 'variable',
                                          'value': 'y'},
                                 'right': {'type': 'variable',
                                           'value': 'z'}}})
Example #6
0
 def setUp(self):
     self.simple_exp = '(lambda x. x)'
     self.nest_exp = '(lambda x. (lambda y. y)'
     self.id_tokens = ['(', 'lambda', 'x', '.', 'x', ')']
     self.bound_and_free = ['(', 'lambda', 'x', '.', 'x', 'y', ')']
     self.application_tokens = copy.copy(self.id_tokens)
     self.application_tokens.append('t')
     semantic = lambda x: Parser.full_parse(Lexer.tokenize(x))
     self.semantic = semantic
 def setUp(self):
     self.simple_exp = '(lambda x. x)'
     self.nest_exp = '(lambda x. (lambda y. y)'
     self.id_tokens = ['(', 'lambda', 'x', '.', 'x', ')']
     self.bound_and_free = ['(', 'lambda', 'x', '.', 'x', 'y', ')']
     self.application_tokens = copy.copy(self.id_tokens)
     self.application_tokens.append('t')
     semantic = lambda x: Parser.full_parse(Lexer.tokenize(x))
     self.semantic = semantic
Example #8
0
 def test_parse1(self):
     self.assertEqual(
         Parser.full_parse(self.id_tokens), {
             'type': 'lambda',
             'binder': 'x',
             'body': [{
                 'type': 'variable',
                 'value': 'x'
             }]
         })
Example #9
0
 def test_raw_eval2(self):
     newTokens = ['(', 'lambda', 'x', '.', 'x', 'y', ')', 't']
     parsed = Parser.full_parse(newTokens)
     self.assertEqual(
         Evaluator.raw_eval(parsed), {
             'type': 'application',
             'left': {
                 'type': 'variable',
                 'value': 't'
             },
             'right': {
                 'type': 'variable',
                 'value': 'y'
             }
         })
Example #10
0
 def test_parse2(self):
     self.assertEqual(
         Parser.full_parse(self.bound_and_free), {
             'type':
             'lambda',
             'binder':
             'x',
             'body': [{
                 'type': 'variable',
                 'value': 'x'
             }, {
                 'type': 'variable',
                 'value': 'y'
             }]
         })
Example #11
0
 def test_parse3(self):
     self.assertEqual(
         Parser.full_parse(self.application_tokens), {
             'type': 'application',
             'left': {
                 'type': 'lambda',
                 'binder': 'x',
                 'body': [{
                     'type': 'variable',
                     'value': 'x'
                 }]
             },
             'right': {
                 'type': 'variable',
                 'value': 't'
             }
         })
Example #12
0
 def test_nested_parse(self):
     string = "(lambda x. x) ((lambda x. x) (lambda z. (lambda x. x) x))"
     tokens = Lexer.tokenize(string)
     self.assertEqual(
         Parser.full_parse(tokens), {
             'type': 'application',
             'left': {
                 'type': 'lambda',
                 'binder': 'x',
                 'body': [{
                     'type': 'variable',
                     'value': 'x'
                 }]
             },
             'right': {
                 'type': 'application',
                 'left': {
                     'type': 'lambda',
                     'binder': 'x',
                     'body': [{
                         'type': 'variable',
                         'value': 'x'
                     }]
                 },
                 'right': {
                     'type':
                     'lambda',
                     'binder':
                     'z',
                     'body': [{
                         'type': 'lambda',
                         'binder': 'x',
                         'body': [{
                             'type': 'variable',
                             'value': 'x'
                         }]
                     }, {
                         'type': 'variable',
                         'value': 'x'
                     }]
                 }
             }
         })
Example #13
0
 def test_parse_list_of_variables(self):
     self.assertEqual(
         Parser.full_parse(Lexer.tokenize("x y z")), {
             'type': 'application',
             'left': {
                 'type': 'variable',
                 'value': 'x'
             },
             'right': {
                 'type': 'application',
                 'left': {
                     'type': 'variable',
                     'value': 'y'
                 },
                 'right': {
                     'type': 'variable',
                     'value': 'z'
                 }
             }
         })
 def test_nested_parse(self):
     string = "(lambda x. x) ((lambda x. x) (lambda z. (lambda x. x) x))"
     tokens = Lexer.tokenize(string)
     self.assertEqual(Parser.full_parse(tokens),
                      {'type': 'application',
                       'left': {'type': 'lambda', 'binder': 'x',
                                'body': [{'type': 'variable',
                                         'value': 'x'}]},
                       'right': {'type': 'application',
                                 'left': {'type': 'lambda',
                                          'binder': 'x',
                                          'body': [{'type': 'variable',
                                                   'value': 'x'}]},
                                 'right': {'type': 'lambda',
                                           'binder': 'z',
                                           'body': [{'type': 'lambda',
                                                     'binder': 'x',
                                                     'body': [{'type': 'variable',
                                                               'value': 'x'}]},
                                                    {'type': 'variable',
                                                     'value': 'x'}]}}})
Example #15
0
 def test_scope2(self):
     self.assertEqual(Parser.scope(self.id_tokens),
                      [['lambda', 'x', '.', 'x']])
Example #16
0
 def test_matched_paren3(self):
     self.assertEqual(Parser.matched_parens('()('), False)
Example #17
0
 def test_scope1(self):
     self.assertEqual(Parser.scope(self.application_tokens),
                      [['lambda', 'x', '.', 'x'], 't'])
Example #18
0
 def test_eval2(self):
     newTokens = ['(', 'lambda', 'x', '.', 'x', 'y', ')', 't']
     parsed = Parser.full_parse(newTokens)
     self.assertEqual(Evaluator.eval(parsed), "t y")
Example #19
0
 def test_matched_paren1(self):
     self.assertEqual(Parser.matched_parens('((testing) 1 2 3)'), True)
 def test_parse1(self):
     self.assertEqual(Parser.full_parse(self.id_tokens),
                      {'type': 'lambda', 'binder': 'x',
                       'body': [{'type': 'variable', 'value': 'x'}]})
Example #21
0
 def test_eval1(self):
     parsed = Parser.full_parse(self.application_tokens)
     self.assertEqual(Evaluator.eval(parsed), "t")
Example #22
0
 def test_scope3(self):
     newTokens = ['(', 'lambda', 'x', '.', 'x', 'y', ')', 't']
     self.assertEqual(Parser.scope(newTokens),
                      [['lambda', 'x', '.', 'x', 'y'], 't'])
 def test_eval1(self):
     parsed = Parser.full_parse(self.application_tokens)
     self.assertEqual(Evaluator.eval(parsed), "t")
 def test_matched_paren3(self):
     self.assertEqual(Parser.matched_parens('()('), False)
 def test_parse2(self):
     self.assertEqual(Parser.full_parse(self.bound_and_free),
                      {'type': 'lambda', 'binder': 'x',
                       'body': [{'type': 'variable', 'value': 'x'},
                                {'type': 'variable', 'value': 'y'}]})
 def test_raw_eval1(self):
     parsed = Parser.full_parse(self.application_tokens)
     self.assertEqual(Evaluator.raw_eval(parsed),
                      {'type': 'variable', 'value': 't'})
 def test_scope1(self):
     self.assertEqual(Parser.scope(self.application_tokens),
                      [['lambda', 'x', '.', 'x'], 't'])
 def test_scope2(self):
     self.assertEqual(Parser.scope(self.id_tokens),
                      [['lambda', 'x', '.', 'x']])
 def test_eval2(self):
     newTokens = ['(', 'lambda', 'x', '.', 'x', 'y', ')', 't']
     parsed = Parser.full_parse(newTokens)
     self.assertEqual(Evaluator.eval(parsed), "t y")
Example #30
0
 def test_raw_eval1(self):
     parsed = Parser.full_parse(self.application_tokens)
     self.assertEqual(Evaluator.raw_eval(parsed), {
         'type': 'variable',
         'value': 't'
     })
 def test_matched_paren1(self):
     self.assertEqual(Parser.matched_parens('((testing) 1 2 3)'), True)
 def test_scope3(self):
     newTokens = ['(', 'lambda', 'x', '.', 'x', 'y', ')', 't']
     self.assertEqual(Parser.scope(newTokens),
                      [['lambda', 'x', '.', 'x', 'y'], 't'])