Comment by ohazi

6 years ago

Your IDE parser will be unusable if it goes bananas while you're typing the characters needed to get from one fully, correctly parseable state to the next.

It needs to be able to handle:

    printf("hello");

and also:

    prin

and also:

    printf("He

It also needs to be able to autocomplete function signatures that exist below the current line being edited, so the parser can't simply bail out as soon as it reaches the first incomplete or incorrect line.

Isn't that pretty standard for a parser? When was the last time a compiler bailed on the very first error it hit and refused to do anything else?

The solution is to pick synchronisation points to start parsing again, i.e. ; at the end of a statement or } at the end of a block.

  • > When was the last time a compiler bailed on the very first error it hit and refused to do anything else?

    Make still does this. (That's the "Stop." in the famous "* missing separator. Stop.") Many errors in Python still do this.

    As late as 2010 I still saw some major C compilers do this.

    99% of the toy compilers written for DSLs do this, or worse.

    Good error recovery / line blaming is still an active field of development.

    • > Good error recovery / line blaming is still an active field of development.

      True. But let's get terminology straight: that's not a compiler science, that's parsing science. And it's no more compiler science than parsing a natural language is.

      1 reply →

  • How can you be sure that that } is the end of a certain defined block? This most importantly affects the scoping and in many cases it's ambiguous. IDEs do have rich metadata besides from the source code but then parsers should be aware of them.

    • You're ignoring the ; which are sync points.

      > How can you be sure that that } is the end of a certain defined block

      If it's not in a string, what else is it but a typo? If a typo, it fails to parse but so long as it doesn't crash, fine.

      1 reply →