Mercurial > lcfOS
comparison test/testpyy.py @ 319:8d07a4254f04
Work on burg
author | Windel Bouwman |
---|---|
date | Sat, 18 Jan 2014 18:58:43 +0100 |
parents | e84047f29c78 |
children | 4d204f6f7d4e |
comparison
equal
deleted
inserted
replaced
318:e84047f29c78 | 319:8d07a4254f04 |
---|---|
1 import unittest | 1 import unittest |
2 from pyyacc import Grammar, Item, ParserGenerationException, ParserException | 2 from pyyacc import Grammar, Item, ParserGenerationException, ParserException |
3 from pyyacc import EPS, EOF | 3 from pyyacc import EPS, EOF, calculate_first_sets |
4 from ppci import Token | 4 from ppci import Token |
5 | 5 |
6 | 6 |
7 class genTokens: | 7 class genTokens: |
8 def __init__(self, lst): | 8 def __init__(self, lst): |
121 tokens = genTokens(['id', ':', 'id', 'id']) # i.e. "lab_0: inc rax" | 121 tokens = genTokens(['id', ':', 'id', 'id']) # i.e. "lab_0: inc rax" |
122 p.parse(tokens) | 122 p.parse(tokens) |
123 tokens = genTokens(['id', 'id']) # i.e. "inc rax" | 123 tokens = genTokens(['id', 'id']) # i.e. "inc rax" |
124 p.parse(tokens) | 124 p.parse(tokens) |
125 | 125 |
126 def testEpsSequence(self): | |
127 """ Test epsilon terminal for use in sequences """ | |
128 g = Grammar(['a']) | |
129 g.add_production('aas', []) | |
130 g.add_production('aas', ['aas', 'a']) | |
131 g.start_symbol = 'aas' | |
132 p = g.genParser() | |
133 tokens = genTokens(['a', 'a', 'a']) | |
134 p.parse(tokens) | |
135 tokens = genTokens([]) | |
136 p.parse(tokens) | |
137 | |
126 def test_cb(self): | 138 def test_cb(self): |
127 """ Test callback of one rule and order or parameters """ | 139 """ Test callback of one rule and order or parameters """ |
128 self.cb_called = False | 140 self.cb_called = False |
129 def cb(a, c, b): | 141 def cb(a, c, b): |
130 self.cb_called = True | 142 self.cb_called = True |
154 g.start_symbol = 'input' | 166 g.start_symbol = 'input' |
155 self.g = g | 167 self.g = g |
156 | 168 |
157 def testFirstSimpleGrammar(self): | 169 def testFirstSimpleGrammar(self): |
158 # 1. define a simple grammar: | 170 # 1. define a simple grammar: |
159 first = self.g.calcFirstSets() | 171 first = calculate_first_sets(self.g) |
160 self.assertEqual(first['input'], {'identifier', '(', 'num'}) | 172 self.assertEqual(first['input'], {'identifier', '(', 'num'}) |
161 self.assertEqual(first['term'], {'identifier', '(', 'num'}) | 173 self.assertEqual(first['term'], {'identifier', '(', 'num'}) |
162 | 174 |
163 def testCanonical(self): | 175 def testCanonical(self): |
164 s0 = self.g.initialItemSet() | 176 s0 = self.g.initialItemSet() |