Closed SuperDoxin closed 8 years ago
Given issue_182.d
with contents
import pegged.grammar;
mixin(grammar(`
assemblyFile:
list <- line+ EOF
line <- :WS? (comment / instruction)
comment <- :';' ~((!'\n' .)*) EOL / EOL
label_list <- (label :WS?)*
label <- ~(!opcode ([a-zA-Z_] [a-zA-Z0-9_]*))
operation <- opcode :'.' modifier / opcode
opcode <~ 'dat' / 'mov' / 'add' /
'sub' / 'mul' / 'div' /
'mod' / 'jmp' / 'jmz' /
'jmn' / 'djn' / 'cmp' /
'slt' / 'spl' / 'sne' /
'seq' / 'org' / 'equ' /
'end'
modifier <- 'ab' / 'ba' / 'a' / 'b' / 'f' / 'x' / 'i' / eps
mode <- '#' / '$' / '@' / '<' / '>' / '{' / '}' / '*' / eps
expr <- '(' expr ')' tail / term tail
tail <- '%' expr / '/' expr / '*' expr / '-' expr / '+' expr / eps
term <- label / number / expr
number <- whole_number / signed_integer
signed_integer <~ '+' whole_number / '-' whole_number
whole_number <~ [0-9]+
WS <- ' '+
EOL <- :'\n' / EOF
EOF <- !.
instruction <- label_list :WS? operation :WS? mode :WS? expr :WS? ',' :WS? mode :WS? expr :WS? comment /
label_list :WS? operation :WS? mode :WS? expr :WS? comment
`));
unittest
{
enum input = `
;redcode-94
;name Behemot
;author Michal Janeczek
;strategy MiniQ^3 -> Stun bomber
;assert CORESIZE==8000
org qGo
bStep equ 2223
bDrop equ 382
bDist equ 3250
bcOff equ 51
bgOff equ 17
bRun equ (bHit-bInc*bDrop)
bGate equ (bClr-bgOff)
bSpl equ (bHit-2*bInc)+1
bJmp equ (bHit-2*bInc)-1
bInc equ 3*bStep
bStart mov.i {0 , #0
bLoop mov bSpl , <bPtr
mov bJmp , *bPtr
bPtr mov bRun-bStep , @bRun+bStep+1
bHit add *bEvac , bPtr
mov >bJmp , @bPtr
jmz.a bLoop , <bJmp
bEvac jmp -bcOff , <1-bcOff-bgOff
bGo spl 1 , bWipe+5
bcDst spl 1 , bDist+4+bEvac-bcOff
mov <bGo , <bbDst
mov <bGo , <bcDst
mov <bBoot , {bBoot
mov <bBoot , {bBoot
bbDst mov.i bGo , #bDist+2+bSpl
bBoot jmp >bDist+bEvac+1 , bEvac+1
spl #bInc , <bInc+1
bClr mov bWipe , >bGate
djn.f bClr , >bGate
bWipe dat <2667 , 2-bGate
jmp bStep , {1
mov @0 , }-1
spl #2 , -bStep
for 35
dat 0 , 0
rof
qf equ qKil
qs equ 222
qd equ 322
qi equ 7
qr equ 11
qGo seq qd+qf+qs , qf+qs
jmp qSki , {qd+qf+qs+qi
seq qd+qf+6*qs , qf+6*qs
jmp qFas , {qd+qf+6*qs+qi
seq qd+qf+5*qs , qf+5*qs
jmp qFas , <qBmb
seq qd+qf+7*qs , qf+7*qs
jmp qFas , >qBmb
seq qd+qf+9*qs , qf+9*qs
djn qFas , {qFas
seq qd+qf+10*qs , qf+10*qs
jmp qFas , {qFas
seq qd+qf+3*qs , qf+3*qs
jmp >qFas , {qd+qf+3*qs+qi
seq qd+qf+2*qs , qf+2*qs
jmp >qFas , {qSlo
seq qd+qf+4*qs , qf+4*qs
jmp >qFas , }qSlo
seq qd+qf+12*qs , qf+12*qs
jmp qSlo , {qSlo
seq qd+qf+15*qs , qf+15*qs
jmp qSlo , <qBmb
seq qd+qf+21*qs , qf+21*qs
jmp qSlo , >qBmb
seq qd+qf+24*qs , qf+24*qs
jmp qSlo , }qSlo
seq qd+qf+27*qs , qf+27*qs
djn qSlo , {qFas
seq qd+qf+30*qs , qf+30*qs
jmp qSlo , {qFas
sne qd+qf+18*qs , qf+18*qs
jmz.f bGo , qd+qf+18*qs-10
qSlo mul.ab #3 , qKil
qFas mul.b qBmb , @qSlo
qSki sne >3456 , @qKil
add #qd , qKil
qLoo mov qBmb , @qKil
qKil mov qBmb , *qs
sub #qi , qKil
djn qLoo , #qr
jmp bGo , >10
qBmb dat {qi*qr-10 , {6
end
`;
import std.stdio;
writeln(assemblyFile(input));
}
and testing with
rdmd -unittest -main -I"<Pegged-dir>" issue_182.d
I get this output:
assemblyFile (failure)
+-assemblyFile.list (failure)
+-assemblyFile.line [1, 17]["redcode-94"]
| +-assemblyFile.comment [5, 17]["redcode-94"]
+-assemblyFile.line [17, 35]["name Behemot"]
| +-assemblyFile.comment [21, 35]["name Behemot"]
+-assemblyFile.line [35, 63]["author Michal Janeczek"]
| +-assemblyFile.comment [39, 63]["author Michal Janeczek"]
+-assemblyFile.line [63, 100]["strategy MiniQ^3 -> Stun bomber"]
| +-assemblyFile.comment [67, 100]["strategy MiniQ^3 -> Stun bomber"]
+-assemblyFile.line [100, 127]["assert CORESIZE==8000"]
| +-assemblyFile.comment [104, 127]["assert CORESIZE==8000"]
+-assemblyFile.line [128, 149]["org", "", "qGo", ""]
| +-assemblyFile.instruction [139, 149]["org", "", "qGo", ""]
| +-assemblyFile.operation [139, 142]["org"]
| | +-assemblyFile.opcode [139, 142]["org"]
| +-assemblyFile.mode [145, 145][""]
| +-assemblyFile.expr [145, 148]["qGo", ""]
| +-assemblyFile.term [145, 148]["qGo"]
| | +-assemblyFile.label [145, 148]["qGo"]
| +-assemblyFile.tail [148, 148][""]
+-assemblyFile.line [150, 172]["bStep", "equ", "", "2223", ""]
| +-assemblyFile.instruction [154, 172]["bStep", "equ", "", "2223", ""]
| +-assemblyFile.label_list [154, 161]["bStep"]
| | +-assemblyFile.label [154, 159]["bStep"]
| +-assemblyFile.operation [161, 164]["equ"]
| | +-assemblyFile.opcode [161, 164]["equ"]
| +-assemblyFile.mode [167, 167][""]
| +-assemblyFile.expr [167, 171]["2223", ""]
| +-assemblyFile.term [167, 171]["2223"]
| | +-assemblyFile.number [167, 171]["2223"]
| | +-assemblyFile.whole_number [167, 171]["2223"]
| +-assemblyFile.tail [171, 171][""]
+-assemblyFile.line [172, 193]["bDrop", "equ", "", "382", ""]
| +-assemblyFile.instruction [176, 193]["bDrop", "equ", "", "382", ""]
| +-assemblyFile.label_list [176, 183]["bDrop"]
| | +-assemblyFile.label [176, 181]["bDrop"]
| +-assemblyFile.operation [183, 186]["equ"]
| | +-assemblyFile.opcode [183, 186]["equ"]
| +-assemblyFile.mode [189, 189][""]
| +-assemblyFile.expr [189, 192]["382", ""]
| +-assemblyFile.term [189, 192]["382"]
| | +-assemblyFile.number [189, 192]["382"]
| | +-assemblyFile.whole_number [189, 192]["382"]
| +-assemblyFile.tail [192, 192][""]
+-assemblyFile.line [194, 216]["bDist", "equ", "", "3250", ""]
| +-assemblyFile.instruction [198, 216]["bDist", "equ", "", "3250", ""]
| +-assemblyFile.label_list [198, 205]["bDist"]
| | +-assemblyFile.label [198, 203]["bDist"]
| +-assemblyFile.operation [205, 208]["equ"]
| | +-assemblyFile.opcode [205, 208]["equ"]
| +-assemblyFile.mode [211, 211][""]
| +-assemblyFile.expr [211, 215]["3250", ""]
| +-assemblyFile.term [211, 215]["3250"]
| | +-assemblyFile.number [211, 215]["3250"]
| | +-assemblyFile.whole_number [211, 215]["3250"]
| +-assemblyFile.tail [215, 215][""]
+-assemblyFile.line [216, 236]["bcOff", "equ", "", "51", ""]
| +-assemblyFile.instruction [220, 236]["bcOff", "equ", "", "51", ""]
| +-assemblyFile.label_list [220, 227]["bcOff"]
| | +-assemblyFile.label [220, 225]["bcOff"]
| +-assemblyFile.operation [227, 230]["equ"]
| | +-assemblyFile.opcode [227, 230]["equ"]
| +-assemblyFile.mode [233, 233][""]
| +-assemblyFile.expr [233, 235]["51", ""]
| +-assemblyFile.term [233, 235]["51"]
| | +-assemblyFile.number [233, 235]["51"]
| | +-assemblyFile.whole_number [233, 235]["51"]
| +-assemblyFile.tail [235, 235][""]
+-assemblyFile.line [236, 256]["bgOff", "equ", "", "17", ""]
| +-assemblyFile.instruction [240, 256]["bgOff", "equ", "", "17", ""]
| +-assemblyFile.label_list [240, 247]["bgOff"]
| | +-assemblyFile.label [240, 245]["bgOff"]
| +-assemblyFile.operation [247, 250]["equ"]
| | +-assemblyFile.opcode [247, 250]["equ"]
| +-assemblyFile.mode [253, 253][""]
| +-assemblyFile.expr [253, 255]["17", ""]
| +-assemblyFile.term [253, 255]["17"]
| | +-assemblyFile.number [253, 255]["17"]
| | +-assemblyFile.whole_number [253, 255]["17"]
| +-assemblyFile.tail [255, 255][""]
+-assemblyFile.line [257, 292]["bRun", "equ", "", "(", "bHit", "-", "bInc", "*", "bDrop", "", ")", ""]
| +-assemblyFile.instruction [261, 292]["bRun", "equ", "", "(", "bHit", "-", "bInc", "*", "bDrop", "", ")", ""]
| +-assemblyFile.label_list [261, 268]["bRun"]
| | +-assemblyFile.label [261, 265]["bRun"]
| +-assemblyFile.operation [268, 271]["equ"]
| | +-assemblyFile.opcode [268, 271]["equ"]
| +-assemblyFile.mode [274, 274][""]
| +-assemblyFile.expr [274, 291]["(", "bHit", "-", "bInc", "*", "bDrop", "", ")", ""]
| +-assemblyFile.expr [275, 290]["bHit", "-", "bInc", "*", "bDrop", ""]
| | +-assemblyFile.term [275, 279]["bHit"]
| | | +-assemblyFile.label [275, 279]["bHit"]
| | +-assemblyFile.tail [279, 290]["-", "bInc", "*", "bDrop", ""]
| | +-assemblyFile.expr [280, 290]["bInc", "*", "bDrop", ""]
| | +-assemblyFile.term [280, 284]["bInc"]
| | | +-assemblyFile.label [280, 284]["bInc"]
| | +-assemblyFile.tail [284, 290]["*", "bDrop", ""]
| | +-assemblyFile.expr [285, 290]["bDrop", ""]
| | +-assemblyFile.term [285, 290]["bDrop"]
| | | +-assemblyFile.label [285, 290]["bDrop"]
| | +-assemblyFile.tail [290, 290][""]
| +-assemblyFile.tail [291, 291][""]
+-assemblyFile.line [292, 322]["bGate", "equ", "", "(", "bClr", "-", "bgOff", "", ")", ""]
| +-assemblyFile.instruction [296, 322]["bGate", "equ", "", "(", "bClr", "-", "bgOff", "", ")", ""]
| +-assemblyFile.label_list [296, 303]["bGate"]
| | +-assemblyFile.label [296, 301]["bGate"]
| +-assemblyFile.operation [303, 306]["equ"]
| | +-assemblyFile.opcode [303, 306]["equ"]
| +-assemblyFile.mode [309, 309][""]
| +-assemblyFile.expr [309, 321]["(", "bClr", "-", "bgOff", "", ")", ""]
| +-assemblyFile.expr [310, 320]["bClr", "-", "bgOff", ""]
| | +-assemblyFile.term [310, 314]["bClr"]
| | | +-assemblyFile.label [310, 314]["bClr"]
| | +-assemblyFile.tail [314, 320]["-", "bgOff", ""]
| | +-assemblyFile.expr [315, 320]["bgOff", ""]
| | +-assemblyFile.term [315, 320]["bgOff"]
| | | +-assemblyFile.label [315, 320]["bgOff"]
| | +-assemblyFile.tail [320, 320][""]
| +-assemblyFile.tail [321, 321][""]
+-assemblyFile.line [322, 355]["bSpl", "equ", "", "(", "bHit", "-", "2", "*", "bInc", "", ")", "+", "1", ""]
| +-assemblyFile.instruction [326, 355]["bSpl", "equ", "", "(", "bHit", "-", "2", "*", "bInc", "", ")", "+", "1", ""]
| +-assemblyFile.label_list [326, 333]["bSpl"]
| | +-assemblyFile.label [326, 330]["bSpl"]
| +-assemblyFile.operation [333, 336]["equ"]
| | +-assemblyFile.opcode [333, 336]["equ"]
| +-assemblyFile.mode [339, 339][""]
| +-assemblyFile.expr [339, 354]["(", "bHit", "-", "2", "*", "bInc", "", ")", "+", "1", ""]
| +-assemblyFile.expr [340, 351]["bHit", "-", "2", "*", "bInc", ""]
| | +-assemblyFile.term [340, 344]["bHit"]
| | | +-assemblyFile.label [340, 344]["bHit"]
| | +-assemblyFile.tail [344, 351]["-", "2", "*", "bInc", ""]
| | +-assemblyFile.expr [345, 351]["2", "*", "bInc", ""]
| | +-assemblyFile.term [345, 346]["2"]
| | | +-assemblyFile.number [345, 346]["2"]
| | | +-assemblyFile.whole_number [345, 346]["2"]
| | +-assemblyFile.tail [346, 351]["*", "bInc", ""]
| | +-assemblyFile.expr [347, 351]["bInc", ""]
| | +-assemblyFile.term [347, 351]["bInc"]
| | | +-assemblyFile.label [347, 351]["bInc"]
| | +-assemblyFile.tail [351, 351][""]
| +-assemblyFile.tail [352, 354]["+", "1", ""]
| +-assemblyFile.expr [353, 354]["1", ""]
| +-assemblyFile.term [353, 354]["1"]
| | +-assemblyFile.number [353, 354]["1"]
| | +-assemblyFile.whole_number [353, 354]["1"]
| +-assemblyFile.tail [354, 354][""]
+-assemblyFile.line [355, 388]["bJmp", "equ", "", "(", "bHit", "-", "2", "*", "bInc", "", ")", "-", "1", ""]
| +-assemblyFile.instruction [359, 388]["bJmp", "equ", "", "(", "bHit", "-", "2", "*", "bInc", "", ")", "-", "1", ""]
| +-assemblyFile.label_list [359, 366]["bJmp"]
| | +-assemblyFile.label [359, 363]["bJmp"]
| +-assemblyFile.operation [366, 369]["equ"]
| | +-assemblyFile.opcode [366, 369]["equ"]
| +-assemblyFile.mode [372, 372][""]
| +-assemblyFile.expr [372, 387]["(", "bHit", "-", "2", "*", "bInc", "", ")", "-", "1", ""]
| +-assemblyFile.expr [373, 384]["bHit", "-", "2", "*", "bInc", ""]
| | +-assemblyFile.term [373, 377]["bHit"]
| | | +-assemblyFile.label [373, 377]["bHit"]
| | +-assemblyFile.tail [377, 384]["-", "2", "*", "bInc", ""]
| | +-assemblyFile.expr [378, 384]["2", "*", "bInc", ""]
| | +-assemblyFile.term [378, 379]["2"]
| | | +-assemblyFile.number [378, 379]["2"]
| | | +-assemblyFile.whole_number [378, 379]["2"]
| | +-assemblyFile.tail [379, 384]["*", "bInc", ""]
| | +-assemblyFile.expr [380, 384]["bInc", ""]
| | +-assemblyFile.term [380, 384]["bInc"]
| | | +-assemblyFile.label [380, 384]["bInc"]
| | +-assemblyFile.tail [384, 384][""]
| +-assemblyFile.tail [385, 387]["-", "1", ""]
| +-assemblyFile.expr [386, 387]["1", ""]
| +-assemblyFile.term [386, 387]["1"]
| | +-assemblyFile.number [386, 387]["1"]
| | +-assemblyFile.whole_number [386, 387]["1"]
| +-assemblyFile.tail [387, 387][""]
+-assemblyFile.line [388, 413]["bInc", "equ", "", "3", "*", "bStep", ""]
| +-assemblyFile.instruction [392, 413]["bInc", "equ", "", "3", "*", "bStep", ""]
| +-assemblyFile.label_list [392, 399]["bInc"]
| | +-assemblyFile.label [392, 396]["bInc"]
| +-assemblyFile.operation [399, 402]["equ"]
| | +-assemblyFile.opcode [399, 402]["equ"]
| +-assemblyFile.mode [405, 405][""]
| +-assemblyFile.expr [405, 412]["3", "*", "bStep", ""]
| +-assemblyFile.term [405, 406]["3"]
| | +-assemblyFile.number [405, 406]["3"]
| | +-assemblyFile.whole_number [405, 406]["3"]
| +-assemblyFile.tail [406, 412]["*", "bStep", ""]
| +-assemblyFile.expr [407, 412]["bStep", ""]
| +-assemblyFile.term [407, 412]["bStep"]
| | +-assemblyFile.label [407, 412]["bStep"]
| +-assemblyFile.tail [412, 412][""]
+-assemblyFile.line [414, 451]["bStart", "mov", "i", "{", "0", "", ",", "#", "0", ""]
| +-assemblyFile.instruction [418, 451]["bStart", "mov", "i", "{", "0", "", ",", "#", "0", ""]
| +-assemblyFile.label_list [418, 425]["bStart"]
| | +-assemblyFile.label [418, 424]["bStart"]
| +-assemblyFile.operation [425, 430]["mov", "i"]
| | +-assemblyFile.opcode [425, 428]["mov"]
| | +-assemblyFile.modifier [429, 430]["i"]
| +-assemblyFile.mode [431, 432]["{"]
| +-assemblyFile.expr [432, 433]["0", ""]
| | +-assemblyFile.term [432, 433]["0"]
| | | +-assemblyFile.number [432, 433]["0"]
| | | +-assemblyFile.whole_number [432, 433]["0"]
| | +-assemblyFile.tail [433, 433][""]
| +-assemblyFile.mode [448, 449]["#"]
| +-assemblyFile.expr [449, 450]["0", ""]
| +-assemblyFile.term [449, 450]["0"]
| | +-assemblyFile.number [449, 450]["0"]
| | +-assemblyFile.whole_number [449, 450]["0"]
| +-assemblyFile.tail [450, 450][""]
+-assemblyFile.line [451, 491]["bLoop", "mov", "", "bSpl", "", ",", "<", "bPtr", ""]
| +-assemblyFile.instruction [455, 491]["bLoop", "mov", "", "bSpl", "", ",", "<", "bPtr", ""]
| +-assemblyFile.label_list [455, 462]["bLoop"]
| | +-assemblyFile.label [455, 460]["bLoop"]
| +-assemblyFile.operation [462, 465]["mov"]
| | +-assemblyFile.opcode [462, 465]["mov"]
| +-assemblyFile.mode [468, 468][""]
| +-assemblyFile.expr [468, 472]["bSpl", ""]
| | +-assemblyFile.term [468, 472]["bSpl"]
| | | +-assemblyFile.label [468, 472]["bSpl"]
| | +-assemblyFile.tail [472, 472][""]
| +-assemblyFile.mode [485, 486]["<"]
| +-assemblyFile.expr [486, 490]["bPtr", ""]
| +-assemblyFile.term [486, 490]["bPtr"]
| | +-assemblyFile.label [486, 490]["bPtr"]
| +-assemblyFile.tail [490, 490][""]
+-assemblyFile.line [491, 531]["mov", "", "bJmp", "", ",", "*", "bPtr", ""]
| +-assemblyFile.instruction [502, 531]["mov", "", "bJmp", "", ",", "*", "bPtr", ""]
| +-assemblyFile.operation [502, 505]["mov"]
| | +-assemblyFile.opcode [502, 505]["mov"]
| +-assemblyFile.mode [508, 508][""]
| +-assemblyFile.expr [508, 512]["bJmp", ""]
| | +-assemblyFile.term [508, 512]["bJmp"]
| | | +-assemblyFile.label [508, 512]["bJmp"]
| | +-assemblyFile.tail [512, 512][""]
| +-assemblyFile.mode [525, 526]["*"]
| +-assemblyFile.expr [526, 530]["bPtr", ""]
| +-assemblyFile.term [526, 530]["bPtr"]
| | +-assemblyFile.label [526, 530]["bPtr"]
| +-assemblyFile.tail [530, 530][""]
+-assemblyFile.line [531, 579]["bPtr", "mov", "", "bRun", "-", "bStep", "", ",", "@", "bRun", "+", "bStep", "+", "1", ""]
| +-assemblyFile.instruction [535, 579]["bPtr", "mov", "", "bRun", "-", "bStep", "", ",", "@", "bRun", "+", "bStep", "+", "1", ""]
| +-assemblyFile.label_list [535, 542]["bPtr"]
| | +-assemblyFile.label [535, 539]["bPtr"]
| +-assemblyFile.operation [542, 545]["mov"]
| | +-assemblyFile.opcode [542, 545]["mov"]
| +-assemblyFile.mode [548, 548][""]
| +-assemblyFile.expr [548, 558]["bRun", "-", "bStep", ""]
| | +-assemblyFile.term [548, 552]["bRun"]
| | | +-assemblyFile.label [548, 552]["bRun"]
| | +-assemblyFile.tail [552, 558]["-", "bStep", ""]
| | +-assemblyFile.expr [553, 558]["bStep", ""]
| | +-assemblyFile.term [553, 558]["bStep"]
| | | +-assemblyFile.label [553, 558]["bStep"]
| | +-assemblyFile.tail [558, 558][""]
| +-assemblyFile.mode [565, 566]["@"]
| +-assemblyFile.expr [566, 578]["bRun", "+", "bStep", "+", "1", ""]
| +-assemblyFile.term [566, 570]["bRun"]
| | +-assemblyFile.label [566, 570]["bRun"]
| +-assemblyFile.tail [570, 578]["+", "bStep", "+", "1", ""]
| +-assemblyFile.expr [571, 578]["bStep", "+", "1", ""]
| +-assemblyFile.term [571, 576]["bStep"]
| | +-assemblyFile.label [571, 576]["bStep"]
| +-assemblyFile.tail [576, 578]["+", "1", ""]
| +-assemblyFile.expr [577, 578]["1", ""]
| +-assemblyFile.term [577, 578]["1"]
| | +-assemblyFile.number [577, 578]["1"]
| | +-assemblyFile.whole_number [577, 578]["1"]
| +-assemblyFile.tail [578, 578][""]
+-assemblyFile.line [579, 618]["bHit", "add", "*", "bEvac", "", ",", "", "bPtr", ""]
| +-assemblyFile.instruction [583, 618]["bHit", "add", "*", "bEvac", "", ",", "", "bPtr", ""]
| +-assemblyFile.label_list [583, 590]["bHit"]
| | +-assemblyFile.label [583, 587]["bHit"]
| +-assemblyFile.operation [590, 593]["add"]
| | +-assemblyFile.opcode [590, 593]["add"]
| +-assemblyFile.mode [596, 597]["*"]
| +-assemblyFile.expr [597, 602]["bEvac", ""]
| | +-assemblyFile.term [597, 602]["bEvac"]
| | | +-assemblyFile.label [597, 602]["bEvac"]
| | +-assemblyFile.tail [602, 602][""]
| +-assemblyFile.mode [613, 613][""]
| +-assemblyFile.expr [613, 617]["bPtr", ""]
| +-assemblyFile.term [613, 617]["bPtr"]
| | +-assemblyFile.label [613, 617]["bPtr"]
| +-assemblyFile.tail [617, 617][""]
+-assemblyFile.line [618, 658]["mov", ">", "bJmp", "", ",", "@", "bPtr", ""]
| +-assemblyFile.instruction [629, 658]["mov", ">", "bJmp", "", ",", "@", "bPtr", ""]
| +-assemblyFile.operation [629, 632]["mov"]
| | +-assemblyFile.opcode [629, 632]["mov"]
| +-assemblyFile.mode [635, 636][">"]
| +-assemblyFile.expr [636, 640]["bJmp", ""]
| | +-assemblyFile.term [636, 640]["bJmp"]
| | | +-assemblyFile.label [636, 640]["bJmp"]
| | +-assemblyFile.tail [640, 640][""]
| +-assemblyFile.mode [652, 653]["@"]
| +-assemblyFile.expr [653, 657]["bPtr", ""]
| +-assemblyFile.term [653, 657]["bPtr"]
| | +-assemblyFile.label [653, 657]["bPtr"]
| +-assemblyFile.tail [657, 657][""]
+-assemblyFile.line [658, 698]["jmz", "a", "", "bLoop", "", ",", "<", "bJmp", ""]
| +-assemblyFile.instruction [669, 698]["jmz", "a", "", "bLoop", "", ",", "<", "bJmp", ""]
| +-assemblyFile.operation [669, 674]["jmz", "a"]
| | +-assemblyFile.opcode [669, 672]["jmz"]
| | +-assemblyFile.modifier [673, 674]["a"]
| +-assemblyFile.mode [675, 675][""]
| +-assemblyFile.expr [675, 680]["bLoop", ""]
| | +-assemblyFile.term [675, 680]["bLoop"]
| | | +-assemblyFile.label [675, 680]["bLoop"]
| | +-assemblyFile.tail [680, 680][""]
| +-assemblyFile.mode [692, 693]["<"]
| +-assemblyFile.expr [693, 697]["bJmp", ""]
| +-assemblyFile.term [693, 697]["bJmp"]
| | +-assemblyFile.label [693, 697]["bJmp"]
| +-assemblyFile.tail [697, 697][""]
+-assemblyFile.EOF (failure)
+-negLookahead!(any) failure at line 29, col 0, after " , <bJmp
" expected anything but " ", but got " bEvac "
No segfault, but a missing :WS?
maybe?
well don't I look silly. in my debugging attempts I was using an old grammar by accident. that said, I am still intermittently getting warnings about unreachable code. I have turned off generating errors for warnings for now.
OK. I suppose you could get unreachable code if your grammar contains a rule that is nowhere used in the rest of the grammar (and it's not the first one).
it seems the unreachability-ness is related to the if(__ctfe) statements, which would make sense I guess.
Ah. Food for the forum?
On Thu, Feb 4, 2016 at 11:33 PM, Bastiaan Veelo notifications@github.com wrote
Doxin, if you ever get an 'unreachable statement' warning with a small grammar, I'm interested in diving in the generated source code.
depends on your definition of small. this grammar throws two such warnings
given this grammar:
and this input:
I get a segfault. using gdb to inspect the stack trace doesn't do me good since the trace is thousands of frames deep, and I'm having massive trouble reading the pegged source to figure out what is going on.
I suspect the problem lies in expr and it's related rules, but I can't be sure. is there any better way to debug this?
do note that simpler inputs don't segfault.