compiler/PPCCacheFirstFollowPass.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 18 Jan 2016 08:05:03 +0000
changeset 555 4aa0496e6c22
parent 534 a949c4fe44df
permissions -rw-r--r--
For tests on Pharo 5.0, use Spur VM

"{ Package: 'stx:goodies/petitparser/compiler' }"

"{ NameSpace: Smalltalk }"

PPCPass subclass:#PPCCacheFirstFollowPass
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Core'
!

!PPCCacheFirstFollowPass methodsFor:'running'!

run: ir
    "Actually run the pass on given IR (tree of PPCNode) and return
     (possibly transformed or completely new) another IR."

    | firstSets firstSetsWithTokens followSets followSetsWithTokens |

    "Cache first sets"
    firstSets := ir firstSets.
    ir allNodesDo: [ :node | node firstSet: (firstSets at: node) ].
    firstSetsWithTokens := ir firstSetsSuchThat: [:e | e isTerminal or: [ e isTokenNode ] ].
    ir allNodesDo: [ :node | node firstSetWithTokens: (firstSetsWithTokens at: node) ].

    "Cache follow sets"
    followSets := ir followSets.
    ir allNodesDo: [ :node | node followSet: (followSets at: node) ].
    followSetsWithTokens := ir followSetsSuchThat: [:e | e isTerminal or: [ e isTokenNode ] ].
    ir allNodesDo: [ :node | node followSetWithTokens: (followSetsWithTokens at: node) ].
    ^ ir

    "Created: / 29-08-2015 / 07:27:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !