September 7th, 2012, 07:34 PM
Compiler Error Correction
Good day! I am kind of new to this forum things. Sorry for that. I would just like to ask what are the methods that most compiler use for suggesting corrections for the erroneous part of the code. Is it simply pattern matching or are there any method more complicated than that. Need an answer in this one. Just part of our thesis. Thanks in advance!
September 13th, 2012, 02:58 PM
Compiler errors are detected by the parser, which understands the syntax of the language. It goes a little beyond simple pattern matching though. For example, the language may require the user to declare variable types before they are used (e.g. C, C++, java etc.), in which case, a statement like this:
x = a + b;
might be invalid if the type of x, a or b is unknown when the compiler hits this statement.
Similarly, there could also be violations of syntax rules. For example:
int x = "123";
Some compilers may complain about this because we are assigning a string variable to an int. However, there may be other languages where this is a perfectly valid statement and the string is silently converted to int. It all depends on the language syntax.
Then, you may have symbols which are not valid for a language compiler. For example:
$foo = 1;
This is valid code for perl, but not valid code for a C compiler, because the $ sign is not recognized by C.
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo