Chapter 6 Fundamentals of the Logical Paradigm. Programming Languages and Paradigms J. Fenwick, B. Kurtz, C. Norris (to be published in 2012)

Size: px
Start display at page:

Download "Chapter 6 Fundamentals of the Logical Paradigm. Programming Languages and Paradigms J. Fenwick, B. Kurtz, C. Norris (to be published in 2012)"

Transcription

1 Chapter 6 Fundamentals of the Logical Paradigm Programming Languages and Paradigms J. Fenwick, B. Kurtz, C. Norris (to be published in 2012)

2 Introduction In this second part of chapter 6 you will learn about Answering the Fundamental Questions for Prolog Name, binding, and scope Expressions and Horn Clauses Operators Flow control and unification Exception handling Concurrency A Case Study You will build a lexical analyzer (scanner) for Wren source code This is a somewhat tedious task of processing a source code file character by character, but Prolog is up to the task The scanner is essential to complete the parser and code generator in the next chapter

3 Name, Binding, and Scope - 1 Terms are either atoms, numbers, variables or compound terms An atom is a sequence of alphanumeric characters beginning with a lower case letter or a sequence of characters enclosed in single quotes jay Jay Fenwick Numeric literals are sequences of digits, e.g., 1234 Variables are represented by a sequence of letters, numbers and underscores, starting with either an upper case letter or an underscore Thefather _father

4 Name, Binding, and Scope - 2 Compound terms A list [1, a, [ hello ]]?- "abc" = [X, Y, Z]. X = 97 Y = 98 Z = 99 A functor is composed of an atom and a number of argument terms enclosed within parenthesis father('ethan', fatherof('baron')). sibling(x, Y) :- father(x, Z), father(y, Z), \+(X = Y). Prolog performs static scoping and the scope of a Prolog variable is the statement in which the variable appears

5 Expressions and Horn Clauses A Horn clause is one of the following two forms (P 1 ^ P 2 ^ ^ P n ) -> Q (R 1 ^ R 2 ^ ^ R n ) Written in Prolog this become Q :- P 1, P 2,, P n. % a rule R 1. R 2... R n. % a sequence of facts and (, ) has higher precedence than or ( ; ) Q :- P 1, P 2 ; P 3, P 4. is equivalent to: Q :- P 1, P 2. Q :- P 3, P 4.

6 Operators - 1 Operator Description Examples is Evaluates the expression on the right and determines whether it can be unified with the expression on the left. The expression on the left is not evaluated, thus the last example evaluates to no.?- X is 3. X = 3 yes?- 3 is 3. yes? is no =, \= Determines whether the left operand and the right operand can or can not be unified?- [X, Y] = [a, b]. X = a Y = b Yes?- X = 3. X = 3 yes?- X = Y. Y = X yes ==, \== Determines whether the left and right operands evaluate to the same values. In the first example, X is unbound and thus has no value.?- X == 3. no?- 3 * 4 == 3 * 4. yes?- X is 3, X == 3. X = 3 yes

7 Operators - 2 Operator Description Examples <, >, =<, >= Comparison operators. Notice the less than or equal to operator is =<?- 5 >= 4. yes?- X is 4, 3 =< X. X = 4 yes /, * Operators for division and multiplication?- X is 2 * 3, 10 > X. X = 6 yes?- X is 3, Y is 10/X. X = 3 Y = yes +, - Operators for addition and subtraction?- X is 3, Y is 4 - X + 7. X = 3 Y = 8 yes

8 Rules Flow Control Given a :- b, c, d. The interference engine tries to satisfy b first, then c, then d. If all 3 succeed, then a succeeds. Given a :- b, c. followed by a :- d, e. Rules of the same name are attempted from top to bottom; typically the base case is given first. A comparison of Haskell and Prolog mymember _ [] = False mymember x (y:z) = (x == y) mymember x z mymember(x, [X _]). mymember(x, [_ Y]) :- mymember(x, Y). How is the False case handled in Prolog?

9 Unification The constraints of the unification process are: Two predicates unify if they have the same name and arity and their arguments unify. For example, p(x, Y) does not unify with q(x, Y) because p and q are two different names. Two functor terms unify if they have the same name and arity and their terms unify. For example, f(a, b, X) unifies with f(a, Y, c) because the functors have the same name, arity and their terms unify. Two different constants do not unify. For example, fruit(apple) does not unify with fruit(banana). A constant unifies with a variable. For example, fruit(apple) unifies with fruit(x). Two variables unify. For example, fruit(x) unifies with fruit(y). Unification requires that all instances of the same variable in a rule must get the same value. For example, p(x, b, X) does not unify with p(y, Y, c) because Y must be b to make the second arguments equal and X must be c to make the third arguments equal. This makes the instantiation of the first predicate p(c, b, c) and the instantiation of the second predicate p(b, b, c).

10 Exception Handling The catch function takes three arguments. The first argument is the goal to be performed (comparable to the body of a try in Java). The second argument is the exception to be caught while solving the goal and may be a variable to allow any type of exception to be caught. The third argument is the function to be executed in the event of an exception. divide :- catch(causeerror, X, handleerror(x)). handleerror(x) :- write('caught Exception' : X), nl. causeerror :- result is 10 / 0.?- divide. Error:error(evaluation_error(zero_divisor),(is)/2) yes

