M1-MAIN
M1-MAIN
LANGUAGES
Module 1
INTRODUCTION TO
LANGUAGES
What makes a language successful?
• easy to learn (BASIC, Pascal, LOGO, Scheme)
• easy to express things, easy use once fluent, "powerful” (C,
Common Lisp, APL, Algol-68, Perl)
• easy to implement (BASIC, Forth)
• possible to compile to very good (fast/small) code (Fortran)
• backing of a powerful sponsor (COBOL, PL/1, Ada, Visual
Basic)
• wide dissemination at minimal cost (Pascal, Turing, Java)
Why do we have programming languages? What is a
language for?
• way of thinking -- way of expressing algorithms
• languages from the user's point of view
• abstraction of virtual machine -- way of specifying
what you want
• the hardware to do without getting down into the bits
• languages from the implementor's point of view
Help you choose a language.
Compilation
• Better performance
Most language implementations include a mixture of
both compilation and interpretation
Note that compilation does NOT have to produce machine
language for some sort of hardware
Compilation is translation from one language into another,
with full analysis of the meaning of the input
Compilation entails semantic understanding of what is being
processed;
A pre-processor will often let errors through. A compiler
hides further steps; a pre-processor does not
Implementation strategies:
• Preprocessor
• Looks for compiler directives (e.g., #include )
• Removes comments and white space
• Groups characters into tokens (keywords, identifiers,
numbers, symbols)
• Identifies higher-level syntactic structures (loops,
subroutines)
Implementation strategies:
INTERMEDIATE
CODE
LEXICAL GENERATION
ANALYSIS
CODE
OPTIMIZATION
SYNTAX
ANALYSIS
TARGET CODE
GENERATION
SEMANTIC
ANALYSIS
Overview:
*
Scanning:
• divides the program into "tokens", which are the smallest meaningful
units; this saves time, since character-by-character processing is slow
• we can tune the scanner better if its job is simple; it also saves
complexity (lots of it) for later stages
• you can design a parser to take characters instead of tokens as input,
but it isn't pretty
• scanning is recognition of a regular language, e.g., via DFA
Parsing is recognition of a context-free language, e.g.,
via PDA
• Parsing discovers the "context free" structure of the
program
• Informally, it finds the structure you can describe with
syntax diagrams (the "circles and arrows" in a Pascal
manual)
Lexical Analyzer or Linear Analyzer breaks the sentence into
tokens. For Example following assignment statement :-
position = initial + rate * 60
Would be grouped into the following tokens:
1. The identifier position.
2. The assignment symbol =.
3. The identifier initial.
4. The plus sign.
5. The identifier rate.
6. The multiplication sign.
7. The number 60
SYMBOL TABLE: POSITION Id1 & attributes
https://www.computerhope.com/jargon/p/programming-language.htm
https://www.tutorialspoint.com/compiler_design/compiler_design_syntax_analysis.htm
https://www.cs.iusb.edu/~dvrajito/teach/c311/c311_3_scope.html
https://www.tutorialspoint.com/compiler_design/compiler_design_semantic_analysis.htm
https://cs.lmu.edu/~ray/notes/controlflow/
https://teachcomputerscience.com/programming-data-types/
https://algs4.cs.princeton.edu/12oop/