Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE240 Lecture 04

CSE240 Lecture 04

Introduction to Programming Languages
Program Processing
(201701)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

January 04, 2017
Tweet

Transcript

  1. jgs CSE 240 Introduction to Programming Languages Lecture 04: Program

    Processing Dr. Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 2 jgs

    Announcement § Assignment 01. Java Programming. Just to test your Java knowledge will open Thursday
  3. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 3 jgs

    Structure of a Programming Language Paradigm Language Rules Lexical Input: Symbols Output: Words Syntax Input: Words Output: Sentences Semantic Input: Sentences
  4. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 4 jgs

    Structure of a Programming Language Review that the sentences are meaningful Run-Time Errors
  5. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 5 jgs

    Semantic Rules 1.Declaration and Unicity. Review for uniqueness and that the variable has been declared before its usage. 2.Types. Review that the types of variables match the values assigned to them. 3.Array’s indexes. Review that the indexes are integers. 4.Conditions. Review that all expressions on the conditons return a boolean value. 5.Return type. Review that the value returned by a method match the type of the method. 6.Parameters. Review that the parameters in a method match in type and number with the declaration of the method.
  6. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 6 jgs

    Semantic Rules Declaration and Unicity: Review for uniqueness and that the variable has been declared before its usage. //Case 1: int i; char j; int m; void method(int n, char c) { int n; short l; i = j; i = m; } //Case 2: int i, j; void method() { int i = 5; int j = i + i; int i = i + i; }
  7. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 7 jgs

    Semantic Rules 1.Declaration and Unicity. Review for uniqueness and that the variable has been declared before its usage. 2.Types. Review that the types of variables match the values assigned to them. 3.Array’s indexes. Review that the indexes are integers. 4.Conditions. Review that all expressions on the conditons return a boolean value. 5.Return type. Review that the value returned by a method match the type of the method. 6.Parameters. Review that the parameters in a method match in type and number with the declaration of the method.
  8. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 8 jgs

    Semantic Rules Types: Review that the types of variables match the values assigned to them. //Case 3: int x = "hello"; char c = false; boolean foo = c;
  9. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 9 jgs

    Semantic Rules 1.Declaration and Unicity. Review for uniqueness and that the variable has been declared before its usage. 2.Types. Review that the types of variables match the values assigned to them. 3.Array’s indexes. Review that the indexes are integers. 4.Conditions. Review that all expressions on the conditons return a boolean value. 5.Return type. Review that the value returned by a method match the type of the method. 6.Parameters. Review that the parameters in a method match in type and number with the declaration of the method.
  10. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 10 jgs

    Structure of a Programming Language Run-Time Errors Paradigm Language Rules Lexical Input: Symbols Output: Words Syntax Input: Words Output: Sentences Semantic Input: Sentences
  11. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 11 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
  12. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 12 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;
  13. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 13 jgs

    Program Processing
  14. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 14 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?
  15. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 15 jgs

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

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

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

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

    Program Processing assembler linker compiler Why?
  20. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 20 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
  21. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 21 jgs

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

    C and C++ § Install Microsoft Visual Studio or XCode Plan B § 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
  23. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 23 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)
  24. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 24 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
  25. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 25 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
  26. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 26 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
  27. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 27 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)
  28. Javier Gonzalez-Sanchez | CSE240 | Fall 2021 | 28 jgs

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

    Questions
  30. jgs CSE 240 Introduction to Programming Languages Javier Gonzalez-Sanchez, Ph.D.

    javiergs@asu.edu Fall 2021 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.