author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 08 Oct 2015 09:41:03 +0100 | |
changeset 548 | 5536a6da50e4 |
parent 502 | 1e45d3c96ec5 |
permissions | -rw-r--r-- |
376
a2656b27cace
Added monticelloName to package definition to ease export to .mcz
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
375
diff
changeset
|
1 |
"{ Package: 'stx:goodies/petitparser/tests' }" |
0 | 2 |
|
427
a7f5e6de19d2
Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
3 |
"{ NameSpace: Smalltalk }" |
a7f5e6de19d2
Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
4 |
|
0 | 5 |
PPCompositeParser subclass:#PPArithmeticParser |
6 |
instanceVariableNames:'terms addition factors multiplication power primary parentheses |
|
7 |
number' |
|
8 |
classVariableNames:'' |
|
9 |
poolDictionaries:'' |
|
10 |
category:'PetitTests-Examples' |
|
11 |
! |
|
12 |
||
13 |
||
14 |
!PPArithmeticParser methodsFor:'accessing'! |
|
15 |
||
16 |
start |
|
17 |
^ terms end |
|
18 |
! ! |
|
19 |
||
20 |
!PPArithmeticParser methodsFor:'grammar'! |
|
21 |
||
22 |
addition |
|
183 | 23 |
^ (factors separatedBy: ($+ asParser / $- asParser) trim) |
24 |
foldLeft: [ :a :op :b | a perform: op asSymbol with: b ] |
|
0 | 25 |
! |
26 |
||
27 |
factors |
|
28 |
^ multiplication / power |
|
29 |
! |
|
30 |
||
31 |
multiplication |
|
183 | 32 |
^ (power separatedBy: ($* asParser / $/ asParser) trim) |
33 |
foldLeft: [ :a :op :b | a perform: op asSymbol with: b ] |
|
0 | 34 |
! |
35 |
||
36 |
number |
|
183 | 37 |
^ ($- asParser optional , #digit asParser plus , ($. asParser , #digit asParser plus) optional) flatten trim |
38 |
==> [ :value | value asNumber ] |
|
0 | 39 |
! |
40 |
||
41 |
parentheses |
|
183 | 42 |
^ $( asParser trim , terms , $) asParser trim |
427
a7f5e6de19d2
Merged JK's version from Monticello
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
43 |
==> [ :nodes | nodes at: 2 ] |
0 | 44 |
! |
45 |
||
46 |
power |
|
183 | 47 |
^ (primary separatedBy: $^ asParser trim) |
48 |
foldRight: [ :a :op :b | a raisedTo: b ] |
|
0 | 49 |
! |
50 |
||
51 |
primary |
|
52 |
^ number / parentheses |
|
53 |
! |
|
54 |
||
55 |
terms |
|
56 |
^ addition / factors |
|
57 |
! ! |
|
58 |
||
59 |
!PPArithmeticParser class methodsFor:'documentation'! |
|
60 |
||
31 | 61 |
version |
183 | 62 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPArithmeticParser.st,v 1.4 2014-03-04 14:33:59 cg Exp $' |
31 | 63 |
! |
64 |
||
65 |
version_CVS |
|
183 | 66 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPArithmeticParser.st,v 1.4 2014-03-04 14:33:59 cg Exp $' |
31 | 67 |
! |
68 |
||
502
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
427
diff
changeset
|
69 |
version_HG |
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
427
diff
changeset
|
70 |
|
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
427
diff
changeset
|
71 |
^ '$Changeset: <not expanded> $' |
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
427
diff
changeset
|
72 |
! |
1e45d3c96ec5
Updated to PetitCompiler-JanVrany.135, PetitCompiler-Tests-JanKurs.93, PetitCompiler-Extras-Tests-JanVrany.16, PetitCompiler-Benchmarks-JanKurs.12
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
427
diff
changeset
|
73 |
|
0 | 74 |
version_SVN |
183 | 75 |
^ '$Id: PPArithmeticParser.st,v 1.4 2014-03-04 14:33:59 cg Exp $' |
0 | 76 |
! ! |
183 | 77 |