{"action":"closed","issue":{"url":"https://api.github.com/repos/PhilippeSigaud/Pegged/issues/182","repository_url":"https://api.github.com/repos/PhilippeSigaud/Pegged","labels_url":"https://api.github.com/repos/PhilippeSigaud/Pegged/issues/182/labels{/name}","comments_url":"https://api.github.com/repos/PhilippeSigaud/Pegged/issues/182/comments","events_url":"https://api.github.com/repos/PhilippeSigaud/Pegged/issues/182/events","html_url":"https://github.com/PhilippeSigaud/Pegged/issues/182","id":131477694,"number":182,"title":"segfault on parsing some inputs","user":{"login":"SuperDoxin","id":377239,"avatar_url":"https://avatars.githubusercontent.com/u/377239?v=3","gravatar_id":"","url":"https://api.github.com/users/SuperDoxin","html_url":"https://github.com/SuperDoxin","followers_url":"https://api.github.com/users/SuperDoxin/followers","following_url":"https://api.github.com/users/SuperDoxin/following{/other_user}","gists_url":"https://api.github.com/users/SuperDoxin/gists{/gist_id}","starred_url":"https://api.github.com/users/SuperDoxin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SuperDoxin/subscriptions","organizations_url":"https://api.github.com/users/SuperDoxin/orgs","repos_url":"https://api.github.com/users/SuperDoxin/repos","events_url":"https://api.github.com/users/SuperDoxin/events{/privacy}","received_events_url":"https://api.github.com/users/SuperDoxin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-02-04T21:21:30Z","updated_at":"2016-02-04T22:04:29Z","closed_at":"2016-02-04T22:04:29Z","body":"given this grammar:\r\n\r\n    assemblyFile:\r\n        list <- line+ EOF\r\n        line <- :WS? (comment / instruction)\r\n        comment <- :';' ~((!'\\n' .)*) EOL / EOL\r\n        label_list <- (label :WS?)*\r\n        label <- ~(!opcode ([a-zA-Z_] [a-zA-Z0-9_]*))\r\n        operation <- opcode :'.' modifier / opcode\r\n        opcode <~ 'dat' / 'mov' / 'add' /\r\n                  'sub' / 'mul' / 'div' /\r\n                  'mod' / 'jmp' / 'jmz' /\r\n                  'jmn' / 'djn' / 'cmp' /\r\n                  'slt' / 'spl' / 'sne' /\r\n                  'seq' / 'org' / 'equ' / \r\n                  'end'\r\n        modifier <- 'ab' / 'ba' / 'a' / 'b' / 'f' / 'x' / 'i' / eps\r\n        mode <- '#' / '$' / '@' / '<' / '>' / '{' / '}' / '*' / eps\r\n        expr <- '(' expr ')' tail / term tail\r\n        tail <- '%' expr / '/' expr / '*' expr / '-' expr / '+' expr / eps\r\n        term <- label / number / expr\r\n        number <- whole_number / signed_integer\r\n        signed_integer <~ '+' whole_number / '-' whole_number\r\n        whole_number <~ [0-9]+\r\n        WS <- ' '+\r\n        EOL <- :'\\n' / EOF\r\n        EOF <- !.\r\n        \r\n        instruction <- label_list :WS? operation :WS? mode :WS? expr :WS? ',' :WS? mode :WS? expr :WS? comment / \r\n                       label_list :WS? operation :WS? mode :WS? expr :WS? comment \r\n\r\nand this input:\r\n\r\n    ;redcode-94\r\n    ;name Behemot\r\n    ;author Michal Janeczek\r\n    ;strategy MiniQ^3 -> Stun bomber\r\n    ;assert CORESIZE==8000\r\n\r\n           org   qGo\r\n\r\n    bStep  equ   2223\r\n    bDrop  equ   382\r\n\r\n    bDist  equ   3250\r\n    bcOff  equ   51\r\n    bgOff  equ   17\r\n\r\n    bRun   equ   (bHit-bInc*bDrop)\r\n    bGate  equ   (bClr-bgOff)\r\n    bSpl   equ   (bHit-2*bInc)+1\r\n    bJmp   equ   (bHit-2*bInc)-1\r\n    bInc   equ   3*bStep\r\n\r\n    bStart mov.i {0             , #0\r\n    bLoop  mov   bSpl           , <bPtr\r\n           mov   bJmp           , *bPtr\r\n    bPtr   mov   bRun-bStep     , @bRun+bStep+1\r\n    bHit   add   *bEvac         , bPtr\r\n           mov   >bJmp          , @bPtr\r\n           jmz.a bLoop          , <bJmp\r\n    bEvac  jmp   -bcOff         , <1-bcOff-bgOff\r\n\r\n    bGo    spl   1              , bWipe+5\r\n    bcDst  spl   1              , bDist+4+bEvac-bcOff\r\n           mov   <bGo           , <bbDst\r\n           mov   <bGo           , <bcDst\r\n           mov   <bBoot         , {bBoot\r\n           mov   <bBoot         , {bBoot\r\n    bbDst  mov.i bGo            , #bDist+2+bSpl\r\n    bBoot  jmp   >bDist+bEvac+1 , bEvac+1\r\n\r\n           spl   #bInc          , <bInc+1\r\n    bClr   mov   bWipe          , >bGate\r\n           djn.f bClr           , >bGate\r\n    bWipe  dat   <2667          , 2-bGate\r\n\r\n           jmp   bStep          , {1\r\n           mov   @0             , }-1\r\n           spl   #2             , -bStep\r\n\r\n           for   35\r\n           dat   0              , 0\r\n           rof\r\n\r\n    qf     equ   qKil\r\n    qs     equ   222\r\n    qd     equ   322\r\n    qi     equ   7\r\n    qr     equ   11\r\n\r\n    qGo    seq   qd+qf+qs       , qf+qs\r\n           jmp   qSki           , {qd+qf+qs+qi\r\n           seq   qd+qf+6*qs     , qf+6*qs\r\n           jmp   qFas           , {qd+qf+6*qs+qi\r\n           seq   qd+qf+5*qs     , qf+5*qs\r\n           jmp   qFas           , <qBmb\r\n           seq   qd+qf+7*qs     , qf+7*qs\r\n           jmp   qFas           , >qBmb\r\n           seq   qd+qf+9*qs     , qf+9*qs\r\n           djn   qFas           , {qFas\r\n           seq   qd+qf+10*qs    , qf+10*qs\r\n           jmp   qFas           , {qFas\r\n           seq   qd+qf+3*qs     , qf+3*qs\r\n           jmp   >qFas          , {qd+qf+3*qs+qi\r\n           seq   qd+qf+2*qs     , qf+2*qs\r\n           jmp   >qFas          , {qSlo\r\n           seq   qd+qf+4*qs     , qf+4*qs\r\n           jmp   >qFas          , }qSlo\r\n           seq   qd+qf+12*qs    , qf+12*qs\r\n           jmp   qSlo           , {qSlo\r\n           seq   qd+qf+15*qs    , qf+15*qs\r\n           jmp   qSlo           , <qBmb\r\n           seq   qd+qf+21*qs    , qf+21*qs\r\n           jmp   qSlo           , >qBmb\r\n           seq   qd+qf+24*qs    , qf+24*qs\r\n           jmp   qSlo           , }qSlo\r\n           seq   qd+qf+27*qs    , qf+27*qs\r\n           djn   qSlo           , {qFas\r\n           seq   qd+qf+30*qs    , qf+30*qs\r\n           jmp   qSlo           , {qFas\r\n           sne   qd+qf+18*qs    , qf+18*qs\r\n           jmz.f bGo            , qd+qf+18*qs-10\r\n    qSlo   mul.ab #3            , qKil\r\n    qFas   mul.b qBmb           , @qSlo\r\n    qSki   sne   >3456          , @qKil\r\n           add   #qd            , qKil\r\n    qLoo   mov   qBmb           , @qKil\r\n    qKil   mov   qBmb           , *qs\r\n           sub   #qi            , qKil\r\n           djn   qLoo           , #qr\r\n           jmp   bGo            , >10\r\n    qBmb   dat   {qi*qr-10      , {6\r\n\r\n           end\r\n\r\nI 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.\r\n\r\nI 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?\r\n\r\ndo note that simpler inputs don't segfault."}}