Introduction to Language Processing Technology Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.

Slides:



Advertisements
Similar presentations
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Advertisements

Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Compilers and Language Translation
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch. 3: Compilation Spring 2007 Marco Valtorta.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Concepts of Programming Languages 1 Describing Syntax and Semantics Brahim Hnich Högskola I Gävle
1 Languages and Compilers (SProg og Oversættere) Lecture 2 Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch. 3: Compilation Spring 2008 Marco Valtorta.
Computer Concepts 5th Edition Parsons/Oja Page 546 CHAPTER 11 Software Engineering Section A PARSONS/OJA Computer Programming.
Chapter 16 Programming and Languages: Telling the Computer What to Do.
Slide 1 Chapter 3 Attribute Grammars. Slide 2 Attribute Grammars Certain language structures cannot be described using EBNF. Attribute grammars are extensions.
Introduction and Syntax. Course objectives Discuss features of programming languages. Discuss how the features are implemented in a simple computer architecture.
Introduction to a Programming Environment
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.1 Spring 2010 Marco Valtorta
Syntax Analysis (Chapter 4) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
3-1 3 Compilers and interpreters  Compilers and other translators  Interpreters  Tombstone diagrams  Real vs virtual machines  Interpretive compilers.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Compiler Design Nai-Wei Lin Department of Computer Science National Chung Cheng University.
Programming Languages – Coding schemes used to write both systems and application software A programming language is an abstraction mechanism. It enables.
Chapter 17 Programming Tools The Architecture of Computer Hardware and Systems Software: An Information Technology Approach 3rd Edition, Irv Englander.
Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth.
Course Revision Contents  Compilers  Compilers Vs Interpreters  Structure of Compiler  Compilation Phases  Compiler Construction Tools  A Simple.
Syntax Analysis (Chapter 4) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
Syntax Analysis (Chapter 4) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
Natawut NupairojAssembly Language1 Introduction to Assembly Programming.
Languages and Compilers (SProg og Oversættere)
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
CSC 338: Compiler design and implementation
Design Pattern Interpreter By Swathi Polusani. What is an Interpreter? The Interpreter pattern describes how to define a grammar for simple languages,
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
Introduction to Computer Systems and the Java Programming Language.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
C H A P T E R TWO Syntax and Semantic.
Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University.
Introduction (Chapter 1) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
Lecture 11: 10/1/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University.
CT1513 Introduction To java © A.AlOsaimi.
CPS 506 Comparative Programming Languages Syntax Specification.
CS 614: Theory and Construction of Compilers Lecture 7 Fall 2002 Department of Computer Science University of Alabama Joel Jones.
CS 614: Theory and Construction of Compilers Lecture 8 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Language Translation A programming language processor is any system that manipulates programs expressed in a PL A source program in some source language.
Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.
A compiler is a computer program that translate written code (source code) into another computer language Associated with high level languages A well.
 Chapter 2 Language Processors Fall Chart 2  Translators and Compilers  Interpreters  Real and Abstract Machines  Interpretive Compilers 