11 Using threads fibonacci(1, 0). fibonacci(2, 1). Concurrency fibonacci(n, Result) :- N > 2, Nminus1 is N - 1, Nminus2 is N - 2, thread_create(callfibo(nminus1), Id1, []), thread_create(callfibo(nminus2), Id2, []), thread_join(id1, exited(n1)), thread_join(id2, exited(n2)), Result is N1 + N2. callfibo(n) :- fibonacci(n, Result), thread_exit(result).

12 Case Study: Building a Scanner for Wren Input to the scanner program gcd is var m,n : integer; begin read m; read n; while m <> n do if m < n then n := n - m else m := m - n end if end while; write m end Output from the scanner [program,ide(gcd),is,var,ide(m),comma,ide(n),colon,integer, semicolon,begin,read,ide(m),semicolon,read,ide(n),semicolon, while,ide(m),neq,ide(n),do,if,ide(m),less,ide(n),then,ide(n), assign,ide(n),minus,ide(m),else,ide(m),assign,ide(m),minus, ide(n),end,if,end,while,semicolon,write,ide(m),end,eop]

13 Opening the Source Code File The go rule go :- nl, write('>>> Lexical Analyzer for Wren <<<'), nl, write('enter name of source file: '), nl, getfilename(filename), nl, see(filename), scan(tokens), seen, write('scan successful'), nl,!, write(tokens), nl. Some new built-in Prolog rules write that displays the specified object on the console nl that forces a new line on the console see opens the file with the path specified by the user seen closes the file

14 The getfilename Rule The rule getfilename(f) :- get0(c),restfilename(c,cs),name(f,cs). restfilename(c,[c Cs]):-filechar(C),get0(D),restfilename(D,Cs). restfilename(c,[]). Some comments on this rule get0 fetches a single character from the file It is possible to write a single rule to fetch all the characters in the file name but it will be left recursive and always cause the Prolog interpreter to fail due to exhausting the stack space (see next slide) The restfilename rule is right recursive and will not blow up the Prolog interpreter Lab Activity: put these rules and the go rule into a scanner.pl file

15 Eliminating Left Recursion Left recursion occurs when the recursive call to the rule is the first item in the clauses to be satisfied iamrecursive(<params>) :- iamrecursive(<params>), This will cause Prolog to fail due to infinite recursion The general strategy to write right recursive Prolog code is to introduce a new rule The original rule only handles the first case, such as the first get0 in the getfilename rule The helper rule completes the operation using right recursion, as in the restfilename rule We will use this strategy several times in the scanner program

16 Reserved Words The reserved words in Wren are program,is,begin,end,var,integer,boolean,read,write, while,do,if,then,else,skip,or,and,true,false,not Here are the facts to recognize the first four reserved words reswd(program). reswd(is). reswd(begin). reswd(end). Lab Activity: Write the facts for the remaining reserved words and add to the scanner.pl file

