
Lecture 1 - part 3 - CIS430
Presentation
•
Computers
•
University
•
Medium
Sherif Abdelhamid
Used 4+ times
FREE Resource
26 Slides • 11 Questions
1
ISBN 0-321-49362-1
Chapter 1
Preliminaries
2
Copyright © 2015 Pearson. All rights reserved.
1-2
Chapter 1 Topics
•
Reasons for Studying Concepts of
Programming Languages
•
Programming Domains
•
Language Evaluation Criteria
•
Influences on Language Design
•
Language Categories
•
Language Design Trade-Offs
•
Implementation Methods
•
Programming Environments
3
Copyright © 2015 Pearson. All rights reserved.
1-3
Implementation Methods
• Compilation
– Programs are translated into machine language
– Use: Large commercial applications
• Pure Interpretation
– Programs are interpreted by another program known as
an interpreter
– Use: Small programs or when efficiency is not an issue
• Hybrid Implementation Systems
– A compromise between compilers and pure interpreters
– Use: Small and medium systems when efficiency is not the
first concern
4
Copyright © 2015 Pearson. All rights reserved.
1-4
Compilation
• Translate high-level program (source language)
into machine code (machine language)
• Slow translation, fast execution
• Compilation process has several phases:
– lexical analysis: converts characters in the source program
into lexical units
– syntax analysis: transforms lexical units into parse trees
which represent the syntactic structure of program
– Semantics analysis: generate intermediate code
– code generation: machine code is generated
5
Multiple Choice
A computer programming language, such as C and C++, that uses a software tool called a compiler to translate the code into binary machine language.
Encapsulation
Assembly Language
Compiled Language
Interpreted Language
6
Lexical Analysis
1-5
7
Copyright © 2015 Pearson. All rights reserved.
1-6
The Compilation Process
Pros
•The program is immediately ready
•Usually faster
•Source code is private and safe
Cons
•Not cross-platform (Mac-Windows)
•Need to prepare for different CPU/Memory machine
(not flexible)
8
Copyright © 2015 Pearson. All rights reserved.
1-6
Code Optimization
Common Subexpression elimination
t1=x*z;
t2=a+b;
t3=p%t2;
t4=x*z;
t5=a-z;
//t4 and t1 is same expression, but evaluated twice by compiler.
// after Optimization
t1=x*z;
t2=a+b;
t3=p%t2;
t5=a-z;
9
Copyright © 2015 Pearson. All rights reserved.
1-6
Code Optimization
Constant Folding
//Code segment
int x= 5+7+c;
//Folding applied
int x=12+c;
10
Copyright © 2015 Pearson. All rights reserved.
1-6
Code Optimization
Dead Code Elimination
//Code
int x= a+23;
z=a+y;
printf("%d,%d".z,y);
//After Optimization and removing x
z=a+y;
printf("%d,%d".z,y);
11
Copyright © 2015 Pearson. All rights reserved.
1-6
Code Optimization
Copy Propagation
//Code segment
a=b;
z=a+x;
x=z-b;
//After Optimization
z=b+x;
x=z-b;
12
Copyright © 2015 Pearson. All rights reserved.
1-6
Code Optimization
Loop Optimizations
p=100 ;
for(i=0;i<p;i++)
{
a=b+40;
//loop invariant code
if(p/a==0)
printf("%d",p); }
// After code motion
p=100
a=b+40;
for(i=0;i<p;i++) {
if(p/a==0)
printf("%d",p);
}
13
Multiple Choice
All of these are examples of tokens except___
Comment
Keyword
Operator
Identifier
14
Multiple Choice
In this code, int x = 5; 'int' is considered____
identifier
keyword
Operator
None of these
15
Multiple Choice
Removing unused code from the program, is considered___
Machine dependent code optimization
Machine Independent code optimization
16
Syntax Analysis
1-7
The Java compiler checks if the keywords
(class, public, static, void, int), variable declarations,
assignments, arithmetic operations, and method invocations
are in the correct order and properly nested.
It also verifies that the parentheses, semicolons, and
quotation marks are used correctly.
If there are any syntax errors in the code, the Java compiler
will report them, and the program will not compile until the
errors are fixed.
17
Multiple Choice
Which of the following is a syntax error?
Attempting to divide by 0
Forgetting a colon at the end of a statement where one is required.
Forgetting to divide by 100 when printing a percentage amount.
18
Multiple Choice
The following is an example of what type of error?
print("Here is some text"
print(6/2)
Syntax Error
Run-time Error
Semantic Error
19
Multiple Choice
Program is translated line by line as the program is running
Assembler
Compiler
Interpreter
20
Multiple Choice
This phase scans the source code as a stream of characters and converts it into meaningful lexemes.
Lexical Analyzer
Syntax Analyzer
Semantic Analyzer
Code Generator
21
Abstract Syntax Tree - AST
1-8
ClassDeclaration (SyntaxExample)
├── MethodDeclaration (main)
│ ├── Modifier (public)
│ ├── Type (void)
│ ├── Identifier (main)
│ ├── FormalParameterList
│ │ └── FormalParameter (String[] args)
│ └── Block
│ └── Statement
│ ├── VariableDeclaration (int x = 5)
│ ├── VariableDeclaration (int y = 10)
│ ├── VariableDeclaration (int sum = x + y)
│ └── ExpressionStatement (System.out.println("The sum is: " + sum))
└── PrimitiveType (int)
22
Abstract Syntax Tree - AST
1-9
23
Semantic Analysis
1-10
Type Checking:
Ensure that expressions, variables, and operations are used correctly
based on their types. It verifies that compatible types are used together
and reports any type mismatches.
Scope and Declaration Resolution:
Ensures that variables are declared before they are used and that they
are accessible within their respective scopes.
Control Flow Analysis:
It ensures that the control flow is well-formed and that there are no
unreachable statements or potential infinite loops.
24
Copyright © 2015 Pearson. All rights reserved.
1-11
Pure Interpretation
• No translation
• Easier implementation of programs (run-time
errors can easily and immediately be displayed)
• Slower execution (10 to 100 times slower than
compiled programs)
• Often requires more space
• Now rare for traditional high-level languages
• Significant comeback with some Web scripting
languages (e.g., JavaScript, PHP)
25
Multiple Choice
An infinite loop is an example of what type of error?
Syntax Error
Run-time Error
Semantic Error
26
Copyright © 2015 Pearson. All rights reserved.
1-12
Pure Interpretation Process
Pros
•Cross-platform and portable
•Easier to test because no compiled step
•When things go wrong, easier to debug since having
access to the code
Cons
•Need interpreter on the user machine
•At least ten times slower than compiled languages
•Source code is public
27
Copyright © 2015 Pearson. All rights reserved.
1-13
Hybrid Implementation Systems
• A compromise between compilers and pure
interpreters
• A high-level language program is translated
to an intermediate language that allows
easy interpretation
• Faster than pure interpretation
28
Copyright © 2015 Pearson. All rights reserved.
1-14
Hybrid Implementation Process
29
Examples
• Compiled Language
– C, C++, and Objective-C
• Interpreted Language
– PHP, Ruby, and Javascript
• Hybrid Language
– Java, C#, Perl, and Python
1-15
30
Generations of programming language
1-15
Machine Code Assembly Java/Python/C SQL Prolog
31
Multiple Choice
C is a ___________generation programming language.
Third
First
Second
Fourth
32
Multiple Choice
Language the consists of binary codes (0s and 1s)___
Assembly
Machine Language
3G
4G
33
Copyright © 2015 Pearson. All rights reserved.
1-16
Programming Environments
• A collection of tools used in software development
• Microsoft Visual Studio.NET
– A large, complex visual environment
•Used to build Web applications and non-Web applications in
any .NET language
• NetBeans
– Related to Visual Studio .NET, except for applications in
Java
• PyCharm
– Used to build Python applications
34
Copyright © 2015 Pearson. All rights reserved.
1-17
Programming Environments
• Online Environments
– https://www.onlinegdb.com/
35
Copyright © 2015 Pearson. All rights reserved.
1-18
Programming Environments
• Online Environments
– https://repl.it/
36
Programming Environments
• Online Environments
https://swish.swi-prolog.org
1-19
37
Copyright © 2015 Pearson. All rights reserved.
1-20
Summary
• The study of programming languages is valuable for
a number of reasons:
– Increase our capacity to use different constructs
– Enable us to choose languages more intelligently
– Makes learning new languages easier
• Most important criteria for evaluating programming
languages include:
– Readability, writability, reliability, cost
• Major influences on language design have been
machine architecture and software development
methodologies
• The major methods of implementing programming
languages are: compilation, pure interpretation, and
hybrid implementation
ISBN 0-321-49362-1
Chapter 1
Preliminaries
Show answer
Auto Play
Slide 1 / 37
SLIDE
Similar Resources on Wayground
28 questions
Computer software
Presentation
•
University
27 questions
M2U2 - Using Apps (SY25-26/C103-101i)
Presentation
•
University
29 questions
2 weeks certification program - Day 1
Presentation
•
12th Grade - University
33 questions
Herramientas informáticas - Conceptos
Presentation
•
University
33 questions
operator overloading
Presentation
•
KG - University
34 questions
IntroDatabases
Presentation
•
University
28 questions
IT1 Topic 2 Hardware and Software (Computer Basics) Lesson
Presentation
•
University
35 questions
M0dule2 CPE4O8
Presentation
•
University
Popular Resources on Wayground
20 questions
"What is the question asking??" Grades 3-5
Quiz
•
1st - 5th Grade
20 questions
“What is the question asking??” Grades 6-8
Quiz
•
6th - 8th Grade
10 questions
Fire Safety Quiz
Quiz
•
12th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
34 questions
STAAR Review 6th - 8th grade Reading Part 1
Quiz
•
6th - 8th Grade
20 questions
“What is the question asking??” English I-II
Quiz
•
9th - 12th Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
47 questions
8th Grade Reading STAAR Ultimate Review!
Quiz
•
8th Grade
Discover more resources for Computers
15 questions
LGBTQ Trivia
Quiz
•
University
36 questions
8th Grade US History STAAR Review
Quiz
•
KG - University
25 questions
5th Grade Science STAAR Review
Quiz
•
KG - University
16 questions
Parallel, Perpendicular, and Intersecting Lines
Quiz
•
KG - Professional Dev...
20 questions
5_Review_TEACHER
Quiz
•
University
10 questions
Applications of Quadratic Functions
Quiz
•
10th Grade - University
10 questions
Add & Subtract Mixed Numbers with Like Denominators
Quiz
•
KG - University
20 questions
Block Buster Movies
Quiz
•
10th Grade - Professi...