compiler/PPCUniversalConfiguration.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 24 Aug 2015 17:38:44 +0100
changeset 527 9b50ec9a6918
parent 524 f6f68d32de73
child 529 439c4057517f
permissions -rw-r--r--
Added missing #new methods

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

"{ NameSpace: Smalltalk }"

PPCConfiguration subclass:#PPCUniversalConfiguration
	instanceVariableNames:'clazz'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Core'
!

!PPCUniversalConfiguration methodsFor:'compiling'!

buildClass
    |  builder |
    self assert: (clazz isKindOf: PPCClass).
    
    builder := PPCClassBuilder new.
    
    builder compiledClassName: arguments parserName.
    builder compiledSuperclass: PPCompiledParser.
    builder methodDictionary: clazz methodDictionary.
    builder constants: clazz constants.

    ^ builder compileClass.	
!

initialize
    super initialize.

    clazz := PPCClass new.
!

invokePhases
    self toPPCIr.
    self createTokens.
    self cacheFirstFollow.
    self specialize.
    self createRecognizingComponents.
    self specialize.
    self inline.
    self merge.
    self check.	
    self generate.
! !

!PPCUniversalConfiguration methodsFor:'hooks'!

codeGenerator
    ^ PPCUniversalCodeGenerator new
        arguments: arguments
! !

!PPCUniversalConfiguration methodsFor:'phases'!

generate
    | rootMethod compiledParser |
    arguments generate ifFalse: [ ^ self ].
    
    rootMethod := self codeGenerator
        arguments: arguments;
        clazz: clazz;
        visit: ir.
    
    compiledParser := self buildClass.
    compiledParser startSymbol: rootMethod methodName.
    compiledParser := compiledParser new.
    
    ir := compiledParser.
! !