17 Single Character Tokens Many single characters in Wren, such as (, will become full word tokens, such as lparen single(40,lparen). 40 is the ASCII code for a left parenthesis Lab Activity: Using a ASCII table write additional single facts for the following characters: rparen, times, plus, comma, minus, divides, semicolon, equal Some Prolog interpreters, such as gprolog, require rules or facts with the same name and arity (number of parameters) to be grouped into contiguous code; make sure you do this.

18 Single or Double Character Tokens Some single characters, such as <, may be part of a single character token, less, or a double character token, <= which is the token lteq double(58,colon). double(60,less). double(62,grtr). Here are a sample rule for a pair of characters pair(58,61,assign). Lab Activity: Add additional pair rules for <> (neq), <= (lteq), and >= (gteq).

19 Recognizing Groups of Characters Character groups, such as digits, lower case characters, and upper case characters are contiguous within a range of ASCII values Here is a rule for lower case lower(c) :- 97=<C,C=<122. % a-z Lab Activity: Add two additional rules to test if a character is upper case, name it upper, or a digit, name it digit.

20 Other Utility Fact and Rules space(32). tabch(9). period(46). slash(47). endline(10). endfile(26). endfile(-1). whitespace(c) :- space(c) ; tabch(c) ; endline(c). idchar(c) :- lower(c) ; digit(c). filechar(c) :- lower(c); upper(c); digit(c); period(c); slash(c). Lab Activity: Add these to your scanner.pl file

21 Building the scan Rule The scan and getch rules scan([t Lt]) :- tab(4), getch(c), gettoken(c, T, D), restprog(t, D, Lt). getch(c):- get0(c),(endline(c),nl,tab(4); endfile(c),nl; put(c)). Most of the work is done by the gettoken rule Here is the restprog rule restprog(eop,c,[]). % end of file in previous character restprog(t,c,[u Lt]):- gettoken(c,u,d),restprog(u,d,lt).

22 The gettoken rules - 1 There is a long sequence of rules; we add them one by one; the general form of the rule is: gettoken(<current char>, token, <next char>) Here is the first example when end of file is encountered. gettoken(c, eop, 0) :- endfile(c). Lab Activity: Write the gettoken rule for the case when a single character unambiguously corresponds to a token, such as ( corresponding to lparen.

23 The gettoken rules - 2 The next rule is when the current character is one of the three characters that either corresponds to a single character token or a two character token gettoken(c, T, E) :- double(c,u),getch(d), (pair(c,d,t),getch(e); T=U,E=D). Lab Activity: Keep your scanner.pl file up to date by adding the gettoken rules as discussed

24 The gettoken rules - 3 A lower case letter indicates a start of an identifier or a reserved word; the following rule takes care of both cases gettoken(c, T, E) :- lower(c), getch(d), restid(d, Lc, E), name(i, [C Lc]), (reswd(i),t=i ; T=ide(I)). Lab Activity: Write the restid rules. The general form of these rules are: restid(<current char>, seq of ASCII values, <next char>) The first rule is the general recursive case where you keep fetching characters until the idchar goal fails. The second rule handles this case where the current character is not an idchar; it matches the first to third arguments and returns the empty list of characters as the second argument

25 The gettoken rules - 4 Lab Activity: Write the gettoken rule for integer literals. Suppose the literal is the sequence of digits 123 then the token returned is num(123). You will need a restnum rule that is very similar to the restid in the previous exercise. To complete this exercise you are writing a single gettoken rule and two restnum rules, the second handling the base case. The final two gettoken rules are gettoken(c, T, E) :- whitespace(c), getch(d), gettoken(d,t,e). gettoken(c, T, E) :- write('illegal character: '), put(c), nl, abort. The first rules removes white space and the second one (the final gettoken) reports an illegal character and aborts.

26 A Word about Singleton Variables Prolog will issue a warning if a rule contains a singleton variable; that is, a variable that appears only once in the rule and is not used elsewhere. gettoken(c, T, E) :- write('illegal character: '), put(c), nl, abort. How you can remove singletons You can remove any singleton variable by replacing it with the _ character This will remove the singleton warning The argument for keeping singletons From the compiler/interpreter perspective a singleton binds a name to a value unnecessarily From a documentation perspective, the singleton says what the term represents, it makes the rule more readable and consistent for a human programmer

27 Tools for Debugging The spy rules You can either spy on everything or on a particular predicate (the more common usage)?- spy(gettoken). Spy will show on the console the call to the specified predicate along with the result produced The rule nospy will turn off a spy point The trace rules Turn on with trace(gettoken) and turn off with notrace This causes the program to enter single step mode When you are in single-step mode there are a variety of options on how to proceed; pressing return will continue the single-step mode.

28 Completing the Scanner Enter all of your code in the scanner.pl file If there are any missing rules or facts, complete them Test your program with the gcd program stored in an external file as given at the start of section 6.4 Debugging may be tedious, but often that is the life of a computer scientist Now test your scanner with the product and divide programs from section 2.1; fix any remaining errors

Scanning. Reading Tokens. Reserved Words. Identifiers and Reserved Words: Recognizing Kinds of Characters

Scanning. Reading Tokens. Reserved Words. Identifiers and Reserved Words: Recognizing Kinds of Characters Character List Scanning Scanner Token List Recognizing Kinds of Characters lower(c) :- 97=

More information

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) Introduction This semester, through a project split into 3 phases, we are going

More information

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler.

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler. Name: Midterm Exam PID: This is a closed-book exam; you may not use any tools besides a pen. You have 75 minutes to answer all questions. There are a total of 75 points available. Please write legibly;

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

CSE 413 Programming Languages & Implementation. Hal Perkins Autumn 2012 Grammars, Scanners & Regular Expressions

CSE 413 Programming Languages & Implementation. Hal Perkins Autumn 2012 Grammars, Scanners & Regular Expressions CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Grammars, Scanners & Regular Expressions 1 Agenda Overview of language recognizers Basic concepts of formal grammars Scanner Theory

More information

Topic B: Backtracking and Lists

Topic B: Backtracking and Lists Topic B: Backtracking and Lists 1 Recommended Exercises and Readings From Programming in Prolog (5 th Ed.) Readings: Chapter 3 2 Searching for the Answer In order for a Prolog program to report the correct

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

A Pascal program. Input from the file is read to a buffer program buffer. program xyz(input, output) --- begin A := B + C * 2 end.

A Pascal program. Input from the file is read to a buffer program buffer. program xyz(input, output) --- begin A := B + C * 2 end. A Pascal program program xyz(input, output); var A, B, C: integer; begin A := B + C * 2 end. Input from the file is read to a buffer program buffer program xyz(input, output) --- begin A := B + C * 2 end.

More information

CSEP 501 Compilers. Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter /8/ Hal Perkins & UW CSE B-1

CSEP 501 Compilers. Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter /8/ Hal Perkins & UW CSE B-1 CSEP 501 Compilers Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter 2008 1/8/2008 2002-08 Hal Perkins & UW CSE B-1 Agenda Basic concepts of formal grammars (review) Regular expressions

More information

Prolog Programming. Lecture Module 8

Prolog Programming. Lecture Module 8 Prolog Programming Lecture Module 8 Prolog Language Prolog is unique in its ability to infer facts from the given facts and rules. In Prolog, an order of clauses in the program and goals in the body of

More information

Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3.

Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3. 1 Lecture Overview Prolog 1. Introduction Interaction Terms 2. Clauses and predicates Clauses Predicates Variables 3. Satisfying goals 2 Prolog A standard free Prolog can be downloaded from http://www.swi-prolog.org

More information

ML 4 A Lexer for OCaml s Type System

ML 4 A Lexer for OCaml s Type System ML 4 A Lexer for OCaml s Type System CS 421 Fall 2017 Revision 1.0 Assigned October 26, 2017 Due November 2, 2017 Extension November 4, 2017 1 Change Log 1.0 Initial Release. 2 Overview To complete this

More information

DINO. Language Reference Manual. Author: Manu Jain

DINO. Language Reference Manual. Author: Manu Jain DINO Language Reference Manual Author: Manu Jain Table of Contents TABLE OF CONTENTS...2 1. INTRODUCTION...3 2. LEXICAL CONVENTIONS...3 2.1. TOKENS...3 2.2. COMMENTS...3 2.3. IDENTIFIERS...3 2.4. KEYWORDS...3

More information

CSE 413 Programming Languages & Implementation. Hal Perkins Winter 2019 Grammars, Scanners & Regular Expressions

CSE 413 Programming Languages & Implementation. Hal Perkins Winter 2019 Grammars, Scanners & Regular Expressions CSE 413 Programming Languages & Implementation Hal Perkins Winter 2019 Grammars, Scanners & Regular Expressions 1 Agenda Overview of language recognizers Basic concepts of formal grammars Scanner Theory

More information

Part I Logic programming paradigm

Part I Logic programming paradigm Part I Logic programming paradigm 1 Logic programming and pure Prolog 1.1 Introduction 3 1.2 Syntax 4 1.3 The meaning of a program 7 1.4 Computing with equations 9 1.5 Prolog: the first steps 15 1.6 Two

More information

MP 3 A Lexer for MiniJava

MP 3 A Lexer for MiniJava MP 3 A Lexer for MiniJava CS 421 Spring 2010 Revision 1.0 Assigned Tuesday, February 2, 2010 Due Monday, February 8, at 10:00pm Extension 48 hours (20% penalty) Total points 50 (+5 extra credit) 1 Change

More information

Programming Language Concepts, cs2104 Lecture 04 ( )

Programming Language Concepts, cs2104 Lecture 04 ( ) Programming Language Concepts, cs2104 Lecture 04 (2003-08-29) Seif Haridi Department of Computer Science, NUS haridi@comp.nus.edu.sg 2003-09-05 S. Haridi, CS2104, L04 (slides: C. Schulte, S. Haridi) 1

More information

On Academic Dishonesty. Declarative Computation Model. Single assignment store. Single assignment store (2) Single assignment store (3)

On Academic Dishonesty. Declarative Computation Model. Single assignment store. Single assignment store (2) Single assignment store (3) Declarative Computation Model Single assignment store (VRH 2.2) Kernel language syntax (VRH 2.3) Carlos Varela RPI October 6, 2009 Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL On Academic

More information

PLT 4115 LRM: JaTesté

PLT 4115 LRM: JaTesté PLT 4115 LRM: JaTesté Andrew Grant amg2215@columbia.edu Jemma Losh jal2285@columbia.edu Jake Weissman jdw2159@columbia.edu March 7, 2016 Jared Weiss jbw2140@columbia.edu 1 Contents 1 Introduction 4 2 Lexical

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

Typescript on LLVM Language Reference Manual

Typescript on LLVM Language Reference Manual Typescript on LLVM Language Reference Manual Ratheet Pandya UNI: rp2707 COMS 4115 H01 (CVN) 1. Introduction 2. Lexical Conventions 2.1 Tokens 2.2 Comments 2.3 Identifiers 2.4 Reserved Keywords 2.5 String

More information

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9

More information

Java+- Language Reference Manual

Java+- Language Reference Manual Fall 2016 COMS4115 Programming Languages & Translators Java+- Language Reference Manual Authors Ashley Daguanno (ad3079) - Manager Anna Wen (aw2802) - Tester Tin Nilar Hlaing (th2520) - Systems Architect

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Spoke. Language Reference Manual* CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS. William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03

Spoke. Language Reference Manual* CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS. William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03 CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS Spoke Language Reference Manual* William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03 (yw2347, ct2459, zy2147, xc2180)@columbia.edu Columbia University,

More information

Cellular Automata Language (CAL) Language Reference Manual

Cellular Automata Language (CAL) Language Reference Manual Cellular Automata Language (CAL) Language Reference Manual Calvin Hu, Nathan Keane, Eugene Kim {ch2880, nak2126, esk2152@columbia.edu Columbia University COMS 4115: Programming Languages and Translators

More information

Assignment 1. Due 08/28/17

Assignment 1. Due 08/28/17 Assignment 1. Due 08/28/17 1. Implement Scanner for Micro language (Micro Scanner) employing routines considered in class. When you call Scanner in a the output must be a list of tokens. Scan the following

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Haskell Programming

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Haskell Programming About the Tutorial Haskell is a widely used purely functional language. Functional programming is based on mathematical functions. Besides Haskell, some of the other popular languages that follow Functional

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

YOLOP Language Reference Manual

YOLOP Language Reference Manual YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language

More information

Lecture 16: Logic Programming in Prolog

Lecture 16: Logic Programming in Prolog Lecture 16: Logic Programming in Prolog COMP 524 Programming Language Concepts Stephen Olivier March 26, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts Goal of

More information

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016 CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016 In this course you will start by building a compiler for a language called Xi. This is an imperative,

More information

COP4020 Programming Assignment 1 - Spring 2011

COP4020 Programming Assignment 1 - Spring 2011 COP4020 Programming Assignment 1 - Spring 2011 In this programming assignment we design and implement a small imperative programming language Micro-PL. To execute Mirco-PL code we translate the code to

More information

Lecture 5 Tao Wang 1

Lecture 5 Tao Wang 1 Lecture 5 Tao Wang 1 Objectives In this chapter, you will learn about: Selection criteria Relational operators Logical operators The if-else statement Nested if statements C++ for Engineers and Scientists,

More information

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals VENTURE COMS 4115 - Language Reference Manual Zach Adler (zpa2001), Ben Carlin (bc2620), Naina Sahrawat (ns3001), James Sands (js4597) Section 1. Lexical Elements 1.1 Identifiers An identifier in VENTURE

More information

Declarative Programming Prolog CS360

Declarative Programming Prolog CS360 Declaratie Programming Prolog CS360 Terms Numerical literals String literals Ø By default, any string that starts is all lowercase Ø Use single quotes for anything else Atoms Ø Essentially, strings Ø Also,

More information

Parsing. Zhenjiang Hu. May 31, June 7, June 14, All Right Reserved. National Institute of Informatics

Parsing. Zhenjiang Hu. May 31, June 7, June 14, All Right Reserved. National Institute of Informatics National Institute of Informatics May 31, June 7, June 14, 2010 All Right Reserved. Outline I 1 Parser Type 2 Monad Parser Monad 3 Derived Primitives 4 5 6 Outline Parser Type 1 Parser Type 2 3 4 5 6 What

More information

GBIL: Generic Binary Instrumentation Language. Language Reference Manual. By: Andrew Calvano. COMS W4115 Fall 2015 CVN

GBIL: Generic Binary Instrumentation Language. Language Reference Manual. By: Andrew Calvano. COMS W4115 Fall 2015 CVN GBIL: Generic Binary Instrumentation Language Language Reference Manual By: Andrew Calvano COMS W4115 Fall 2015 CVN Table of Contents 1) Introduction 2) Lexical Conventions 1. Tokens 2. Whitespace 3. Comments

