def test_nested_tokenize(self):
     string = "(lambda x. x) ((lambda x. x) (lambda z. (lambda x. x) x))"
     self.assertEqual(Lexer.tokenize(string),
                      ['(', 'lambda', 'x', '.', 'x', ')', '(', '(',
                       'lambda', 'x', '.', 'x', ')', '(', 'lambda', 'z',
                       '.', '(', 'lambda', 'x', '.', 'x', ')', 'x', ')',
                       ')'])
Beispiel #2
0
 def test_nested_tokenize(self):
     string = "(lambda x. x) ((lambda x. x) (lambda z. (lambda x. x) x))"
     self.assertEqual(Lexer.tokenize(string), [
         '(', 'lambda', 'x', '.', 'x', ')', '(', '(', 'lambda', 'x', '.',
         'x', ')', '(', 'lambda', 'z', '.', '(', 'lambda', 'x', '.', 'x',
         ')', 'x', ')', ')'
     ])
Beispiel #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']]])
Beispiel #5
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 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 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
Beispiel #8
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'
                     }]
                 }
             }
         })
Beispiel #9
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'}]}}})
Beispiel #11
0
 def test_tokenize3(self):
     self.assertEqual(Lexer.tokenize('(lambda x. x)'),
                      ['(', 'lambda', 'x', '.', 'x', ')'])
Beispiel #12
0
 def test_tokenize2(self):
     self.assertEqual(Lexer.tokenize('bill (bob)'),
                      ['bill', '(', 'bob', ')'])
Beispiel #13
0
 def test_tokenize1(self):
     self.assertEqual(Lexer.tokenize('(bob) bill'),
                      ['(', 'bob', ')', 'bill'])
 def test_tokenize3(self):
     self.assertEqual(Lexer.tokenize('(lambda x. x)'),
                      ['(', 'lambda', 'x', '.', 'x', ')'])
 def test_tokenize2(self):
     self.assertEqual(Lexer.tokenize('bill (bob)'),
                      ['bill', '(', 'bob', ')'])
 def test_tokenize1(self):
     self.assertEqual(Lexer.tokenize('(bob) bill'),
                      ['(', 'bob', ')', 'bill'])