compiler/tests/PPCompiledExpressionGrammarTest.st
changeset 452 9f4558b3be66
parent 438 20598d7ce9fa
equal deleted inserted replaced
438:20598d7ce9fa 452:9f4558b3be66
    10 !
    10 !
    11 
    11 
    12 !PPCompiledExpressionGrammarTest class methodsFor:'as yet unclassified'!
    12 !PPCompiledExpressionGrammarTest class methodsFor:'as yet unclassified'!
    13 
    13 
    14 resources
    14 resources
    15 	^ (OrderedCollection with: PPCompiledExpressionGrammarResource)
    15     ^ (OrderedCollection with: PPCompiledExpressionGrammarResource)
    16 		addAll: super resources;
    16         addAll: super resources;
    17 		yourself
    17         yourself
    18 ! !
    18 ! !
    19 
    19 
    20 !PPCompiledExpressionGrammarTest methodsFor:'as yet unclassified'!
    20 !PPCompiledExpressionGrammarTest methodsFor:'as yet unclassified'!
    21 
    21 
    22 compilerArguments
    22 compilerArguments
    23 	^ PPCArguments default
    23     ^ PPCArguments default
    24 		profile: true;
    24         profile: true;
    25 		ll: true;
    25         ll: true;
    26 		yourself
    26         yourself
    27 !
    27 !
    28 
    28 
    29 context
    29 context
    30 	^ PPCContext new
    30     ^ PPCContext new
    31 !
    31 !
    32 
    32 
    33 parserClass
    33 parserClass
    34 	^ Smalltalk at: #PPCompiledExpressionGrammar
    34     ^ Smalltalk at: #PPCompiledExpressionGrammar
    35 !
    35 !
    36 
    36 
    37 parserInstanceFor: aSymbol
    37 parserInstanceFor: aSymbol
    38 	^ (Smalltalk at: #PPCompiledExpressionGrammar) new startSymbol: aSymbol
    38     ^ (Smalltalk at: #PPCompiledExpressionGrammar) new startSymbol: aSymbol
       
    39 !
       
    40 
       
    41 testAdd
       
    42     result := self parse: '1+2' rule: #add.
       
    43     self assert: result isArray.
       
    44     self assert: result first = 1.
       
    45     self assert: result second inputValue = '+'.
       
    46     self assert: result third = 2.
       
    47 !
       
    48 
       
    49 testMul
       
    50     result := self parse: '1 * 2' rule: #mul.
       
    51     self assert: result isArray.
       
    52     self assert: result first = 1.
       
    53     self assert: result second inputValue = '*'.
       
    54     self assert: result third = 2.
    39 !
    55 !
    40 
    56 
    41 testNumber
    57 testNumber
    42 	result := self parse: '1' rule: #number.
    58     result := self parse: '1' rule: #number.
    43 	self assert: result = 1.
    59     self assert: result = 1.
       
    60 !
       
    61 
       
    62 testParens
       
    63     result := self parse: '(1)' rule: #parens.
       
    64     self assert: result size = 3.
       
    65     self assert: result first inputValue = '('.
       
    66     self assert: result second = 1.
       
    67     self assert: result third inputValue = ')'.
       
    68     
       
    69 !
       
    70 
       
    71 testPrim
       
    72     result := self parse: '1' rule: #prim.
       
    73     self assert: result = 1.
       
    74 !
       
    75 
       
    76 testPrim2
       
    77     result := self parse: '(1)' rule: #prim.
       
    78     self assert: result size = 3.
       
    79     self assert: result second = 1.
       
    80 !
       
    81 
       
    82 testProd
       
    83     result := self parse: '1' rule: #prod.
       
    84     self assert: result = 1.
    44 !
    85 !
    45 
    86 
    46 testTerm
    87 testTerm
    47 	result := self parse: '1 + 2' rule: #term.
    88     result := self parse: '1' rule: #term.
    48 	self assert: result size = 3.
    89     self assert: result = 1.
    49 	self assert: result first = 1.
    90     
    50 	self assert: result second inputValue = '+'.
    91 !
    51 	self assert: result third = 2.
    92 
    52 	
    93 testTerm11
       
    94     result := self parse: '1 + 2' rule: #term.
       
    95     self assert: result size = 3.
       
    96     self assert: result first = 1.
       
    97     self assert: result second inputValue = '+'.
       
    98     self assert: result third = 2.
       
    99     
       
   100 !
       
   101 
       
   102 testTerm12
       
   103     result := self parse: '1 + 2 * 3' rule: #term.
       
   104     self assert: result size = 3.
       
   105     self assert: result second inputValue = '+'.
       
   106     self assert: result first = 1.
       
   107     self assert: result third isArray.
       
   108     self assert: result third first = 2.
       
   109     self assert: result third second inputValue = '*'.
       
   110     self assert: result third third = 3.	
       
   111 !
       
   112 
       
   113 testTerm13
       
   114     result := self parse: '1 * 2 + 3' rule: #term.
       
   115     self assert: result size = 3.
       
   116     self assert: result first isArray.
       
   117     self assert: result first first = 1.
       
   118     self assert: result first second inputValue = '*'.
       
   119     self assert: result first third = 2.	
       
   120     self assert: result second inputValue = '+'.
       
   121     self assert: result third = 3.
    53 ! !
   122 ! !
    54 
   123