INTERCAL is a wonderful language, but it is not always easy to understand other people's code. This is particularly the case if they use the COME FROM statement.
Challenge definition
- Write a program or function which take the source code of an INTERCAL program as a text/data stream. If you write a function it is recommended that you also provide a program to call the function, but it will not count towards your score.
- The function output will be a text/data stream of the jumps that program makes, according to the following instructions. The output does not need to be printed, but it does need to be a single text, not an array of strings (for example).
Each line of output will consist of the statement which will be COME FROM and the line number of its COME FROM statement, separated by a
->
. An example:(310) DO .4 <- .3 -> 55
You can trim these lines of source code, but it is not necessary to.
- The test cases will only consist of noncomputed labels (i.e., integer labels).
- The output must be sorted by the source code order of the statements which will be COME FROM, not their label, nor the order of the COME FROM statements or their labels.
- It is possible for multiple statements to COME FROM the same label. In such cases the COME FROM line numbers must be sorted, and separated by commas.
- It is possible for a statement to COME FROM itself.
- A COME FROM statement may be prefixed with a NOT statement. In such cases the line number must be wrapped in square brackets.
- The words COME FROM can appear in a comment and must be ignored. You do not need to fully parse the file: if they are followed by a label (a number in parentheses) then you can assume it is a real statement.
Scoring
Entrants will be scored by the character length of their program or function.
Test cases
These test cases all come from the calvinmetcalf/intercal Github repo. Although any useful application will safely accept any input, for the purposes of this challenge you need only account for these five test cases.
(10) PLEASE DON'T GIVE UP -> 87
(33) DON'T GIVE UP -> 92
(15) DO (13) NEXT -> 26
(16) DO .12 <- .1 -> 6
(23) DO (21) NEXT -> 3
(7202) DO RETRIEVE .203+,202 -> 75
(4202) DO ,202SUB.201.202#7 <- ,201SUB.201.202#7 -> 108
(6202) DO ,201SUB.201.202#7 <- ,202SUB.201.202#7 -> 117
(4203) DO READ OUT ,201SUB.201.202#7 -> 133
(4302) DO .302 <- .2 -> 181
(5410) DO ,400SUB#124 <- #4 $ #17 -> 293
(3410) PLEASE (4410) NEXT -> 288
(5402) DO (412) NEXT -> 328
(4412) PLEASE (3412) NEXT -> 334
(3423) DO FORGET #2 -> 375
(4404) DO RETRIEVE .311+.312 -> 411
(5404) PLEASE DO (414) NEXT -> 430
(4434) DO FORGET #1 -> 441
(3454) DO (103) NEXT -> 451
(5502) DO .512 <- .312 -> 520
(8503) PLEASE RETRIEVE .311+.312 -> 621
(7503) DO (302) NEXT -> 515
(3622) DO (302) NEXT -> 514
(603) PLEASE FORGET #2 -> 622
(10) DO NOTHING -> 5, 11
(20) PLEASE (100) NEXT -> 6
(30) PLEASE (200) NEXT -> 12
(103) DO (104) NEXT -> 27
(104) DO (105) NEXT -> 19
(1) DO (2) NEXT -> 36
(2) DO (105) NEXT -> 194
(202) DO NOT .2 <- #2 AGAIN -> [196]
(203) DO (204) NEXT -> 167
(204) DO (205) NEXT -> 159
(8201) DO NOTHING -> 165, 271
(8202) PLEASE NOTE Fork threads, one dormant, one alive -> 53, 58
(8211) DO COME FROM (8211) -> 60
(8216) DO NOTHING -> 71
(8215) DO NOTHING -> 68
(8217) DO COME FROM (8217) AGAIN -> 118
(8299) DO COME FROM (8299) AGAIN -> 141
(8274) DO (8273) NEXT ONCE -> 158
(8259) PLEASE DO NOTHING -> 166
(8276) DO COME FROM (8276) AGAIN -> 199
(8278) PLEASE DO COME FROM (8278) AGAIN -> 237
INTERCAL is a wonderful language
downvoted for offensive language. \$\endgroup\$^(\d+)
grabs the label? \$\endgroup\$