compiler/PPCTokenizingConfiguration.st
changeset 515 b5316ef15274
parent 464 f6d77fee9811
child 516 3b81c9e53352
child 524 f6f68d32de73
equal deleted inserted replaced
502:1e45d3c96ec5 515:b5316ef15274
     1 "{ Package: 'stx:goodies/petitparser/compiler' }"
     1 "{ Package: 'stx:goodies/petitparser/compiler' }"
     2 
     2 
     3 "{ NameSpace: Smalltalk }"
     3 "{ NameSpace: Smalltalk }"
     4 
     4 
     5 PPCConfiguration subclass:#PPCTokenizingConfiguration
     5 PPCConfiguration subclass:#PPCTokenizingConfiguration
     6 	instanceVariableNames:''
     6 	instanceVariableNames:'codeGen'
     7 	classVariableNames:''
     7 	classVariableNames:''
     8 	poolDictionaries:''
     8 	poolDictionaries:''
     9 	category:'PetitCompiler-Core'
     9 	category:'PetitCompiler-Core'
    10 !
    10 !
    11 
    11 
    12 !PPCTokenizingConfiguration methodsFor:'compiling'!
    12 !PPCTokenizingConfiguration methodsFor:'compiling'!
       
    13 
       
    14 buildClass: compiler
       
    15     |  builder |
       
    16     builder := PPCClassBuilder new.
       
    17     
       
    18     builder compiledClassName: arguments parserName.
       
    19     builder compiledSuperclass: PPTokenizingCompiledParser.
       
    20     builder methodDictionary: compiler methodDictionary.
       
    21     builder constants: compiler constants.
       
    22 
       
    23     ^ builder compileClass.	
       
    24 !
    13 
    25 
    14 invokePhases
    26 invokePhases
    15     self toPPCIr.
    27     self toPPCIr.
    16     self createTokens.
    28     self createTokens.
    17     self cacheFirstFollow.
    29     self cacheFirstFollow.
    23     self specialize.
    35     self specialize.
    24     self inline.
    36     self inline.
    25     self merge.
    37     self merge.
    26     self check.	
    38     self check.	
    27     self cacheFirstFollow.
    39     self cacheFirstFollow.
       
    40     self generateScanner.		"Please note that codeGen is shared between these two phases"
    28     self generate.
    41     self generate.
    29 ! !
    42 ! !
    30 
    43 
    31 !PPCTokenizingConfiguration methodsFor:'hooks'!
    44 !PPCTokenizingConfiguration methodsFor:'hooks'!
       
    45 
       
    46 codeCompiler
       
    47     codeGen isNil ifTrue: [ codeGen := PPCTokenizingCodeGen on: arguments ].
       
    48     ^ codeGen
       
    49 !
    32 
    50 
    33 codeCompilerOn: args
    51 codeCompilerOn: args
    34     ^ PPCTokenizingCompiler on: args
    52     ^ PPCTokenizingCompiler on: args
    35 !
    53 !
    36 
    54 
    45         arguments: arguments;
    63         arguments: arguments;
    46         visit: ir.
    64         visit: ir.
    47     self remember: #LL1
    65     self remember: #LL1
    48 !
    66 !
    49 
    67 
       
    68 generateScanner
       
    69     | generator scanner |
       
    70     generator :=  PPCTokenCodeGenerator new
       
    71         compiler: self codeCompiler;
       
    72         arguments: arguments;
       
    73         yourself.
       
    74 
       
    75     generator visit: ir.
       
    76     
       
    77     scanner := generator compileScanner.	
       
    78     self codeCompiler addConstant: scanner as: #scannerClass.
       
    79 !
       
    80 
    50 tokenize
    81 tokenize
    51     "
    82     "
    52         This will try transform the parser into the tokenizing parser
    83         This will try transform the parser into the tokenizing parser
    53     "
    84     "
    54     arguments tokenize ifFalse: [ ^ self ] .
    85     arguments tokenize ifFalse: [ ^ self ] .