CS 3304 Comparative Languages. Lecture 1: Introduction

Similar documents
Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

Early computers (1940s) cost millions of dollars and were programmed in machine language. less error-prone method needed

Why are there so many programming languages?

Programming Languages

Introduction to Programming Languages. CSE 307 Principles of Programming Languages Stony Brook University

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

CSC 326H1F, Fall Programming Languages. What languages do you know? Instructor: Ali Juma. A survey of counted loops: FORTRAN

Compilation I. Hwansoo Han

Programming Languages, Summary CSC419; Odelia Schwartz

CSCI 3136 Principles of Programming Languages

Chapter 7:: Data Types. Mid-Term Test. Mid-Term Test (cont.) Administrative Notes

CS/SE 153 Concepts of Compiler Design

CMPE 152 Compiler Design

CS/SE 153 Concepts of Compiler Design

Principles of Programming Languages. Lecture Outline

CSc 520. Course Outline (Subject to change) Course Outline (Subject to change)... Principles of Programming Languages. Christian Collberg

CMPE 152 Compiler Design

Concepts in Programming Languages

Concepts of Programming Languages

CS 415 Midterm Exam Spring 2002

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

CMPE 152 Compiler Design

San José State University College of Science/Department of Computer Science CS 152, Programming Language Paradigms, Section 03/04, Fall, 2018

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

ECE573 Introduction to Compilers & Translators

Introduction to Computer Science I

CSE 504: Compiler Design

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design



Introduction. A. Bellaachia Page: 1

Com S 541. Programming Languages I

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

CS A331 Programming Language Concepts

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

CS 242. Fundamentals. Reading: See last slide

Chapter 1. Preview. Reason for Studying OPL. Language Evaluation Criteria. Programming Domains

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

CS 241 Data Organization using C

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COSC 2P90 Programming Languages & Object-Orientation

ECE Introduction to Compilers and Translation Engineering

Chapter 1. Preliminaries

Compiler Design. Dr. Chengwei Lei CEECS California State University, Bakersfield

LECTURE 1. Overview and History

CS2303 C14 Systems Programming Concepts. Bob Kinicki

Lecture 1: Course Introduction

A Tour of Language Implementation

Translator Design CRN Course Administration CMSC 4173 Spring 2017

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

PLAGIARISM. Administrivia. Course home page: Introduction to Programming Languages and Compilers

Introduction to Programming Languages and Compilers. CS164 11:00-12:00 MWF 306 Soda

INSTITUTE OF AERONAUTICAL ENGINEERING

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2015 Euiseong Seo

CS383 PROGRAMMING LANGUAGES. Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

Chapter 1. Preliminaries

Spring 2018 El Camino College E. Ambrosio. Course Syllabus

CS415 Compilers Overview of the Course. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

Lecture 1: Course Introduction

CS 314 Principles of Programming Languages

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

CS 113: Introduction to

San Jose State University College of Science Department of Computer Science CS151, Object-Oriented Design, Sections 1,2 and 3, Spring 2017

Welcome to Introduction to Computer Science I

Lecture 1. Introduction to course, Welcome to Engineering, What is Programming and Why is this the first thing being covered in Engineering?

CSc 372 Comparative Programming Languages

Programming Languages 2nd edition Tucker and Noonan"

15-411/ Compiler Design

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

LECTURE 3. Compiler Phases

COMP 401 COURSE OVERVIEW

Programmiersprachen (Programming Languages)

Philadelphia University Faculty of Information Technology Department of Computer Science --- Semester, 2007/2008. Course Syllabus

Seminar in Programming Languages

Why study Programming Language Concepts? Chapter One. Language Evaluation Criteria. Programming Domains. Readability Writability Reliability Cost

Compilers for Modern Architectures Course Syllabus, Spring 2015

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

VE281 Data Structures and Algorithms. Introduction and Asymptotic Algorithm Analysis

CS 360 Programming Languages Interpreters

Programming Language Pragmatics

INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/10

Thanks! Review. Course Goals. General Themes in this Course. There are many programming languages. Teaching Assistants. John Mitchell.

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

CS 241 Data Organization. August 21, 2018

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

San José State University Department of Computer Science CS-144, Advanced C++ Programming, Section 1, Fall 2017

CS 553 Compiler Construction Fall 2009 Project #1 Adding doubles to MiniJava Due September 8, 2009

COMPILER DESIGN LECTURE NOTES

TTh 9.25 AM AM Strain 322

CS153: Compilers Lecture 1: Introduction

Compilers. Computer Science 431

