Ignoring errors in yacc/lex

前端 未结 1 616
温柔的废话
温柔的废话 2021-01-28 10:09

I\'m new to yacc/lex and I\'m working on a parser that was written by someone else. I notice that when an undefined token is found, the parser returns an error and stops. Is the

1条回答
  •  南方客
    南方客 (楼主)
    2021-01-28 10:55

    just add a rule that looks like

    . {
      // do nothing
    }
    

    at the bottom of all of your rules, and it will just ignore everything it comes across that doesn't fit any of the previous rules.

    Edit: if you have multiple states, then a catch-all that works in any state would then look like:

    <*>. {
    
    }
    

    0 讨论(0)
提交回复
热议问题