compiler/tests/extras/PPLL1ExpressionGrammar.st
changeset 464 f6d77fee9811
child 469 8dc4eb06316e
child 502 1e45d3c96ec5
equal deleted inserted replaced
459:4751c407bb40 464:f6d77fee9811
       
     1 "{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }"
       
     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-Extras-Tests-Expressions'
       
    10 !
       
    11 
       
    12 
       
    13 !PPLL1ExpressionGrammar methodsFor:'as yet unclassified'!
       
    14 
       
    15 add
       
    16    ^ prod, addPrime optional
       
    17  	map: [ :_prod :_addPrime |
       
    18 		_addPrime isNil 
       
    19 			ifTrue: [ _prod  ]
       
    20 			ifFalse: [ Array with: _prod withAll: _addPrime ]
       
    21 		
       
    22 	]
       
    23 !
       
    24 
       
    25 addPrime
       
    26     ^ $+ asParser trimmingToken , term
       
    27 !
       
    28 
       
    29 mul
       
    30    ^ prim, mulPrime optional
       
    31  	map: [ :_prim :_mulPrime |
       
    32 		_mulPrime isNil 
       
    33 			ifTrue: [ _prim  ]
       
    34 			ifFalse: [ Array with: _prim withAll: _mulPrime ]
       
    35 		
       
    36 	]
       
    37 !
       
    38 
       
    39 mulPrime
       
    40    ^ $* asParser trimmingToken, prod
       
    41 !
       
    42 
       
    43 number
       
    44    ^ #digit asParser plus trimmingToken ==> [ :token | token inputValue asNumber ]
       
    45 !
       
    46 
       
    47 parens
       
    48    ^ ($( asParser token trim), term , ($) asParser token trim)
       
    49 !
       
    50 
       
    51 prim
       
    52    ^ parens / number
       
    53 !
       
    54 
       
    55 prod
       
    56    ^ mul
       
    57 !
       
    58 
       
    59 start
       
    60    ^ term end
       
    61 !
       
    62 
       
    63 term
       
    64     ^ prod, termPrime optional
       
    65  	map: [ :_prod :_termPrime |
       
    66         _termPrime isNil 
       
    67             ifTrue: [ _prod  ]
       
    68             ifFalse: [ Array with: _prod withAll: _termPrime ]
       
    69     ]	
       
    70 !
       
    71 
       
    72 termPrime
       
    73     ^ $+ asParser trimmingToken, term
       
    74 ! !
       
    75 
       
    76 !PPLL1ExpressionGrammar class methodsFor:'documentation'!
       
    77 
       
    78 version_HG
       
    79 
       
    80     ^ '$Changeset: <not expanded> $'
       
    81 ! !
       
    82