📄 t-gen-testsuite.st
字号:
basicScannerTest1
"TranslatorGenerator basicScannerTest1"
| tgen failBlock testName |
testName := 'T-gen Scanner Test 1'.
tgen := self new setGrammarModeToLR.
tgen scannerClass: FSABasedScannerWithOneTokenLookahead.
failBlock := [self error: testName, ' failed.'].
Transcript cr; show: 'START: ' , testName; cr.
tgen
parseInputs: #(
'abc'
'abd'
)
compareDTTo: (Array
with: '#S\ . #E\ . . ''abc''\ . #S\ . . ''<epsilon>''\' withCRs
with: '#S\ . #E\ . . ''a''\ . #S\ . . #E\ . . . ''bd''\ . . #S\ . . . ''<epsilon>''\' withCRs
)
tokenSpec: ''
grammarSpec: 'S : E S | ; E : ''a'' | ''abc'' | ''bd'' ;'
ifFail: failBlock.
Transcript cr; show: 'STOP: ' , testName!
basicScannerTest2
"TranslatorGenerator basicScannerTest2"
| tgen failBlock testName |
testName := 'T-gen Scanner Test 2'.
tgen := self new setGrammarModeToLR.
tgen scannerClass: FSABasedScannerWithTwoTokenLookahead.
failBlock := [self error: testName, ' failed.'].
Transcript cr; show: 'START: ' , testName; cr.
tgen
parseInputs: #(
'abc'
'abd'
'abbd'
'a'
)
compareDTTo: (Array
with: '#S\ . #E\ . . ''abc''\ . #S\ . . ''<epsilon>''\' withCRs
with: '#S\ . #E\ . . ''a''\ . #S\ . . #E\ . . . ''bd''\ . . #S\ . . . ''<epsilon>''\' withCRs
with: '#S\ . #E\ . . ''ab''\ . #S\ . . #E\ . . . ''bd''\ . . #S\ . . . ''<epsilon>''\' withCRs
with: '#S\ . #E\ . . ''a''\ . #S\ . . ''<epsilon>''\' withCRs
)
tokenSpec: ''
grammarSpec: 'S : E S | ; E : ''a'' | ''ab'' | ''abc'' | ''bd'' ;'
ifFail: failBlock.
Transcript cr; show: 'STOP: ' , testName!
rrpgToCfgTransformationsTest1
"TranslatorGenerator rrpgToCfgTransformationsTest1"
| tgen failBlock testName |
testName := 'T-gen RRPG-to-CFG Transformation Test 1'.
tgen := self new setGrammarModeToLR.
failBlock := [self error: testName, ' failed.'].
Transcript cr; show: 'START: ' , testName; cr.
tgen tokenSpecification: ''.
tgen
grammarSpec: 'S : ''b''+ ;\' withCRs
targetGrammar: 'S : S0 ;\S0 : ''b'' S0 ;\S0 : ''b'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' ''b''+ ;\' withCRs
targetGrammar: 'S : ''a'' S0 ;\S0 : ''b'' S0 ;\S0 : ''b'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''b''+ ''c'' ;\' withCRs
targetGrammar: 'S : S0 ;\S0 : ''b'' S0 ;\S0 : ''b'' ''c'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' ''b''+ ''c'' ;\' withCRs
targetGrammar: 'S : ''a'' S0 ;\S0 : ''b'' S0 ;\S0 : ''b'' ''c'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''b''* ;\' withCRs
targetGrammar: 'S : S0 ;\S0 : ''b'' S0 ;\S0 : ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' ''b''* ;\' withCRs
targetGrammar: 'S : ''a'' S0 ;\S0 : ''b'' S0 ;\S0 : ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''b''* ''c'' ;\' withCRs
targetGrammar: 'S : S0 ;\S0 : ''b'' S0 ;\S0 : ''c'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' ''b''* ''c'' ;\' withCRs
targetGrammar: 'S : ''a'' S0 ;\S0 : ''b'' S0 ;\S0 : ''c'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''b''? ;\' withCRs
targetGrammar: 'S : S0 ;\S0 : ''b'' ;\S0 : ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' ''b''? ;\' withCRs
targetGrammar: 'S : ''a'' S0 ;\S0 : ''b'' ;\S0 : ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''b''? ''c'' ;\' withCRs
targetGrammar: 'S : S0 ;\S0 : ''b'' ''c'' ;\S0 : ''c'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' ''b''? ''c'' ;\' withCRs
targetGrammar: 'S : ''a'' S0 ;\S0 : ''b'' ''c'' ;\S0 : ''c'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''b'' ^ ''d'' ;\' withCRs
targetGrammar: 'S : S0 ;\S0 : ''b'' ;\S0 : ''b'' ''d'' S0 ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' ''b'' ^ ''d'' ;\' withCRs
targetGrammar: 'S : S0 ;\S0 : ''a'' ''b'' ;\S0 : ''a'' ''b'' ''d'' S0 ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''b'' ^ ''d'' ''c'' ;\' withCRs
targetGrammar: 'S : S0 ;\S0 : ''b'' ;\S0 : ''b'' ''d'' ''c'' S0 ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' ''b'' ^ ''d'' ''c'' ;\' withCRs
targetGrammar: 'S : S0 ;\S0 : ''a'' ''b'' ;\S0 : ''a'' ''b'' ''d'' ''c'' S0 ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''b'' | ''d'' ;\' withCRs
targetGrammar: 'S : ''b'' ;\S : ''d'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' ''b'' | ''d'' ;\' withCRs
targetGrammar: 'S : ''a'' ''b'' ;\S : ''d'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''b'' | ''d'' ''c'' ;\' withCRs
targetGrammar: 'S : ''b'' ;\S : ''d'' ''c'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' ''b'' | ''d'' ''c'' ;\' withCRs
targetGrammar: 'S : ''a'' ''b'' ;\S : ''d'' ''c'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : (''b'' | ''d'') ;\' withCRs
targetGrammar: 'S : ''b'' ;\S : ''d'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' (''b'' | ''d'') ;\' withCRs
targetGrammar: 'S : ''a'' ''b'' ;\S : ''a'' ''d'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : (''b'' | ''d'') ''c'' ;\' withCRs
targetGrammar: 'S : ''b'' ''c'' ;\S : ''d'' ''c'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' (''b'' | ''d'') ''c'' ;\' withCRs
targetGrammar: 'S : ''a'' ''b'' ''c'' ;\S : ''a'' ''d'' ''c'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : A B+ ;\A : ''a'' ;\B : ''b'' ;\' withCRs
targetGrammar: 'S : A S0 ;\S0 : B S0 ;\S0 : B ;\A : ''a'' ;\B : ''b'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : A B* ;\A : ''a'' ;\B : ''b'' ;\' withCRs
targetGrammar: 'S : A S0 ;\S0 : B S0 ;\S0 : ;\A : ''a'' ;\B : ''b'' ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : A B? ;\A : ''a'' ;\B : ''b'' ;\' withCRs
targetGrammar: 'S : A S0 ;\S0 : B ;\S0 : ;\A : ''a'' ;\B : ''b'' ;\' withCRs
ifFail: failBlock.
Transcript cr; show: 'STOP: ' , testName!
rrpgToCfgTransformationsTest2
"TranslatorGenerator rrpgToCfgTransformationsTest2"
| tgen failBlock testName |
testName := 'T-gen RRPG-to-CFG Transformation Test 2'.
tgen := self new setGrammarModeToLR.
failBlock := [self error: testName, ' failed.'].
Transcript cr; show: 'START: ' , testName; cr.
tgen tokenSpecification: ''.
tgen
grammarSpec: 'S : ''a'' (''b'' | ''d'')? ;\' withCRs
targetGrammar: 'S : ''a'' S0 ;\S0 : ''b'' ;\S0 : ''d'' ;\S0 : ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' ''b'' | ''d''? ;\' withCRs
targetGrammar: 'S : ''a'' ''b'' ;\S : S0 ;\S0 : ''d'' ;\S0 : ;\' withCRs
ifFail: failBlock.
tgen
grammarSpec: 'S : ''a'' (B ^ C)? ;\B : ''b'' ;\C : ''c'' ;\' withCRs
targetGrammar: 'S : ''a'' S0 ;\S0 : S00 ;\S00 : B ;\S00 : B C S00 ;\S0 : ;\B : ''b'' ;\C : ''c'' ;\' withCRs
ifFail: failBlock.
Transcript cr; show: 'STOP: ' , testName!
runAllTests
"TranslatorGenerator runAllTests"
Transcript cr; show: 'T-gen TEST SUITE (answer ''yes'' to all prompters)'.
self basicLLParserGenerationTest1.
self basicLLParserGenerationTest2.
self basicLLParserGenerationTest3.
self basicLRParserGenerationTest1.
self basicLRParserGenerationTest2.
self basicLRParserGenerationTest3.
self basicLRParserGenerationTest4.
self basicLRParserGenerationTest5.
self basicLRParserGenerationTest6.
self basicScannerTest1.
self basicScannerTest2.
self rrpgToCfgTransformationsTest1.
self rrpgToCfgTransformationsTest2.
Transcript cr; show: 'ALL TESTS PASSED'; cr.! !
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -