java compiler not give all error at a time

后端 未结 3 2025
执笔经年
执笔经年 2020-12-16 05:30
        System.out.println(\"First eror ::  without semicolon \") // first Error
        System.Out.println(\"This second error :: OUT object not used proper :: \");         


        
相关标签:
3条回答
  • 2020-12-16 05:55

    I'd say this has to do with how compilers often work:

    1. Lexical analysis is performed, where the source code is converted into a sequence of "tokens".
    2. The code is parsed, where the compiler checks whether the tokens meet the language syntax. This is where your first line would fail: every statement in Java must be ended with a semicolon.
    3. Semantic analysis is performed, where the compiler tries to resolve variables, methods, etc. according to the list of known symbols - in Java, this would roughly translate to your classpath.
    4. Code is generated where the source statements are translated either into native bytecode or some intermediate bytecode (the latter is the case for Java).

    If one of the steps fails, the process must stop, because a compiler cannot perform semantic analysis when the code doesn't meet the syntax.

    0 讨论(0)
  • 2020-12-16 05:58

    In java language partially compiler and partially interpreter and In java first compilation happen so compiler should list out all errors

    I'm sorry to disappoint you but that's a non sequitur. The interpreter isn't present at compile time and has nothing whatsoever to do with it.

    The compiler can't determine all your errors at once, if for example some of them are syntax errors which preclude semantic analysis, or a simple semantic error precludes further analysis.

    0 讨论(0)
  • 2020-12-16 06:06

    Your second error is an error only in a Java program, i.e. a string that conforms to the Java syntax. The notion of a non syntactic error in a non-program does not make sense. For the compiler, all strings that are not syntactically correct have the same meaning: none.

    It is like you submit the following "program":

    double x = 5.3; x[42] = 0;
    

    and complain that the compiler does not tell you that a double value cannot be indexed.

    For example, giving this input in a java source file in eclipse gives only "Syntax error on tokens, delete these tokens."

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