CS 3304 Comparative Languages

Slides:



Advertisements
Similar presentations
PLLab, NTHU Cs2403 Programming Languages Implementation Issues Cs2403 Programming Language Spring 2005 Kun-Yuan Hsieh.
Advertisements

Programming Languages Structure
Summer 02-03Programming Language Concepts1 Programming Language Concepts (CS 360) Lecture 1: Overview, Grammars, and Little Languages Jeremy R. Johnson.
Organization of Programming Languages (CSE452)
Chapter 1 :: Introduction
CS 415: Programming Languages Chapter 1 Aaron Bloomfield Fall 2005.
Copyright © 2005 Elsevier Chapter 1 :: Introduction Programming Language Pragmatics Michael L. Scott.
Introduction COMP104: Fundamentals and Methodology.
Programming Language and Paradigms
CS 355 – Programming Languages
CS 326 Programming Languages, Concepts and Implementation
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
Programming Languages and Design Lecture 1 Introduction to Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern University,
COP4020 Programming Languages
Chapter 1. Introduction.
CS 363 Comparative Programming Languages
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.
CS 330 Programming Languages 09 / 04 / 2008 Instructor: Michael Eckmann.
1 Programming Languages Tevfik Koşar Lecture - II January 19 th, 2006.
1 Programming Languages Marjan Sirjani Course web site:
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
Engr. Isabelo Jun D. Paat, ME-CoE Lecturer 1 Programming Languages.
1 Organization of Programming Languages-Cheng (Fall 2005) Organization of Programming Languages (CSE452) Instructor: Dr. B. Cheng Fall 2005.
COP4020 INTRODUCTION FALL COURSE DESCRIPTION Programming Languages introduces the fundamentals of the design and implementation of programming languages.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
Programming Language Theory 2014, 1 Chapter 1 :: Introduction Origin : Michael L. Scott School of Computer & Information Engineering,
The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. from Concepts of Programming Languages, 9th edition by Robert W. Sebesta,
Chapter 1 :: Introduction Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright © 2016 Elsevier.
Programming Language History and Evolution
Chapter 1. Introduction.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Teaching Compiler Design
Advanced Computer Systems
Computer Engineering Department Islamic University of Gaza
Compiler Design (40-414) Main Text Book:
Concepts of Programming Languages
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
Why study programming languages?
Chapter 1 Introduction.
PROGRAMMING LANGUAGES
CS 326 Programming Languages, Concepts and Implementation
CSCI-235 Micro-Computer Applications
CS 3304 Comparative Languages
CS 3304 Comparative Languages
Programming Language Design Concepts
Chapter 1 Introduction.
课程名 编译原理 Compiling Techniques
Programming Language History and Evolution
Programming COMP104: Fundamentals and Methodology Introduction.
Course supervisor: Lubna Siddiqui
Welcome to Programming Languages!
Ada – 1983 History’s largest design effort
CSE401 Introduction to Compiler Construction
COP4020 Programming Languages
CS 3304 Comparative Languages
Programming Languages 2nd edition Tucker and Noonan
CSE 341 Programming Languages Autumn 2003
High Level Programming Languages
CSE 341 Programming Languages Spring 2003
Principles of Programming Languages
CSE 341 Programming Languages Autumn 2003
강의 내용 및 방법 접근방법 리포트 시험 Lambda Calculus, Proof of Correctness
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 10: Compilers and Language Translation
School of Computer & Information Engineering,
Programming Languages, Preliminaries, History & Evolution
Presentation transcript:

CS 3304 Comparative Languages Lecture 1: Introduction 17 January 2012

Course Overview

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/

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)

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

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/

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

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.

Introduction

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.

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).

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.

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).

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++).

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). 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.

Language Groups Imperative: Declarative: 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.

ANTLR

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.

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).

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.

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.

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();} ;

ANTLRWorks

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.