introduction to programming languages
play

INTRODUCTION TO PROGRAMMING LANGUAGES COMS W1001 Introduction to - PowerPoint PPT Presentation

1 INTRODUCTION TO PROGRAMMING LANGUAGES COMS W1001 Introduction to Information Science Boyi Xie 2 Todays Topics Why We Need Programming Languages Low-level Programming Language High-level Programming Language How a Program


  1. 1 INTRODUCTION TO PROGRAMMING LANGUAGES COMS W1001 Introduction to Information Science Boyi Xie

  2. 2 Today’s Topics • Why We Need Programming Languages • Low-level Programming Language • High-level Programming Language • How a Program Works • Compiler • Interpreters

  3. 3 Why We Need Programming Languages • A computer’s CPU can only understand instructions that are written in machine language. • Assembly language was created in the early days of computing a an alternative to machine languages. • Instead of using binary numbers for instructions, assembly language uses short words that are know as mnemonics. • Because assembly language is so close in nature to machine language , it is referred to as a low-level language LDF R2, id3 � MULF R2, R2, #60.0 � LDF R1, id2 � ADDF R1, R1, R2 � STF id1, R1 �

  4. 4 Why We Need Programming Languages • People still find it very difficult to write entire programs in assembly language, other programming languages have been invented. • Programming languages are notations for describing computations to people and to machines. • In the 1950s, a new generation of programming languages known as high-level languages began to appear • They allow programmers to create powerful and complex programs without knowing how the CPU works, and without writing large numbers of low-level instructions.

  5. 5 Some High-Level Programming Languages Languages Description BASIC Beginners All-purpose Symbolic Instruction Code, 1960s FORTRAN FORmula TRANslator, 1950ss COBOL Common Business-Oriented Language, 1950s Pascal Originally designed for teaching programming, 1970s C and C++ General purpose programming language, developed at Bell Lab in 1972 (C) and 1983 (C++) C# Around the year 2000 by Microsoft for .NET platform Java General purpose programming language, created by Sun Microsystem in early 1990s JavaScript Mainly used in web pages, created in 1990s Pythons General purpose programming language, created in the early 1990s Ruby General purpose programming language, created in the early 1990s Visual Basic Created in the early 1990s for Windows-based applications

  6. 6 How a Program Works • Before a program can be run, it first must be translated into a form in which it can be executed by a computer. • The software systems that do this translation are called compilers. • A compiler is a program that can read a program in one language – the source language – and translate it into an equivalent program in another language – the target language.

  7. 7 How a Program Works • Compiler • Translates a source program into a target program • If the target program is an executable machine-language program, it can then be called by the user to process inputs and produce outputs Source Program Compiler input Target Program output

  8. 8 character stream How a Program Works Lexical Analyzer • Phases of a compiler token stream • Analysis part Syntax Analyzer • breaks up the source program into syntax tree constituent pieces • imposes a grammatical structure Semantic Analyzer • uses this structure to create Symbol syntax tree intermediate representation Table • Synthesis part Intermediate Code Generator • construct the desired target program from the intermediate representation intermediate representation and the information in the symbol Machine-Independent table Code Optimizer • Symbol table intermediate representation • the analysis part collects information Code Generator about the source program and stores it in a data structure called a symbol target-machine code table, which is passed along with the Machine-Dependent intermediate representation to the Code Optimizer synthesis part. target-machine code

  9. 9 character stream How a Program Works Lexical Analyzer token stream position = initial + rate * 60 Syntax Analyzer < id ,1> <=> < id ,2> <+> < id ,3> <*> <60> � syntax tree = Semantic Analyzer Symbol Table < id ,1> + … 1 position syntax tree … 2 initial Intermediate Code Generator … < id ,2> * 3 rate intermediate representation 60 < id ,3> = Machine-Independent Code Optimizer < id ,1> + intermediate representation Code Generator < id ,2> * target-machine code Machine-Dependent < id ,3> inttofloat Code Optimizer target-machine code 60

  10. 10 character stream How a Program Works Lexical Analyzer token stream position = initial + rate * 60 Syntax Analyzer t1 = inttofloat(60) � syntax tree t2 = id3 * t1 � t3 = id2 + t2 � Semantic Analyzer Symbol Table id1 = t3 � … 1 position syntax tree … 2 initial t1 = id3 * 60.0 � Intermediate Code Generator … 3 rate id1 = id2 + t1 � intermediate representation Machine-Independent LDF R2, id3 � Code Optimizer MULF R2, R2, #60.0 � LDF R1, id2 � intermediate representation ADDF R1, R1, R2 � Code Generator STF id1, R1 � target-machine code 0001 0010 1111 0000 � Machine-Dependent 1110 0010 0011 1100 � Code Optimizer … � target-machine code

  11. 11 How a Program Works • Interpreter • Translates a source program to its equivalent machine-language program and immediately executes them. Source Program Interpreter output input • The Python language uses an interpreter.

  12. 12 References & Photo Credits • Pearson Custom Computer Science COMS W1001 Introduction to Information Science, Columbia University. Chapter 12 Introduction to Computer and Programming by Tony Gaddis • Compilers, Principles, Techniques, and Tools. Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend