Safely-Composable Type-Specific Languages (TSLs) Cyrus Omar Darya Kurilova Ligia Nistor Benjamin Chung Alex Potanin (Victoria University of Wellington)

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Types and Programming Languages Lecture 7 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Attribute Grammars Prabhaker Mateti ACK: Assembled from many sources.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
CS7100 (Prasad)L16-7AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
Compiler Principle and Technology Prof. Dongming LU Mar. 28th, 2014.
Domain Specific Embedded Languages Lecture 2, Designing and Using Combinators John Hughes.
Understand Web Page Development Software Development Fundamentals LESSON 4.1.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
Context-sensitive Analysis, II Ad-hoc syntax-directed translation, Symbol Tables, andTypes.
1 Dan Quinlan, Markus Schordan, Qing Yi Center for Applied Scientific Computing Lawrence Livermore National Laboratory Semantic-Driven Parallelization.
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
Copyright  Oracle Corporation, All rights reserved. 4 Creating Functions.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
CS784 (Prasad)L167AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
Type-Directed, Whitespace-Delimited Parsing for Embedded DSLs Cyrus Omar School of Computer Science Carnegie Mellon University [GlobalDSL13] Benjamin ChungAlex.
Extensible Type-Driven Parsing for Embedded DSLs in Wyvern Cyrus Omar Benjamin Chung Darya Kurilova Ligia Nistor Alex Potanin (Victoria University of Wellington)
Creating a Basic Web Page
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
CS 299 – Web Programming and Design Introduction to HTML.
1 WWW/HTML Basics CS What is the WWW? Perspective for this lecture A distributed document delivery system Uses a client-server model Main presentation.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Composable and Hygienic Typed Syntax Macros (TSMs) Cyrus Omar Chenglong (Stanley) Wang Jonathan Aldrich School of Computer Science Carnegie Mellon University.
1 Extending Java And Developing DSLs With Open Source Language Workbench JetBrains MPS Konstantin Solomatov JetBrains Lead Developer for JetBrains MPS.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Chapter 1 Introduction. Goal to learn about computers and programming to compile and run your first Java program to recognize compile-time and run-time.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
SRI International Bioinformatics 1 The Structured Advanced Query Page Tomer Altman & Mario Latendresse Bioinformatics Research Group SRI, International.
E0262 – MIS – Multimedia Storage Techniques XML (Extensible Markup Language  XML is a markup language for creating documents containing structured information.
A Little Language for Surveys: Constructing an Internal DSL in Ruby H. Conrad Cunningham Computer and Information Science University of Mississippi.
Safely Composable Type-Specific Languages (TSLs) Cyrus Omar Darya Kurilova Ligia Nistor Benjamin Chung Alex Potanin (Victoria University of Wellington)
Active Code Completion Cyrus Omar Computer Science School of Computer Science Carnegie Mellon University [ICSE12] YoungSeok Yoon Software Engineering Brad.
What on Earth? LEXEMETOKENPATTERN print p,r,i,n,t (leftpar( 4number4 *arith* 5number5 )rightpar) userAnswerID Letter followed by letters and digits “Game.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
Weaving a Debugging Aspect into Domain-Specific Language Grammars SAC ’05 PSC Track Santa Fe, New Mexico USA March 17, 2005 Hui Wu, Jeff Gray, Marjan Mernik,
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
1 JavaScript in Context. Server-Side Programming.
The Interpreter Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Presented by: Elena C. Ciobanu Mihai V. Ciobanu Kuntal Ghosh
Concepts and Realization of a Diagram Editor Generator Based on Hypergraph Transformation Author: Mark Minas Presenter: Song Gu.
Basic HTML Document Structure. Slide 2 Goals (XHTML HTML5) XHTML Separate document structure and content from document formatting HTML 5 Create a formal.
CMSC 330: Organization of Programming Languages Operational Semantics.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
JSON. JSON as an XML Alternative JSON is a light-weight alternative to XML for data- interchange JSON = JavaScript Object Notation It’s really language.
Copyright 2006 Pearson Addison-Wesley, 2008, 2012 Joey Paquet 1 Concordia University Department of Computer Science and Software Engineering SOEN6441 –
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
Application generation Peter Bell SystemsForge Peter Bell SystemsForge Beyond Scaffolding.
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Parsing 1 of 4: Grammars and Parse Trees
Chapter 3 – Describing Syntax
The Object-Oriented Thought Process Chapter 11
A Simple Syntax-Directed Translator
Interpreters Study Semantics of Programming Languages through interpreters (Executable Specifications) cs7100(Prasad) L8Interp.
Introduction to XHTML.
Section 3.2c Strings and Method Signatures
JavaScript an introduction.
CSE401 Introduction to Compiler Construction
T. Jumana Abu Shmais – AOU - Riyadh
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Presentation transcript:

Safely-Composable Type-Specific Languages (TSLs) Cyrus Omar Darya Kurilova Ligia Nistor Benjamin Chung Alex Potanin (Victoria University of Wellington) Jonathan Aldrich School of Computer Science Carnegie Mellon University

Specialized notations are useful. 2 There exists a positive constant M such that for all sufficiently large values of x, the absolute value of f(x) is at most M multiplied by x 2. MATHEMATICS SPECIALIZED NOTATION GENERAL-PURPOSE NOTATION

3 Cons(1, Cons(2, Cons(3, Cons(4, Cons(5, Nil))))) [1, 2, 3, 4, 5] DATA STRUCTURES SPECIALIZED NOTATION Specialized notations are useful. GENERAL-PURPOSE NOTATION

4 Concat(Digit, Concat(Digit, Concat(Char ':', Concat(Digit, Concat(Digit, Concat(ZeroOrMore(Whitespace), Group(Concat(Group(Or(Char 'a’, Char 'p')), Concat(Optional(Char '.'), Concat(Char 'm', Optional(Char '.'))))))))))) /\d\d:\d\d\w?((a|p)\.?m\.?)/ REGULAR EXPRESSIONS SPECIALIZED NOTATION Specialized notations are useful. GENERAL-PURPOSE NOTATION STRING NOTATION rx_from_str( " \\d\\d:\\d\\d\\w?((a|p)\\.?m\\.?) " ) (cf. Omar et al., ICSE 2012) parsing happens at run-time string literals have their own semantics

5 query(db, "SELECT * FROM users WHERE name='"+name+"' AND pwhash="+hash(pw)) query(db, Select(AllColumns, "users", [ WhereClause(AndPredicate(EqualsPredicate("name", StringLit(name)), EqualsPredicate("pwhash", IntLit(hash(pw))))])) query(db, ) ' ; DROP TABLE users -- QUERY LANGUAGES (SQL) Specialized notations are useful. SPECIALIZED NOTATION GENERAL-PURPOSE NOTATION STRING NOTATION injection attacks

6 HTMLElement({}, [BodyElement({}, [H1Element({}, [Text "Results for " + keyword]), ULElement({id: "results"}, to_list_items(exec_query(db, Select(["title", "snippet"], "products", [ WhereClause(InPredicate(StringLit(keyword), "title"))]))))]]] Results for {keyword} { to_list_items(query(db, )} html_from_str(" Results for "+keyword+" " + to_list_items(query(db, "SELECT title, snippet WHERE '"+keyword+"' in title FROM results")) + " ") TEMPLATE LANGUAGES Specialized notations are useful. SPECIALIZED NOTATION GENERAL-PURPOSE NOTATION STRING NOTATION parsing happens at run-time cross-site scripting attacks injection attacks awkwardness

7 Specialized notations typically require the cooperation of the language designer. NotationLanguageLibrary

8 String notations are ubiquitous. Classes in Java CorpusCount Total125,048 Constructor takes a string argument30,190 String argument is parsed19,317 There are more things in heaven and earth, Horatio, Than are dreamt of in your philosophy. - Hamlet Act 1, scene 5

9 Better approach: an extensible language where specialized notations can be distributed in libraries. NotationLanguageLibrary

Expressivity vs. Safety 10 We want to permit expressive syntax extensions. But if you give each extension too much control, they may interfere with one another in combination!

Example: Sugar* 11 Libraries can extend the base syntax of the language These extensions are imported transitively Extensions can interfere: Pairs vs. n-tuples – what does (1, 2) mean? HTML vs. XML – what does mean? Sets vs. Dicts – what does { } mean? Different implementations of the same abstraction [Erdweg et al, 2010; 2013]

The Argument So Far 12 Specialized notations are preferable to general-purpose notations and string notations in a variety of situations. It is unsustainable for language designers to attempt to anticipate all useful specialized notations. But it is also a bad idea to give users free reign to add arbitrary specialized notations to a base grammar.

Our Solution 13 Libraries cannot extend the base syntax of the language Instead, notation is associated with types. “Type-Specific Languages” (TSLs) A type-specific language can be used within delimiters to create values of that type. “Safely-Composable”

Wyvern 14 Goals: Secure web and mobile programming within a single statically-typed language. Compile-time support for a variety of domains: Security policies and architecture specifications Client-side programming (HTML, CSS) Server-side programming (Databases)

:html :head :title Product Listing Example 15 serve : (URL, HTML) -> () serve(`products.nameless.com` base language URL TSL, ~) HTML TSL :style {~ body { font-family: {bodyFont} } } :body :div[id=“search”] {SearchBox(“Products”)} :ul[id=“products”] {items_from_query(query(db, ))} CSS TSL String TSL SQL TSL

16  How do you enter a TSL?, ~) :html :head :title Product Listing :style {~ body { font-family: {bodyFont} } } :body :div[id=“search”] {SearchBox(“Products”)} :ul[id=“products”] {items_from_query(query(db, ))} serve(`products.nameless.com` base language URL TSL HTML TSL CSS TSL String TSL SQL TSL

TSL Delimiters 17 In the base language, several inline delimiters can be used to create a TSL literal: `TSL code here, ``inner backticks`` must be doubled` 'TSL code here, ''inner single quotes'' must be doubled' {TSL code here, {inner braces} must be balanced} [TSL code here, [inner brackets] must be balanced] must be balanced> If you use the block delimiter, tilde (~), there are no restrictions on the subsequent TSL literal. Indentation (“layout”) determines the end of the block. One block delimiter per line.

18 How do you enter a TSL?  How do you associate a TSL with a type?, ~) :html :head :title Product Listing :style {~ body { font-family: {bodyFont} } } :body :div[id=“search”] {SearchBox(“Products”)} :ul[id=“products”] {items_from_query(query(db, ))} serve(`products.nameless.com` base language URL TSL HTML TSL CSS TSL String TSL SQL TSL

19 casetype HTML = Text of String | DIVElement of (Attributes, HTML) | ULElement of (Attributes, HTML) |... metadata = new val parser : Parser = new def parse(s : TokenStream) : ExpAST = (* code to parse specialized HTML notation *) objtype Parser = def parse(s : TokenStream) : ExpAST Associating a Parser with a type casetype ExpAST = Var of ID | Lam of Var * ExpAST | Ap of Exp * Exp | CaseIntro of TyAST * String * ExpAST |...

20 casetype HTML = Text of String | DIVElement of (Attributes, HTML) | ULElement of (Attributes, HTML) |... metadata = new val parser : Parser = ~ start ::= “:body” children=start => {~ HTML.BodyElement(([], `children`)) } |... Associating a grammar with a type Grammars are TSLs for Parsers! Quotations are TSLs for ASTs!

21 How do you enter a TSL? How do you associate a TSL with a type?  How do you exit a TSL?, ~) :html :head :title Product Listing :style {~ body { font-family: {bodyFont} } } :body :div[id=“search”] {SearchBox(“Products”)} :ul[id=“products”] {items_from_query(query(db, ))} serve(`products.nameless.com` base language URL TSL HTML TSL CSS TSL String TSL SQL TSL

22 casetype HTML = Text of String | DIVElement of (Attributes, HTML) | ULElement of (Attributes, HTML) |... metaobject = new val parser : Parser = ~ start ::= “:body” children=start => {~ HTML.BodyElement(([], `children`)) } |... | “:style“ “{“ e=EXP[“}”] => {~ HTML.StyleElement(([], `e` : CSS)) } Exiting back to the base language

23 How do you enter a TSL? How do you associate a TSL with a type? How do you exit a TSL?  How do parsing and typechecking work?, ~) :html :head :title Product Listing :style {~ body { font-family: {bodyFont} } } :body :div[id=“search”] {SearchBox(“Products”)} :ul[id=“products”] {items_from_query(query(db, ))} serve(`products.nameless.com` base language URL TSL HTML TSL CSS TSL String TSL SQL TSL

24 Wyvern Abstract Syntax

25 Bidirectional Typechecking

26 Bidirectional Typechecking

27 How do you enter a TSL? How do you associate a TSL with a type? How do you exit a TSL? How do parsing and typechecking work?, ~) :html :head :title Product Listing :style {~ body { font-family: {bodyFont} } } :body :div[id=“search”] {SearchBox(“Products”)} :ul[id=“products”] {items_from_query(query(db, ))} serve(`products.nameless.com` base language URL TSL HTML TSL CSS TSL String TSL SQL TSL

Benefits 28 Modularity and Safe Composability DSLs are distributed in libraries, along with types No link-time errors possible Identifiability Can easily see when a DSL is being used Can determine which DSL is being used by identifying expected type DSLs always generate a value of the corresponding type Simplicity Single mechanism that can be described in a few sentences Specify a grammar in a natural manner within the type Flexibility A large number of literal forms can be seen as type-specific languages Whitespace-delimited blocks can contain arbitrary syntax

Types Organize Languages 29 Types represent an organizational unit for programming language semantics. Types are not only useful for traditional verification, but also safely-composable language-internal syntax extensions.

Limitations 30 Decidability of Compilation Because user-defined code is being evaluated during parsing and typechecking, compilation might not terminate. There is work on termination analyses for attribute grammars (Krishnan and Van Wyk, SLE 2012) Even projects like CompCert don’t place a huge emphasis on termination of parsing and typechecking. No story yet for editor support. Too much freedom a bad thing?

The Argument For a New Human-Parser Interaction 31 Specialized notations are preferable to general-purpose notations and string notations in a variety of situations. It is unsustainable for language designers to attempt to anticipate all useful specialized notations. But it is also a bad idea to give users free reign to add arbitrary specialized notations to a base grammar. Associating syntax extensions with types is a principled, practical approach to this problem with minor drawbacks.