Slide 1

Slide 1 text

jgs CSE 240 Introduction to Programming Languages Lecture 04: Program Processing Dr. Javier Gonzalez-Sanchez [email protected] javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment

Slide 2

Slide 2 text

jgs Test Yourselves

Slide 3

Slide 3 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 3 jgs Test Yourselves Exceptions in Java are due to a) Lexical Errors b) Syntactic Errors c) Semantical Errors d) Run-time Error e) All f) None

Slide 4

Slide 4 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 4 jgs Test Yourselves Is there an error below (yes/no) and if (yes) what type of error: a) Object x = new JPanel(“1”); b) int int = 5; c) String string = “string”; d) x+++ 1;

Slide 5

Slide 5 text

jgs Program Processing

Slide 6

Slide 6 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 6 jgs Program Processing

Slide 7

Slide 7 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 7 jgs Program Processing: Interpretation Interpreter is a program that translates in runtime and executes each statement in the high level-language. Advantages: § No separate compilation phase (quicker program development); § Good debugging information since the source code is being executed. § Abstraction Disadvantages: § Slow execution § Can use more memory space Why?

Slide 8

Slide 8 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 8 jgs LISP Steel Bank Common Lisp https://sourceforge.net/projects/sbcl

Slide 9

Slide 9 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 9 jgs LISP Compile LISP online http://rextester.com/l/common_lisp_online_compiler

Slide 10

Slide 10 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 10 jgs Prolog http://www.swi-prolog.org/download/stable

Slide 11

Slide 11 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 11 jgs Prolog https://swish.swi-prolog.org

Slide 12

Slide 12 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 12 jgs Program Processing assembler linker compiler Why?

Slide 13

Slide 13 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 13 jgs Program Processing: Compilation § Compiler is a program that translate the entire code from source to assembly code. § Assembler. § Linker resolves external references (e.g., bring in code from libraries) object code (binary) linker Executable binary for a specific machine other objects source program assembler assembly program compiler

Slide 14

Slide 14 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 14 jgs Program Processing: Compilation Advantages: § Faster than interpretation § Good for multi-module programs Disadvantages: § Separate compilation phase § May lose debugging info

Slide 15

Slide 15 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 15 jgs C and C++ § Microsoft Visual Studio § Apple XCode § Clion https://www.jetbrains.com/clion/ § Online Compiler for C/C++ https://www.onlinegdb.com/online_c_compiler § Dev-C++ 5 http://www.bloodshed.net/devcpp.html

Slide 16

Slide 16 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 16 jgs Program Processing Program Processing Interpretation LISP Prolog Compilation C C++ Two Step Translation with Intermediate Code Compilation + Interpretation Java Compilation + Compilation C++ (.Net Solution) C# (.Net Solution)

Slide 17

Slide 17 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 17 jgs Program Processing: Intermediate Code (Java) Intermediate code make the language and compiler machine-independent. This concept was implemented in 1970’s to simplify the compiler design. It is used in Java. bytecode Java program javac Java virtual machine Interpreter on a specific machine Simulator or Hardware source program intermediate code Virtual machine compiler

Slide 18

Slide 18 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 18 jgs Program Processing: Intermediate Code (.Net) Microsoft uses an intermediate code for its Common Language Runtime (CLR) environment (.Net Runtime Environment), which is independent of languages Prolog F# X F# compiler Prolog compiler X compiler JIT AND CLI C# Languages MS IL Just-In-Time compiler Intermediate Language Common Language Infrastructure Compilers C# compiler C++ C++ compiler C C compiler Simulator or Hardware

Slide 19

Slide 19 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 19 jgs Program Processing: Intermediate Code Advantages: • A single compiler for all machines • A small virtual machine (interpreter) that even fits in a web browser Disadvantages: § Slow execution and memory space § Separate compilation phase and may lose debugging info

Slide 20

Slide 20 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 20 jgs Program Processing Program Processing Interpretation LISP Prolog Compilation C C++ Two Step Translation with Intermediate Code Compilation + Interpretation Java Compilation + Compilation C++ (.Net Solution) C# (.Net Solution)

Slide 21

Slide 21 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 21 jgs Test Yourselves § Pros and Cons Interpreter § Pros and Cons Compiler § Pros and Cons Two-Steps Processing using Intermediate Code

Slide 22

Slide 22 text

Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 22 jgs Questions

Slide 23

Slide 23 text

jgs CSE 240 Introduction to Programming Languages Javier Gonzalez-Sanchez, Ph.D. [email protected] Spring 2022 Copyright. These slides can only be used as study material for the class CSE240 at Arizona State University. They cannot be distributed or used for another purpose.