LECTURE 18. Control Flow

Chapter 1 Preliminaries

Introduction to Programming System Design CSCI 455x (4 Units)

CSE 114, Computer Science 1 Course Information. Spring 2017 Stony Brook University Instructor: Dr. Paul Fodor

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE 130 : Fall 2013

Logic Programming II & Revision

San José State University Department of Computer Science CS049J, Programming in Java, Section 2, Fall, 2016

Transcription:

CS 3304 Comparative Languages Lecture 1: Introduction 17 January 2012 2012 Denis Gracanin

Course Overview 2

Welcome What this course is about? What this course is not about? What will you learn? How will you learn? Read and understand material. Regularly check for announcements and assignments. Interact with instructors and students. Provide feedback. Course website: http://scholar.vt.edu/ Forum website: http://www.piazza.com/ 3

Overview CRN: 12059 Course description: This course in programming language constructs emphasizes the run-time behavior of programs. The languages are studied from two points of view: (1) the fundamental elements of languages and their inclusion in commercially available systems; and, (2) the differences between implementations of common elements in languages. A grade of C or better required in CS prerequisite 3114. I,II. Prerequisites: CS 3114 (MIN grade of C) 4

Contacts Instructor: Dr. Denis Gracanin, Associate Professor E-mail: gracanin@vt.edu Office: KnowledgeWorks II, Room 1135 Office Hours: Location: LumenHaus (behind Cowgill Hall) or McBryde 122 Time: Tuesday/Thursday 1pm-3pm Location: KnowledgeWorks II, Room 1135 Time: By appointment Graduate Teaching Assistant (GTA): Shaimaa Lazem E-mail: shlazem@vt.edu Office Hours: Location: McBryde 106 Time: Friday 9am-noon 5

Textbook and Course Materials Michael L. Scott Programming Language Pragmatics, Third Edition Morgan Kaufmann, 2009 ISBN-13 978-0-12-374514-9 Course materials will be posted on the course web site accessible through the VT scholar gateway: http://scholar.vt.edu/ 6

Grading One midterm exams (closed book): 15%. Final exam (comprehensive, closed book): 25%. Homeworks: 20% total. Programming assignments: 40%. Late submission policy: the assignment is first graded as if submitted on time. The points score is then multiplied by the factor k based on the time t elapsed between the deadline and your submission. t 24 hours: k = 0.9 24 < t 48 hours: k = 0.5 t > 48 hours: k = 0 7

Honor System Please review The Virginia Tech Undergraduate Honor System, for more information see: http://www.honorsystem.vt.edu/ All assignments are individual, no collaboration allowed. However, you can discuss course topics and related issues as long they do not relate to homework or project specifics. When in doubt, consult us first. All code will be checked by a tool that detects similarities and warns about possible plagiarism. 8

Introduction 9

Why So Many Programming Languages? Evolution: we've learned better ways of doing things over time. Socio-economic factors: proprietary interests, commercial advantage. Orientation toward special purposes. Orientation toward special hardware. Diverse ideas about what is pleasant to use. 10

What Makes a Language Successful? Easy to learn (BASIC, Pascal, LOGO, Scheme). Easy to express things, easy use once fluent, "powerful" (C, Common Lisp, APL, Algol-68, Perl). Easy to implement (BASIC, Forth). Possible to compile to very good (fast/small) code (Fortran). Backing of a powerful sponsor (COBOL, PL/1, Ada, Visual Basic). Wide dissemination at minimal cost (Pascal, Turing, Java). 11

What Is a Programming Language for? Way of thinking: way of expressing algorithms. Languages from the user's point of view. Abstraction of virtual machine: way of specifying what you want. The hardware to do without getting down into the bits. Languages from the implementor's point of view. 12

Why Study Programming Languages? I Help you choose a language: C vs. Modula-3 vs. C++ for systems programming. Fortran vs. APL vs. Ada for numerical computations. Ada vs. Modula-2 for embedded systems. Common Lisp vs. Scheme vs. ML for symbolic data manipulation. Java vs. C/CORBA for networked PC programs. Make it easier to learn new languages some languages are similar; easy to walk down family tree: Concepts have even more similarity; if you think in terms of iteration, recursion, abstraction (for example), you will find it easier to assimilate the syntax and semantic details of a new language than if you try to pick it up in a vacuum. Think of an analogy to human languages: good grasp of grammar makes it easier to pick up new languages (at least Indo-European). 13

