600.429 FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.

Slides:



Advertisements
Similar presentations
Functional Programming Lecture 10 - type checking.
Advertisements

1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
WPSM Programming Language A simple language that transform simple data structure into complex xML format Wai Y. Wong Peter Chen Seema Gupta Miqdad Mohammed.
Datalogi A 1: 8/9. Book: Cay Horstmann: Big Java or Java Consepts.
College of Computer Science & Technology Compiler Construction Principles & Implementation Techniques -1- Compiler Construction Principles & Implementation.
CS 280 Data Structures Professor John Peterson. Lexer Project Questions? Must be in by Friday – solutions will be posted after class The next project.
Yu-Chen Kuo1 Chapter 2 A Simple One-Pass Compiler.
1 Python Chapter 4 Branching statements and loops © Samuel Marateck 2010.
CS 280 Data Structures Professor John Peterson. Lexer Project Questions? Must be in by Friday – solutions will be posted after class The next project.
1 Scanning Tokens. 2 Tokens When a Scanner reads input, it separates it into “tokens”  … at least when using methods like nextInt()  nextInt() takes.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
Getting Started with ANTLR Chapter 1. Domain Specific Languages DSLs are high-level languages designed for specific tasks DSLs include data formats, configuration.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
Beginning C++ Through Game Programming, Second Edition by Michael Dawson.
1 Week 4 Questions / Concerns Comments about Lab1 What’s due: Lab1 check off this week (see schedule) Homework #3 due Wednesday (Define grammar for your.
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.
Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Machine-independent code improvement Target code generation Machine-specific.
Lexical Analysis - An Introduction. The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source.
CS 461 – Oct. 7 Applications of CFLs: Compiling Scanning vs. parsing Expression grammars –Associativity –Precedence Programming language (handout)
CS 280 Data Structures Professor John Peterson. How Does Parsing Work? You need to know where to start (“statement”) This grammar is constructed so that.
Lexical Analysis Hira Waseem Lecture
Lexical Analyzer (Checker)
SCRIBE SUBMISSION GROUP 8 Date: 7/8/2013 By – IKHAR SUSHRUT MEGHSHYAM 11CS10017 Lexical Analyser Constructing Tokens State-Transition Diagram S-T Diagrams.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
CS 536 Fall Scanner Construction  Given a single string, automata and regular expressions retuned a Boolean answer: a given string is/is not in.
For loops in programming Assumes you have seen assignment statements and print statements.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
Review: Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Intermediate code generator Code optimizer Code generator Symbol.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
IN LINE FUNCTION AND MACRO Macro is processed at precompilation time. An Inline function is processed at compilation time. Example : let us consider this.
FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.
. n COMPILERS n n AND n n INTERPRETERS. -Compilers nA compiler is a program thatt reads a program written in one language - the source language- and translates.
Muhammad Idrees, Lecturer University of Lahore 1 Top-Down Parsing Top down parsing can be viewed as an attempt to find a leftmost derivation for an input.
Overview of Previous Lesson(s) Over View  Syntax-directed translation is done by attaching rules or program fragments to productions in a grammar. 
Syntax (2).
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
CSE 425: Syntax I Syntax and Semantics Syntax gives the structure of statements in a language –Allowed ordering, nesting, repetition, omission of symbols.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
Chapter 7 Continued Arrays & Strings. Strings as Class Members Strings frequently appear as members of classes. The next example, a variation of the objpart.
COP 3275 – Character Strings Instructor: Diego Rivera-Gutierrez.
FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.
Chpater 3. Outline The definition of Syntax The Definition of Semantic Most Common Methods of Describing Syntax.
Program Input and the Software Design Process ROBERT REAVES.
1 Introduction to Parsing. 2 Outline l Regular languages revisited l Parser overview Context-free grammars (CFG ’ s) l Derivations.
CSE1222: Lecture 1The Ohio State University1. Computing Basics  Computers CPU, Memory & Input/Output (IO)  Program Sequence of instructions for the.
FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Lecture 2 Compiler Design Lexical Analysis By lecturer Noor Dhia
CS 44 – Jan. 28 Pumping lemma #2 Applications to compiling.
FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University.
Lecture 9 Symbol Table and Attributed Grammars
Programming Languages
Lecture 2 Lexical Analysis
A Simple Syntax-Directed Translator
Constructing Precedence Table
Tutorial On Lex & Yacc.
CS510 Compiler Lecture 4.
Overview of Compilation The Compiler Front End
Overview of Compilation The Compiler Front End
PROGRAMMING LANGUAGES
-by Nisarg Vasavada (Compiled*)
CS 536 / Fall 2017 Introduction to programming languages and compilers
Basic Program Analysis: AST
MathWorks Compiler Course – Day 3
Programming Languages
Review: Compiler Phases:
Combinations of Functions; Composite Functions
Compilers B V Sai Aravind (11CS10008).
Presentation transcript:

FUNCTIONAL PROGRAMING AT WORK - HASKELL AND DOMAIN SPECIFIC LANGUAGES Dr. John Peterson Western State Colorado University

Project Pitch Let’s talk! I’ll set up wiki accounts tonight Good things: A well defined scope that allows an incremental approach Pre-existing infrastructure A compositional point of view (building-block pieces + combining functions) Novel semantic foundation (reactive programming, for example)

Quiz 4 Advantages / disadvantages of Haskell embedding Euterpea expressions that are the same in Euterpea but not Haskell. Why does this matter? What is the semantic model of Euterpea? What does a parser know that a grammar doesn’t?

Homework 5 eek_5

HW5 Project Organization Phase 1: a parsec parser that converts strings to tokens Create a data type for lexemes Drop whitespace Group characters for variables / numbers Represent indentation at the start of a line Don’t worry about error reporting Test before proceeding!

HW5 Phase 2 Deal with layout (indentation): Map a list of tokens that includes indentation to a list that drops indentation and replaces it with a new token, End Probably don’t need to use parsec Need to know all outer indentation levels (list of int will work)

Phase 2 Strategy Line indented more than current level Line indented at current level Line indented less than current level How do we recognize a new level? Assume all blocks have at least one statement Ignore blank lines in lexer

Phase 3 Strategy Use “End” to mark line end and block end Should look like grammar Use “try” for backtracking. Where do we need to worry about backtracking?

Questions?

Haskell Modules Modules – group a set of names in a file. Strictly a renaming construct – deals with visibility only. Use modules to encapsulate functionality – like ast.hs You can do selective export (export lists) or import (import lists) Hierarchical namespace uses “.”

Applicative and Functor se/latest/doc/html/Data-Functor.html#v: se/latest/doc/html/Control-Applicative.html#v: What do these infix operators do for parsers?

Inside parsec See Let’s look at “Char”, “Combinator”, and “Prim” How can we make combinators similar to those in Char with an arbitrary token stream type?