Menu

Skipping input in onParseError method

Help
2002-11-09
2002-11-12
  • Nobody/Anonymous

    Hi,
    Quite impressed with you CppCC!

    I know it must be simple but I have not yet figured it out (or it is getting late at night...).

    Once a parse exception has occuredt, which is caught by the 'onParseError' method, how to advance to the next line to enable recovery? I am feeding individual lines from the wrap() method to keep track of which line(s) have problems.

    Tried to 'switchToStream' but the parser still has tokens in its queue. Can't keep on 'consume'ing as there may be invalid tokens after the one that cause the exception.

    Somehow I feel that a token queue somewhere needs to be flushed - can't find it - help....

     
    • Nobody/Anonymous

      You can re-write the grammar rule where you want to do the error-recovery (e.g. the rule that parses one line of input, if you have such a thing) along the lines of:

      (void) parseLineWithRecovery ()
      {
        ( oneLine() <end_of_line> )
        catch (ParseException &ex) { // you get here if  the
                                                  //oneLine rule went wrong
          // so, consume tokens up to and eol
          while (scanner.la()->id != MyScanner::end_of_line)
            scanner.consume();
          // call consume again to skip the eol itself
          scanner.consume()
        }
      }

      The MyScanner::end_of_line constant decl is generated by cppcc (i assumed the scanner is called MyScanner and the eol token is called end_of_line)

      Basically, you can add a catch clause after any expansion if you want to recover when that expansion failed.

      Hope that helps,
      alec.

       
      • Daniel Romano

        Daniel Romano - 2002-11-10

        Thanks - that did it.

        Now on to memory leaks. Tried to compile CppCC with Microsoft VisualC++ (version 7), among many errors I got an "Internal Compiler Error".

        Downloaded MinGW to give it a try ... as soon as I figure out how to set up the configuration files and get a proper compile going...

        Cheers!
        Dan

         
        • Alec Panovici

          Alec Panovici - 2002-11-10

          internal compiler error.. don't know whether to laugh or be sad.... Can you send me the full error log ? Probably this one is related to some earlier errors.

          There are some already-built win bins, if you don't feel like bothering with the compilation stuff you can try those.

           
    • Nobody/Anonymous

      Yes the prebuilts work well here

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.