Why Study Programming Languages? II Help you make better use of whatever language you use: Understand obscure features: In C, help you understand unions, arrays & pointers, separate compilation, varargs, catch and throw. In Common Lisp, help you understand first-class functions/closures, streams, catch and throw, symbol internals. Understand implementation costs: choose between alternative ways of doing things, based on knowledge of what will be done underneath: Use simple arithmetic equal (use x*x instead of x**2). Use C pointers or Pascal "with" statement to factor address calculations. Avoid call by value with large data items in Pascal. Avoid the use of call by name in Algol 60. Choose between computation and table lookup (e.g. for cardinality operator in C or C++). 14

Why Study Programming Languages? III Help you make better use of whatever language you use: Figure out how to do things in languages that don't support them explicitly: Lack of suitable control structures in Fortran. Use comments and programmer discipline for control structures. Lack of recursion in Fortran, CSP, etc. Write a recursive algorithm then use mechanical recursion elimination (even for things that aren't quite tail recursive). Figure out how to do things in languages that don't support them explicitly: Lack of named constants and enumerations in Fortran. Use variables that are initialized once, then never changed. Lack of modules in C and Pascal use comments and programmer discipline. Lack of iterators in just about everything fake them with (member?) functions. 15

Language Groups Imperative: von Neumann (Fortran, Pascal, Basic, C). Object-oriented (Smalltalk, Eiffel, C++?). Scripting languages (Perl, Python, JavaScript, PHP). Declarative: Functional (Scheme, ML, pure Lisp, FP). Logic, constraint-based (Prolog, VisiCalc, RPG). Imperative languages, particularly the von Neumann languages, predominate: They will occupy the bulk of our attention. We also plan to spend a lot of time on functional, logic languages. 16

ANTLR 17

What is ANTLR? ANTLR (http://www.antlr.org/) is a parser generator used to implement language interpreters, compilers, etc. Books by Terence Parr: The Definitive ANTLR Reference: Building Domain-Specific Languages http://www.pragprog.com/titles/tpantlr/ Language Implementation Patterns: Create Your Own Domain-Specific and General Programming Languages http://www.pragprog.com/titles/tpdsl/ Most often used to build translators and interpreters for domain-specific languages (DSLs). DSLs are usually very high-level languages used for specific tasks and particularly effective in a specific domain. DSLs provide a more natural, high-fidelity, robust, and maintainable means of encoding a problem compared to a general-purpose language. 18

Definitions Lexer: converts a stream of characters to a stream of tokens (ANTLR token objects know their start/stop character stream index, line number, index within the line, and more). Parser: processes a stream of tokens, possibly creating an AST. Abstract Syntax Tree (AST): an intermediate tree representation of the parsed input that is simpler to process than the stream of tokens and can be efficiently processed multiple times. Tree Parser: processes an AST. StringTemplate: a library that supports using templates with placeholders for outputting text (ex. Java source code). 19

Using ANTLR Write the grammar using one or more files. A common approach is to use three grammar files, each focusing on a specific aspect of the processing: The first is the lexer grammar: creates tokens from text input. The second is the parser grammar: creates an AST from tokens. The third is the tree parser grammar, which processes an AST. This results in three relatively simple grammar files as opposed to one complex grammar file. Optionally write StringTemplate templates for producing output. Debug the grammar using ANTLRWorks. Generate classes from the grammar. These validate that text input conforms to the grammar and execute target language actions specified in the grammar. Write an application that uses the the generated classes. 20

Overall Translation Data Flow A translator maps each input sentence to an output sentence. The overall translation problem consists of smaller problems mapped to well-defined translation phases (lexing, parsing, and tree parsing). The communication between phases uses well-defined data types and structures (characters, tokens, trees, and ancillary structures). Often the translation requires multiple passes so an intermediate form is needed to pass the input between phases. Abstract Syntax Tree (AST) is a highly processed, condensed version of the input. INPUT characters LEXER tokens PARSER AST OUTPUT TREE WALKER ancillary data structures: symbol table, flow graph,... 21

Example ANTRL File: Expr.g grammar Expr; prog: stat+ ; stat: expr NEWLINE ID '=' expr NEWLINE NEWLINE ; expr: ; multexpr (('+' '-') multexpr)* multexpr : atom ('*' atom)* ; atom: INT ID '(' expr ')' ; ID : ('a'..'z' 'A'..'Z')+ ; INT : '0'..'9'+ ; NEWLINE:'\r'? '\n' ; WS : (' ' '\t')+ {skip();} ; 22

ANTLRWorks 23

Summary There are many programming languages. Two main groups of programming languages are imperative and declarative. ANTLR is a free, open source parser generator tool. 24