Hacker News new | ask | show | jobs
by marvy 3304 days ago
Obviously you don't want silent autocorrect. You use this to get suggested corrections when things don't compile.
2 comments

> You use this to get suggested corrections when things don't compile.

It repeatedly says that the aim is to fix errors. Assuming, however, that it is intended to give better error messages, here is the output of Clang on the input C program given as an example:

  $ cc gupta.c
  gupta.c:3:5: warning: incompatible redeclaration of library function 'pow'
      [-Wincompatible-library-redeclaration]
  int pow(int a, int b);
    ^
  gupta.c:3:5: note: 'pow' is a builtin with type 'double (double, double)'
  gupta.c:14:23: error: function definition is not allowed here
  int pow(int a, int b){
                      ^
  gupta.c:18:14: error: expected ';' at end of declaration
  return res;}
              ^
              ;
  gupta.c:18:14: error: expected '}'
  gupta.c:4:11: note: to match this '{'
  int main(){
            ^
  1 warning and 3 errors generated.
It identifies the problematic line of the program code better than gcc. The function declaration within main is not legal. I tried this with the gcc compiler and did not get the error above. Running "indent" on the code would have revealed the problems:

$ indent < gupta.c

/INDENT Error@18: Stuff missing from end of file */

A simple count of braces, { and }, would also have revealed the problem.

So you're saying this whole paper could have been avoided if they just used clang. And it seems you're right.
A simple way to get suggestions is to take your finite state machine (that consumes tokens) to a special error state and just analyze what got you there. You'll pick up quite a lot of errors.