More information

Lecture 4: The Declarative Sequential Kernel Language. September 5th 2011

Lecture 4: The Declarative Sequential Kernel Language. September 5th 2011 Lecture 4: The Declarative Sequential Kernel Language September 5th 2011 1 Lecture Outline Syntactic Analysis of Programs contd Scanning contd The Declarative Kernel Language Introduction Syntax of the

More information

XQ: An XML Query Language Language Reference Manual

XQ: An XML Query Language Language Reference Manual XQ: An XML Query Language Language Reference Manual Kin Ng kn2006@columbia.edu 1. Introduction XQ is a query language for XML documents. This language enables programmers to express queries in a few simple

More information

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast! Lexical Analysis Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast! Compiler Passes Analysis of input program (front-end) character stream

More information

COMP 9416, session 1, 2006 p. 1. Datalog. COMP 9416, session 1, 2006

COMP 9416, session 1, 2006 p. 1. Datalog. COMP 9416, session 1, 2006 OMP 9416, session 1, 2006 p. 1 Datalog OMP 9416, session 1, 2006 OMP 9416, session 1, 2006 p. 2 Atoms, integers and variables The fact "person(socrates).", the fact "sum(2,3,y)." and the rule "mortal(x)

More information

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567)

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567) 1 M/s Managing distributed workloads Language Reference Manual Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567) Table of Contents 1. Introduction 2. Lexical elements 2.1 Comments 2.2

