Introduction To Programming Languages and Compilation
Introduction To Programming Languages and Compilation
Compilation
An Introduction
[email protected]
– This is a sentence.
• Lexical analyzer divides program text
into“words”or “tokens”
If x == y then z = 1; else z = 2;
• Diagrammed:
• Even worse:
Jack said Jack left his assignment at home?
– How many Jacks are there?
– Which one left the assignment?
CSC 340 Prof. Khalil El Hindi 9
Semantic Analysis in Programming
• Semantic Analysis in Programming
{
int Jack = 3;
{
int Jack = 4;
cout << Jack;
}
}
• Example:
Jack left her homework at home.
• A “type mismatch” between her and Jack; we
know they are different people (Presumably
Jack is male).
CSC 340 Prof. Khalil El Hindi 11
Optimization
• No strong counterpart in English, but akin to
editing
– You can express the same idea using fewer words
• Expressivity
– A set of relatively convenient ways of specifying operations
– Strength and number of operators and predefined functions
Simplicity/orthogonality • • •
Control structures • • •
Syntax design • • •
Expressivity • •
Type checking •
Exception handling •
Restricted aliasing •
• Pure Interpretation
– Programs are interpreted by another program known as an interpreter