1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 PPCompositeParserTest subclass:#PPTokenizedLL1ExpressionGrammarTest |
|
6 instanceVariableNames:'' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Tests-ExpressionGrammar' |
|
10 ! |
|
11 |
|
12 !PPTokenizedLL1ExpressionGrammarTest class methodsFor:'as yet unclassified'! |
|
13 |
|
14 resources |
|
15 ^ (OrderedCollection with: PPTokenizedLL1ExpressionGrammarResource) |
|
16 addAll: super resources; |
|
17 yourself |
|
18 ! ! |
|
19 |
|
20 !PPTokenizedLL1ExpressionGrammarTest methodsFor:'as yet unclassified'! |
|
21 |
|
22 compilerArguments |
|
23 ^ PPCArguments default |
|
24 profile: true; |
|
25 ll: true; |
|
26 yourself |
|
27 ! |
|
28 |
|
29 context |
|
30 ^ PPCContext new |
|
31 ! |
|
32 |
|
33 parserClass |
|
34 ^ Smalltalk at: #PPTokenizedLL1ExpressionGrammar |
|
35 ! |
|
36 |
|
37 parserInstanceFor: aSymbol |
|
38 ^ (Smalltalk at: #PPCompiledExpressionGrammar) new startSymbol: aSymbol |
|
39 ! |
|
40 |
|
41 testAdd |
|
42 result := self parse: '1+2' rule: #add. |
|
43 self assert: result isArray. |
|
44 self assert: result first = 1. |
|
45 self assert: result second inputValue = '+'. |
|
46 self assert: result third = 2. |
|
47 ! |
|
48 |
|
49 testMul |
|
50 result := self parse: '1 * 2' rule: #mul. |
|
51 self assert: result isArray. |
|
52 self assert: result first = 1. |
|
53 self assert: result second inputValue = '*'. |
|
54 self assert: result third = 2. |
|
55 ! |
|
56 |
|
57 testNumber |
|
58 result := self parse: '1' rule: #number. |
|
59 self assert: result = 1. |
|
60 ! |
|
61 |
|
62 testParens |
|
63 result := self parse: '(1)' rule: #parens. |
|
64 self assert: result size = 3. |
|
65 self assert: result first inputValue = '('. |
|
66 self assert: result second = 1. |
|
67 self assert: result third inputValue = ')'. |
|
68 |
|
69 ! |
|
70 |
|
71 testPrim |
|
72 result := self parse: '1' rule: #prim. |
|
73 self assert: result = 1. |
|
74 ! |
|
75 |
|
76 testPrim2 |
|
77 result := self parse: '(1)' rule: #prim. |
|
78 self assert: result size = 3. |
|
79 self assert: result second = 1. |
|
80 ! |
|
81 |
|
82 testProd |
|
83 result := self parse: '1' rule: #prod. |
|
84 self assert: result = 1. |
|
85 ! |
|
86 |
|
87 testTerm |
|
88 result := self parse: '1' rule: #term. |
|
89 self assert: result = 1. |
|
90 |
|
91 ! |
|
92 |
|
93 testTerm11 |
|
94 result := self parse: '1 + 2' rule: #term. |
|
95 self assert: result size = 3. |
|
96 self assert: result first = 1. |
|
97 self assert: result second inputValue = '+'. |
|
98 self assert: result third = 2. |
|
99 |
|
100 ! |
|
101 |
|
102 testTerm12 |
|
103 result := self parse: '1 + 2 * 3' rule: #term. |
|
104 self assert: result size = 3. |
|
105 self assert: result second inputValue = '+'. |
|
106 self assert: result first = 1. |
|
107 self assert: result third isArray. |
|
108 self assert: result third first = 2. |
|
109 self assert: result third second inputValue = '*'. |
|
110 self assert: result third third = 3. |
|
111 ! |
|
112 |
|
113 testTerm13 |
|
114 result := self parse: '1 * 2 + 3' rule: #term. |
|
115 self assert: result size = 3. |
|
116 self assert: result first isArray. |
|
117 self assert: result first first = 1. |
|
118 self assert: result first second inputValue = '*'. |
|
119 self assert: result first third = 2. |
|
120 self assert: result second inputValue = '+'. |
|
121 self assert: result third = 3. |
|
122 ! ! |
|
123 |
|