More information

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Ordinary Differential Equation Solver Language (ODESL) Reference Manual Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE

More information

Wan Hussain Wan Ishak

Wan Hussain Wan Ishak February 2 nd Session 2014/2015 (A142) Wan Hussain Wan Ishak School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) 04-9285150 (E) hussain@uum.edu.my (U) http://wanhussain.com

More information

Announcement. Overview. LISP: A Quick Overview. Outline of Writing and Running Lisp.

Announcement. Overview. LISP: A Quick Overview. Outline of Writing and Running Lisp. Overview Announcement Announcement Lisp Basics CMUCL to be available on sun.cs. You may use GNU Common List (GCL http://www.gnu.org/software/gcl/ which is available on most Linux platforms. There is also

More information

A Simple Syntax-Directed Translator

A Simple Syntax-Directed Translator Chapter 2 A Simple Syntax-Directed Translator 1-1 Introduction The analysis phase of a compiler breaks up a source program into constituent pieces and produces an internal representation for it, called

More information

PROgramming in LOGic PROLOG Recursion, Lists & Predicates

PROgramming in LOGic PROLOG Recursion, Lists & Predicates PROgramming in LOGic PROLOG Recursion, Lists & Predicates CSC9Y4 1 Recursion Recursion in Prolog means placing in the body of a rule a call to the predicate which occurs in the head of the rule. Here is

More information

B E C Y. Reference Manual

B E C Y. Reference Manual B E C Y Tabular data manipulation language Reference Manual Authors: Bong Koh Eunchul Bae Cesar Vichdo Yongju Bang bdk2109@columbia.edu eb2263@columbia.edu cv2139@columbia.edu yb2149@columbia.edu 1 1.

More information

corgi Language Reference Manual COMS W4115

corgi Language Reference Manual COMS W4115 corgi Language Reference Manual COMS W4115 Philippe Guillaume Losembe (pvl2109) Alisha Sindhwani (as4312) Melissa O Sullivan (mko2110) Justin Zhao (jxz2101) October 27, 2014 Chapter 1: Introduction corgi

More information

VLC : Language Reference Manual

VLC : Language Reference Manual VLC : Language Reference Manual Table Of Contents 1. Introduction 2. Types and Declarations 2a. Primitives 2b. Non-primitives - Strings - Arrays 3. Lexical conventions 3a. Whitespace 3b. Comments 3c. Identifiers

More information

UNIVERSITY OF COLUMBIA ADL++ Architecture Description Language. Alan Khara 5/14/2014

UNIVERSITY OF COLUMBIA ADL++ Architecture Description Language. Alan Khara 5/14/2014 UNIVERSITY OF COLUMBIA ADL++ Architecture Description Language Alan Khara 5/14/2014 This report is submitted to fulfill final requirements for the course COMS W4115 at Columbia University. 1 P a g e Contents

More information

GAWK Language Reference Manual

GAWK Language Reference Manual GAWK Language Reference Manual Albert Cui, Karen Nan, Mei-Vern Then, & Michael Raimi So good, you re gonna GAWK. 1.0 Introduction This manual describes the GAWK language and is meant to be used as a reliable

More information

Project 1: Scheme Pretty-Printer

Project 1: Scheme Pretty-Printer Project 1: Scheme Pretty-Printer CSC 4101, Fall 2017 Due: 7 October 2017 For this programming assignment, you will implement a pretty-printer for a subset of Scheme in either C++ or Java. The code should

More information

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]

