COMMON COMPILATION LOGIC

Back to:
index

Before compiler begins to analyse the text, it previously does several operations:

  • check line number in Your program and their length
    If something wrong - show error message.

  • create the copy of our Pascal program text
    Further compilers works only with this copy

  • replace all comments by spaces (including "{" and "}")
    "ComPas" doesn't delete comments to maintain the congruence between original program and its copy. This gives possibility to show error position correctly.

  • translate all letters to upper-case
    This operation skips all texts between ' '
Only after it translation begins.

Further process can finish successfully when there are no errors in the program. But often something is wrong, so compiler fixes the reason of error, shows error message and compilation terminates. Every compilation step is checked for error absence, so I will not write about it in most cases.


As you know, Pascal program consists from 3 parts: title, descriptions and executable part (operators).

The most simple is the first part - title. To process it, "ComPas" searches for word PROGRAM and then skips all symbols until ";" . As you see, name is not checked.

The next part is a descriptions of constant, variables etc. Processing it, compiler fills special tables to remember names, types and values of constants (for variables address is used). Read separate page about this topic.

The last and the most interesting are operators. Only this part generates executable code in processor commands. "COMPAS" does cyclic analysis of operators, trying to translate them.

After every operator compiler checks END or ;. END. stop the process of translation, otherwise cycle of operator translation repeats.

How "COMPAS" recognizes an operator? At first it checks the following reserved words

  • IF
  • WHILE
  • REPEAT
  • FOR
  • WRITE
  • READ
or the name of our procedure. After conjunction with one of these words, "COMPAS" jumps to correspondent analysis of conditional operator, one of three cycles (WHILE, REPEAT and FOR) or procedure call. If nothing from this list is found, it's remain to suppose, that operator under consideration is assignment.

Back to:
index top