CSC1200 INTRODUCTION TO PROGRAMMING Dr. Maureen Markel
The Model of Compilation Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
The Interpreter Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
 Fall Chart 2  Translators and Compilers  Textbook o Programming Language Processors in Java, Authors: David A. Watts & Deryck F. Brown, 2000,
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
1-1 1 Introduction  Programming linguistics: concepts and paradigms syntax, semantics, and pragmatics language processors.  Historical development of.
C H A P T E R T W O Syntax and Semantic. 2 Introduction Who must use language definitions? Other language designers Implementors Programmers (the users.
CS 614: Theory and Construction of Compilers Lecture 8 Fall 2002 Department of Computer Science University of Alabama Joel Jones.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
Compilers Design Chapter1 : Introduction, Structure of a Compiler
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
Overview of Compilers and Language Translation
Introduction to Compiler Construction
CSCI-235 Micro-Computer Applications
Course Overview PART I: overview material PART II: inside a compiler
Course Overview PART I: overview material PART II: inside a compiler
Presentation transcript:

Introduction to Language Processing Technology Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University

Outline Level of Programming Languages. Language Processors. Specification of Programming Languages.

swap(int v[], int k) { int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } swap: muli $2, $5, 4 add $2, $4, $2 lw $15, 0($2)... Assembler C Compiler Level of Programming Languages High level: C / Java / Pascal Low level: Assembly / Bytecode Machine Language

High-Level Language Characteristics Expressions: a = b + (c – d)/2; Data types:  Integer, character, boolean.  Record, array. Control structures:  Selective.  Iterative.

High-Level Language Characteristics Declarations:  Identifier can be constant, variable, procedure, function, and type. Abstraction:  Object-oriented concept.  Concern only what, not how. Encapsulation:  Object-oriented concept.  Information hiding.

Language Processors Program that manipulates programs express in some programming languages. Example:  Editor.  Translator / Compiler.  Interpreter.

Translator Translate a “source” program into an “equivalent” “object” program. Translator source program object program error messages C C++ FORTRAN Java VB Assembly C Bytecode p-code

Tombstone Diagrams Ordinary program Program P Written with Language L L P Java Sort x86 Sort x86 Web Browser

x86 Web Browser Tombstone Diagrams Machine M Machine M x86 SPARCx86 SPARC x86 Web Browser

Tombstone Diagrams Translator L S  T S is translated to T Translator is written with Language L C Java  x86 x86 Java  x86 C++ Java  C

Tombstone Diagrams Compilation x86 C  x86 x86 Sort C x86 Sort

Tombstone Diagrams Cross Compilation x86 C  SPARC x86 SPARC Sort SPARC Sort C

Tombstone Diagrams x86 Java  C x86 C  x86 x86 Two-stage compilation C Sort Java Sort x86 Sort

Tombstone Diagrams x86 C  x86 x86 Compiling a compiler C Pascal  x86 x86 Pascal  x86

Tombstone Diagrams Interpreter SLSL Interpret source S x86 Written in language L Basic x86 Basic x86 SQL SPARC Basic Sort

Tombstone Diagrams Abstract machine = hardware emulator  interpreter for low-level language. x86 C  x86 x C 370 x x86 = 370 HW1 370 HW1

Tombstone Diagrams Java  Portable environment: write-once-run-anywhere.  Interpretive compiler. M Java  JVM JVM M JVM = Bytecode

Tombstone Diagrams x86 JVM x86 SPARC JVM SPARC JVM Sort JVM Sort x86 Java  JVM x86 JVM Sort Java Sort

Tombstone Diagrams Bootstrapping  Compiler L that is written on L language. Full bootstrap  Start from nothing. Half bootstrap  Start from other machine. NNP C  NNP

Tombstone Diagrams Full Bootstrap NNP C sub C sub  NNP NNP C sub  NNP NNP C sub C  NNP NNP C  NNP NNP C sub  NNP NNP C sub  NNP NNP C sub  NNP

Tombstone Diagrams NNP C C  NNP NNP C  NNP NNP C  NNP

Tombstone Diagrams NNP C sub C sub  NNP NNP C sub  NNP NNP C sub C  NNP NNP C  NNP NNP C sub  NNP NNP C  NNP NNP C C  NNP

Tombstone Diagrams Half Bootstrap x86 C  x86 x86 C C  NNP x86 C  NNP x86 C  NNP x86 C C  NNP NNP C  NNP x86 C  X86 x86

Specification of Programming Language Specification  Syntax Define symbol and structure of the language. Grammar.  Contextual constraints Constraints beyond grammar. Rules of the language: scope rules, type rules, etc.  Semantics Meaning of program: its behaviors when run. How to translate a sentence S of the language L to a machine code on M

Syntax Context-free grammar  Terminals.  Non-terminals / Variables.  Start symbol.  Production rules. Usually being expressed with BNF notation.

BNF Notation Backus-Naur Form. Given production rule: N   N   Can be written as: N ::= 

Example: Mini-Triangle Program ! This is a comment. It continues to the end-of-line. let const m ~ 7; var n: Integer in begin n:= 2 * m * m; putint(n); end Terminals beginconstdoelseendif inletthenvarwhile ;::=~() +-*/<> =\

Mini-Triangle Syntax Program::=Command Command::=single-Command |Command ; single-Command single-Command ::=V-name := Expression |Identifier ( Expression ) |if Expression then single-Command else single-Command |while Expression do single-Command |let Declaration in single-Command |begin Command end

Mini-Triangle Syntax Expression::=primary-Expression |Expression Operator primary-Expression primary-Expression ::=Integer-Literal |V-name |Operator primary-Expression |( Expression ) V-name::=Identifier Declaration::=single-Declaration |Declaration ; single-Declaration single-Declaration ::=const Identifier ~ Expression |var Identifier : Type-denoter

Mini-Triangle Syntax Type-denoter::=Identifier Operator::=+ | - | * | / | | = | \ Identifier::=Letter | Identifier Letter |Identifier Digit Integer-Literal ::=Digit | Integer-Literal Digit Comment::=! Graphic* eol Letter::=a | b | … |z Digit::=0 | 1 | 2 | … | 9

Syntax Tree Ordered tree with  Internal nodes: non-terminals.  Leaf nodes: terminals.  N-tree of G is a syntax tree with N as the root.

Mini-Triangle Syntax Tree Expression ::= primary-Expression | Expression Operator primary-Expression primary-Expression ::= Integer-Literal | V-name | Operator primary-Expression |( Expression ) V-name ::= Identifier …