More information

Chapter 16. Logic Programming. Topics. Unification. Resolution. Prolog s Search Strategy. Prolog s Search Strategy

Chapter 16. Logic Programming. Topics. Unification. Resolution. Prolog s Search Strategy. Prolog s Search Strategy Topics Chapter 16 Logic Programming Summary (resolution, unification, Prolog search strategy ) Disjoint goals The cut operator Negative goals Predicate fail Debugger / tracer Lists 2 Resolution Resolution

More information

TML Language Reference Manual

TML Language Reference Manual TML Language Reference Manual Jiabin Hu (jh3240) Akash Sharma (as4122) Shuai Sun (ss4088) Yan Zou (yz2437) Columbia University October 31, 2011 1 Contents 1 Introduction 4 2 Lexical Conventions 4 2.1 Character

More information

Wan Hussain Wan Ishak

Wan Hussain Wan Ishak September 1 st Session 2014/2015 (A141) Wan Hussain Wan Ishak School of Computing UUM College of Arts and Sciences Universiti Utara Malaysia (P) 04-9285150 (E) hussain@uum.edu.my (U) http://wanhussain.com

More information

The object level in Prolog. Meta-level predicates and operators. Contents. The flow of computation. The meta level in Prolog

The object level in Prolog. Meta-level predicates and operators. Contents. The flow of computation. The meta level in Prolog Lecture 8 Meta-level predicates and operators Contents Object level vs. meta level Controlling flow of computation Checking and dismantling expressions Comparison operators The object level in Prolog Prolog

More information

CS321 Languages and Compiler Design I. Winter 2012 Lecture 4

CS321 Languages and Compiler Design I. Winter 2012 Lecture 4 CS321 Languages and Compiler Design I Winter 2012 Lecture 4 1 LEXICAL ANALYSIS Convert source file characters into token stream. Remove content-free characters (comments, whitespace,...) Detect lexical

More information

MP 3 A Lexer for MiniJava

MP 3 A Lexer for MiniJava MP 3 A Lexer for MiniJava CS 421 Spring 2012 Revision 1.0 Assigned Wednesday, February 1, 2012 Due Tuesday, February 7, at 09:30 Extension 48 hours (penalty 20% of total points possible) Total points 43

More information

Language Reference Manual

Language Reference Manual TAPE: A File Handling Language Language Reference Manual Tianhua Fang (tf2377) Alexander Sato (as4628) Priscilla Wang (pyw2102) Edwin Chan (cc3919) Programming Languages and Translators COMSW 4115 Fall

