Errors are often the bane of a novice programmer's existence. You write what you think is a perfectly fine program, and the compiler chokes on it. Or worse, the compiler compiles it and the operating system chokes on it. Error messages can range anywhere from highly descriptive like "Line 5: Identifier not found" to completely unintelligible like "Access violation at address 0xFFAB23D9". As you become more comfortable with programming, you will develop an intuition about what less-than-helpful error messages probably mean, and modern integrated development environments can generally also point you in the right direction. Here we will cover a few of the most common errors and describe the differences between compiler errors like "Line 5: Identifier not found" and runtime errors like "Access violation at address 0xFFAB23D9".

Compiler errors can be only one of a few problems. First, you may have mangled the syntax of the language you are using which results in a syntax error. For example, try compiling the following program:
program Workspace;
var Str : String;
begin
  Str = 'test';
end.
This program fails with an error on line 4. Before reading on, can you spot the error? The actual compiler error message displayed depends completely on the quality of the compiler. The Free Pascal Compiler reports Line 4: Error: Illegal expression. Unfortunately, this error message is only somewhat helpful. At least we know the line that the error occured on, but the compiler does not tell us exactly what is wrong. On the other hand, Delphi (a commercial Object Pascal compiler) reports Line 4: ':=' expected but '=' found. This is a compiler syntax error. A syntax error is analogous to a gramatical punctuation mistake in an English sentence. The statement above was intended to be an assignment of 'test' to the variable Str, and the way it is written uses the relational equals (=) operator which results in a Boolean expression. This is akin to using a colon in an English sentence when you needed a semicolon. If you did not spot that error on your own, don't worry, the difference between := and = is so subtle that many professional programmers can miss it at first glance.

Now let's consider another common error. See if you can spot this one and then compile it to see what happens:
program Workspace;
var
  Num : Integer;
  Str : String
begin
  Str := 'test'; Num := 12;
end.
This program fails with an error on line 5. A semicolon was left off of the end of line 4. This is once again a compiler syntax error. It is important to remember that if the compiler fails dues to an omitted semicolon, the error is on the previous token. This means that in almost all cases the actual error is on the previous line.

Syntax errors are only one type of compiler error. While syntax deals with actual structure (punctuation, etc), semantics deal with the meaning of what is written. Consider the following code:
program Workspace;
var
  Num : Integer;
begin
  Num := '12';
end.
Since Object Pascal is a strongly typed language, it is semantically nonsensical to assign a string expression to an integer variable. This is similar to a sentence in English that reads "The car swam across the lake." Syntactically this sentence is correct because it has a noun for a subject, a verb expressing action, and a properly constructed prepositional phrase. Semantically, this sentence is obviously nonsensical since cars don't swim (for exceptions see Bond, James). If you try to compile the code above you will get a compiler error something like "Incompatible types." There are of course times that you would want to convert a string into a number, but we will deal with these situations later.

Aside from mismatched types, the other common semantic error is an undeclared identifier. Unlike most languages, Object Pascal is not case sensitive. This means that the identifiers Ident and ident are considered the same. For consistency, if you capitalize an identifier when it is declared you should also capitalize it when you use it. If you misspell the identifier, however, the compiler will certainly complain.
Excercise 2-10.
Identify the compiler errors in the following code (feel free to compile them to find the errors but also try to find them first without any help).
  1. {$APPTYPE CONSOLE}
    program Workspace
    var
      X,Y,Z : Integer;
      Str : String;
    begin
      Str := test;
      X := 3; Y := 5; Z := 7;
      Writeln((12*X+3Y*Z)/(2+Z);
    end;
  2. {$APPTYPE CONSOLE}
    program Workspace;
    var
      X,Y,Str : Srting;
    Begin
      Str := 'test';
      X := '3'; Y := '5; Z := '7';
      Writeln(12*X+Y+Z);
    end.
Although we describe syntax and semantic compiler errors here, it does not actually matter in practice for you to be able to determine which is which (you will be able to do this automatically with experience later on). All that really matters is that you are able to correct a compiler error when one occurs.