equal
deleted
inserted
replaced
1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 PPCompositeParser subclass:#PPLL1ExpressionGrammar |
|
6 instanceVariableNames:'add prod term mul prim parens number mulPrime addPrime termPrime' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'PetitCompiler-Tests-ExpressionGrammar' |
|
10 ! |
|
11 |
|
12 !PPLL1ExpressionGrammar methodsFor:'as yet unclassified'! |
|
13 |
|
14 add |
|
15 ^ prod, addPrime optional |
|
16 map: [ :_prod :_addPrime | |
|
17 _addPrime isNil |
|
18 ifTrue: [ _prod ] |
|
19 ifFalse: [ Array with: _prod withAll: _addPrime ] |
|
20 |
|
21 ] |
|
22 ! |
|
23 |
|
24 addPrime |
|
25 ^ $+ asParser trimmingToken , term |
|
26 ! |
|
27 |
|
28 mul |
|
29 ^ prim, mulPrime optional |
|
30 map: [ :_prim :_mulPrime | |
|
31 _mulPrime isNil |
|
32 ifTrue: [ _prim ] |
|
33 ifFalse: [ Array with: _prim withAll: _mulPrime ] |
|
34 |
|
35 ] |
|
36 ! |
|
37 |
|
38 mulPrime |
|
39 ^ $* asParser trimmingToken, prod |
|
40 ! |
|
41 |
|
42 number |
|
43 ^ #digit asParser plus trimmingToken ==> [ :token | token inputValue asNumber ] |
|
44 ! |
|
45 |
|
46 parens |
|
47 ^ ($( asParser token trim), term , ($) asParser token trim) |
|
48 ! |
|
49 |
|
50 prim |
|
51 ^ parens / number |
|
52 ! |
|
53 |
|
54 prod |
|
55 ^ mul |
|
56 ! |
|
57 |
|
58 start |
|
59 ^ term end |
|
60 ! |
|
61 |
|
62 term |
|
63 ^ prod, termPrime optional |
|
64 map: [ :_prod :_termPrime | |
|
65 _termPrime isNil |
|
66 ifTrue: [ _prod ] |
|
67 ifFalse: [ Array with: _prod withAll: _termPrime ] |
|
68 ] |
|
69 ! |
|
70 |
|
71 termPrime |
|
72 ^ $+ asParser trimmingToken, term |
|
73 ! ! |
|
74 |
|