More information

GraphQuil Language Reference Manual COMS W4115

GraphQuil Language Reference Manual COMS W4115 GraphQuil Language Reference Manual COMS W4115 Steven Weiner (Systems Architect), Jon Paul (Manager), John Heizelman (Language Guru), Gemma Ragozzine (Tester) Chapter 1 - Introduction Chapter 2 - Types

More information

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Fluency with Information Technology Third Edition by Lawrence Snyder Overview: Programming Concepts Programming: Act of formulating

More information

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Fluency with Information Technology Third Edition by Lawrence Snyder Overview: Programming Concepts Programming: Act of formulating

More information

2.2 Syntax Definition

2.2 Syntax Definition 42 CHAPTER 2. A SIMPLE SYNTAX-DIRECTED TRANSLATOR sequence of "three-address" instructions; a more complete example appears in Fig. 2.2. This form of intermediate code takes its name from instructions

More information

Logic Languages. Hwansoo Han

Logic Languages. Hwansoo Han Logic Languages Hwansoo Han Logic Programming Based on first-order predicate calculus Operators Conjunction, disjunction, negation, implication Universal and existential quantifiers E A x for all x...

More information

Stating the obvious, people and computers do not speak the same language.

Stating the obvious, people and computers do not speak the same language. 3.4 SYSTEM SOFTWARE 3.4.3 TRANSLATION SOFTWARE INTRODUCTION Stating the obvious, people and computers do not speak the same language. People have to write programs in order to instruct a computer what

More information

Introduction to Logic Programming in Prolog 1 / 39

Introduction to Logic Programming in Prolog 1 / 39 Introduction to Logic Programming in Prolog 1 / 39 Outline Programming paradigms Logic programming basics Introduction to Prolog Predicates, queries, and rules Understanding the query engine Goal search

More information

Chapter 6. Predefined Predicates

Chapter 6. Predefined Predicates Advanced Logic Programming https://sewiki.iai.uni-bonn.de/teaching/lectures/alp/2017/ Chapter 6. Predefined Predicates Updated: 12 June, 2017 Reorganized entire chapter Input and output Exception handling

More information

EZ- ASCII: Language Reference Manual

EZ- ASCII: Language Reference Manual EZ- ASCII: Language Reference Manual Dmitriy Gromov (dg2720), Feifei Zhong (fz2185), Yilei Wang (yw2493), Xin Ye (xy2190), Joe Lee (jyl2157) Table of Contents 1 Program Definition... 3 2 Lexical Conventions...

More information

COMS W4115 Programming Languages & Translators FALL2008. Reference Manual. VideO Processing Language (VOPL) Oct.19 th, 2008

COMS W4115 Programming Languages & Translators FALL2008. Reference Manual. VideO Processing Language (VOPL) Oct.19 th, 2008 Reference Manual VideO Processing Language (VOPL) Oct.19 th, 2008 Baolin Shao bs2530 Xuyang Shi xs2137 Huning Dai ( hd2210 ) Jia Li jl3272 Table of Content 1. Introduction... 4 2. Document Convention...

More information

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF)

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF) Chapter 3: Describing Syntax and Semantics Introduction Formal methods of describing syntax (BNF) We can analyze syntax of a computer program on two levels: 1. Lexical level 2. Syntactic level Lexical

More information

Languages, Automata, Regular Expressions & Scanners. Winter /8/ Hal Perkins & UW CSE B-1

Languages, Automata, Regular Expressions & Scanners. Winter /8/ Hal Perkins & UW CSE B-1 CSE 401 Compilers Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter 2010 1/8/2010 2002-10 Hal Perkins & UW CSE B-1 Agenda Quick review of basic concepts of formal grammars Regular

More information

Functional Programming

Functional Programming Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used

More information

IKI30820 Logic Programming Input and Output Slide 07

