CS 3721 Programming Languages
|
The word syntax when used in programming languages refers to the appearance of a program. During the semester we will be giving this vague definition a precise, formal, mathematical (and very useful) definition.
The word semantics in programming languags refers to the meaning of a program. There are formal mathematical ways to define semantics, but these are difficult and have not been as successful as the definitions of syntax, so we will use informal descriptions in this course.
In this course, when applied to a "normal" programming language, compile-time refers to the time and actions taken during compilations, linking, and loading of a program: everything before the actual execution. Run-time refers to the time and actions taking during the execution of a program.
In studying, and particularly in writing compilers, it is very important to keep these two times straight. It turns out that these issues can be confusing, and we will see some of this in the course (on a small scale).
For a program, translation means the process of converting the program to another equivalent form. When we are translating a program in a high-level language into a lower-level language (one that is closer to the machine), one uses the term compilation. In the case of translation, there are two distinct phases:
The term
For real programming languages, there are often
intermediate forms, where partial compilation occurs,
to translate the program into another form, and then
this other form might be interpreted (executed directly).
Whether a language is compiled or interpreted, or
what degree of intermediate form is used, has significant
implications:
Consider a program that calls for an addition, say like:
a = a + b;
Compiler: Here the compiler will output an actual machine language "add" instruction. No add occurs at compile-time. At run-time the add instruction will be executed and the add operation will be carried out. The compiler will decide at compile-time whether it is adding integers or doubles or what, and will output the proper add instruction. At run-time the correct type of add will be hard-wired in so that it can be executed very efficiently.
Interpreter: Here the interpreter will read the statement, will fetch values for a and b, and then will add them, all at the same time. The machine language "add" instruction that is used will be buried in the code for the interpreter program. The interpreter will be prepared to carry out a variety of adds, including for integers and for doubles. During its processing it will decide based on the types of a and b and will select the correct add, all at run-time. Thus far more is going on at run-time here than with a compiler.