Professional Documents
Culture Documents
R162217 PRINCIPLES OF
PROGRAMMING LANGUAGES
OBJECTIVES:
UNIT I
SYNTAX AND SEMANTICS
Machine Language
The high level languages use the English words such as OPEN, LIST,
PRINT, which might stand for an array of instructions. These commands
are entered via keyboard or from a programme in a storage device.
Historical Landmarks
• Programming has its origin in the 19th century, when the first
“programmable” looms and player piano scrolls were developed.
• This followed the punch cards encoded data in 20th century that used to
direct the mechanical processing. In the 1930s and early 1940s lambda
calculus remained the influential in language design.
• The decade of 1940s has many landmarks to its credit in the initial
development of modern computers and programming languages.
https://www.ulektz.com/ulektz/eReader/sandwich/index.php?book_id=UDE2MjY1&file_id=NDYyMw==&file_name=PRINCIPLES%20OF%20PROGR… 2/11
2/17/2018 Book
https://www.ulektz.com/ulektz/eReader/sandwich/index.php?book_id=UDE2MjY1&file_id=NDYyMw==&file_name=PRINCIPLES%20OF%20PROGR… 3/11
2/17/2018 Book
https://www.ulektz.com/ulektz/eReader/sandwich/index.php?book_id=UDE2MjY1&file_id=NDYyMw==&file_name=PRINCIPLES%20OF%20PROGR… 4/11
2/17/2018 Book
(Or)
https://www.ulektz.com/ulektz/eReader/sandwich/index.php?book_id=UDE2MjY1&file_id=NDYyMw==&file_name=PRINCIPLES%20OF%20PROGR… 5/11
2/17/2018 Book
Lexemes Tokens
Index Identifier
= equal_sing
2 int_literal
* mult_op
Count identifier
+ plus_op
17 int_literal
; semicolon
Language Recognizers
Language Generators
Non terminals are syntactic variables that denote sets of strings. The non
terminals define the sets of strings that help to define the language
generated by the grammar. A set of tokens, known as terminal symbols
(Σ). Terminals are the basic symbols from which strings are formed.
Describing Lists
<ident_list> → ident
https://www.ulektz.com/ulektz/eReader/sandwich/index.php?book_id=UDE2MjY1&file_id=NDYyMw==&file_name=PRINCIPLES%20OF%20PROGR… 7/11
2/17/2018 Book
| ident, <ident_list>
An example grammar:
<program> → <stmts>
<var> → a | b | c | d
a = b + const
⇒ <var> = <expr>
⇒ a = <expr>
⇒ a = <term> + <term>
⇒ a = <var> + <term>
https://www.ulektz.com/ulektz/eReader/sandwich/index.php?book_id=UDE2MjY1&file_id=NDYyMw==&file_name=PRINCIPLES%20OF%20PROGR… 8/11
2/17/2018 Book
⇒ a = b + <term>
⇒ a = b + const
Parse Trees
Hierarchical structures of the language are called parse trees. A parse tree
for the simple statement A = B + const.
Ambiguity
Example:
E→E+E
E→E–E
https://www.ulektz.com/ulektz/eReader/sandwich/index.php?book_id=UDE2MjY1&file_id=NDYyMw==&file_name=PRINCIPLES%20OF%20PROGR… 9/11
2/17/2018 Book
E → id
For the string id + id – id, the above grammar generates two parse trees:
Associativity
Example
id op id op id
(id op id) op id
https://www.ulektz.com/ulektz/eReader/sandwich/index.php?book_id=UDE2MjY1&file_id=NDYyMw==&file_name=PRINCIPLES%20OF%20PROGR… 10/11
2/17/2018 Book
id op (id op id)
Precedence
2 + (3 * 4)
https://www.ulektz.com/ulektz/eReader/sandwich/index.php?book_id=UDE2MjY1&file_id=NDYyMw==&file_name=PRINCIPLES%20OF%20PROGR… 11/11