IKI30820 Logic Programming Input and Output Slide 07 IKI30820 Logic Programming Input and Output Slide 07 Ari Saptawijaya (slides) Adila A. Krisnadhi (L A T E Xadaptation) Fakultas Ilmu Komputer Universitas Indonesia 2009/2010 Semester Gasal AS,AAK (Fasilkom

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

d-file Language Reference Manual

d-file Language Reference Manual Erwin Polio Amrita Rajagopal Anton Ushakov Howie Vegter d-file Language Reference Manual COMS 4115.001 Thursday, October 20, 2005 Fall 2005 Columbia University New York, New York Note: Much of the content

More information

Functional Programming Languages (FPL)

Functional Programming Languages (FPL) Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional

More information

Prolog. Intro to Logic Programming

Prolog. Intro to Logic Programming Prolog Logic programming (declarative) Goals and subgoals Prolog Syntax Database example rule order, subgoal order, argument invertibility, backtracking model of execution, negation by failure, variables

More information

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

Mirage. Language Reference Manual. Image drawn using Mirage 1.1. Columbia University COMS W4115 Programming Languages and Translators Fall 2006

Mirage. Language Reference Manual. Image drawn using Mirage 1.1. Columbia University COMS W4115 Programming Languages and Translators Fall 2006 Mirage Language Reference Manual Image drawn using Mirage 1.1 Columbia University COMS W4115 Programming Languages and Translators Fall 2006 Prof. Stephen Edwards Team Members: Abhilash I ai2160@columbia.edu

More information

Logic Programming. Efficiency Issues. Temur Kutsia

Logic Programming. Efficiency Issues. Temur Kutsia Logic Programming Efficiency Issues Temur Kutsia Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria kutsia@risc.uni-linz.ac.at Efficiency Issues in Prolog Narrow the

More information

Programming Paradigms

Programming Paradigms David Ng June 30, 2017 Contents 1 May 17, 2017 3 1.1 Programming Paradigm............................ 3 1.2 Languages.................................... 3 1.3 Haskell.....................................

More information

Lecture 11: Feb. 10, 2016

Lecture 11: Feb. 10, 2016 CS323: AI (Hands on with Prolog) Spring 2016 Lecturer: K.R. Chowdhary Lecture 11: Feb. 10, 2016 : Professor of CS (VF) Disclaimer: These notes have not been subjected to the usual scrutiny reserved for

More information

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; } Ex: The difference between Compiler and Interpreter The interpreter actually carries out the computations specified in the source program. In other words, the output of a compiler is a program, whereas

More information

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA. R13 SET - 1 III B. Tech I Semester Regular Examinations, November - 2015 1 a) What constitutes a programming environment? [3M] b) What mixed-mode assignments are allowed in C and Java? [4M] c) What is

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

SEMANTIC ANALYSIS TYPES AND DECLARATIONS SEMANTIC ANALYSIS CS 403: Type Checking Stefan D. Bruda Winter 2015 Parsing only verifies that the program consists of tokens arranged in a syntactically valid combination now we move to check whether

More information

Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions

Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions Recursion and Induction: Haskell; Primitive Data Types; Writing Function Definitions Greg Plaxton Theory in Programming Practice, Spring 2005 Department of Computer Science University of Texas at Austin

More information

TaML. Language Reference Manual. Adam Dossa (aid2112) Qiuzi Shangguan (qs2130) Maria Taku (mat2185) Le Chang (lc2879) Columbia University

TaML. Language Reference Manual. Adam Dossa (aid2112) Qiuzi Shangguan (qs2130) Maria Taku (mat2185) Le Chang (lc2879) Columbia University TaML Language Reference Manual Adam Dossa (aid2112) Qiuzi Shangguan (qs2130) Maria Taku (mat2185) Le Chang (lc2879) Columbia University 29h October 2012 Table of Contents 1. Introduction... 4 2. Lexical

More information

Programming Paradigms

Programming Paradigms PP 2016/17 Unit 7 Debugging and the Box Model 1/10 Programming Paradigms Unit 7 Debugging and the Box Model J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE PP 2016/17 Unit 7

More information

Chapter 17. Fundamental Concepts Expressed in JavaScript

Chapter 17. Fundamental Concepts Expressed in JavaScript Chapter 17 Fundamental Concepts Expressed in JavaScript Learning Objectives Tell the difference between name, value, and variable List three basic data types and the rules for specifying them in a program

More information

Fundamentals of Prolog

Fundamentals of Prolog Fundamentals of Prolog Prof. Geraint A. Wiggins Centre for Cognition, Computation and Culture Goldsmiths College, University of London Contents Summary of Lecture 1 What makes a good Prolog program? What

More information

B The SLLGEN Parsing System

B The SLLGEN Parsing System B The SLLGEN Parsing System Programs are just strings of characters. In order to process a program, we need to group these characters into meaningful units. This grouping is usually divided into two stages:

More information

CSE 401/M501 Compilers

CSE 401/M501 Compilers CSE 401/M501 Compilers Languages, Automata, Regular Expressions & Scanners Hal Perkins Spring 2018 UW CSE 401/M501 Spring 2018 B-1 Administrivia No sections this week Read: textbook ch. 1 and sec. 2.1-2.4

More information

CHIL CSS HTML Integrated Language

CHIL CSS HTML Integrated Language CHIL CSS HTML Integrated Language Programming Languages and Translators Fall 2013 Authors: Gil Chen Zion gc2466 Ami Kumar ak3284 Annania Melaku amm2324 Isaac White iaw2105 Professor: Prof. Stephen A. Edwards

More information

Derived from PROgramming in LOGic (1972) Prolog and LISP - two most popular AI languages. Prolog programs based on predicate logic using Horn clauses

Derived from PROgramming in LOGic (1972) Prolog and LISP - two most popular AI languages. Prolog programs based on predicate logic using Horn clauses Prolog Programming Derived from PROgramming in LOGic (1972) Good at expressing logical relationships between concepts Prolog and LISP - two most popular AI languages Execution of a Prolog program is a

More information

Alternation. Kleene Closure. Definition of Regular Expressions

Alternation. Kleene Closure. Definition of Regular Expressions Alternation Small finite sets are conveniently represented by listing their elements. Parentheses delimit expressions, and, the alternation operator, separates alternatives. For example, D, the set of

More information