Dynamo: Language Reference Manual

Similar documents
DYNAMO - A Language for Dynamic Programming

1 Lexical Considerations

Typescript on LLVM Language Reference Manual

Lexical Considerations

Lexical Considerations

Full file at

JME Language Reference Manual

SMURF Language Reference Manual Serial MUsic Represented as Functions

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

ASML Language Reference Manual

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

The Warhol Language Reference Manual

FRAC: Language Reference Manual

GOLD Language Reference Manual

Introduction to Programming Using Java (98-388)

SSOL Language Reference Manual

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

CPS 506 Comparative Programming Languages. Syntax Specification

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Decaf Language Reference

A Simple Syntax-Directed Translator

Sprite an animation manipulation language Language Reference Manual

Algorithms and Programming I. Lecture#12 Spring 2015

Language Reference Manual

Programming in C++ 4. The lexical basis of C++

The SPL Programming Language Reference Manual

Pace University. Fundamental Concepts of CS121 1

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

The pixelman Language Reference Manual. Anthony Chan, Teresa Choe, Gabriel Kramer-Garcia, Brian Tsau

CS 170 Exam 2. Version: A Fall Name (as in OPUS) (print): Instructions:

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

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

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

DaMPL. Language Reference Manual. Henrique Grando

Type Checking. Chapter 6, Section 6.3, 6.5

LECTURE 3. Compiler Phases

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Simple Java Reference

Java Basic Programming Constructs

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Decaf Language Reference Manual

CS 6353 Compiler Construction Project Assignments

IC Language Specification

Creating a C++ Program

PROGRAMMING FUNDAMENTALS

SCoLang - Language Reference Manual

Cellular Automata Language (CAL) Language Reference Manual

CS 6353 Compiler Construction Project Assignments

L-System Fractal Generator: Language Reference Manual

CLIP - A Crytographic Language with Irritating Parentheses

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops

CSE 114 Computer Science I

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS

Computational Expression

VLC : Language Reference Manual

String Computation Program

Scheme Quick Reference

Course Outline. Introduction to java

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

CS111: PROGRAMMING LANGUAGE II

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

JavaCC: SimpleExamples

The PCAT Programming Language Reference Manual

Language Reference Manual

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

Java+- Language Reference Manual

CS313D: ADVANCED PROGRAMMING LANGUAGE

Java Bytecode (binary file)

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

Syntax Intro and Overview. Syntax

Programming: Java. Chapter Objectives. Control Structures. Chapter 4: Control Structures I. Program Design Including Data Structures

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

C-Major Language Reference Manual

Scheme Quick Reference

CIS133J. Working with Numbers in Java

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

COMP-202. Recursion. COMP Recursion, 2011 Jörg Kienzle and others

YOLOP Language Reference Manual

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

Loops. CSE 114, Computer Science 1 Stony Brook University

Chapter 2: Using Data

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

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

( &% class MyClass { }

COMP 202 Java in one week

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

Review of the C Programming Language

Language Reference Manual simplicity

Section 2.2 Your First Program in Java: Printing a Line of Text

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

You ll be reading more about tools for branching in Sections 3.4, and We are skipping Sections 3.5, 3.11 and 3.13-end of chapter.

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

SECTION II: LANGUAGE BASICS

Coral Programming Language Reference Manual

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while

Application Specific Signal Processors S

Transcription:

Dynamo: Language Reference Manual Abhinav Saini Archana Balakrishnan Pradeep Dasigi Srilekha V K Raghavan Muthuregunathan 1 Introduction Dynamo is a programming language that allows the programmer to mathematically represent Dynamic Programming (DP) algorithms The compiler translates it into Java Problems that can be solved using DP are characterized by overlapping sub problems and optimal substructure which are expressed recursively However, representation of DP problems in high level languages is cumbersome with significant book keeping involved Dynamo abstracts the book keeping from the programmer and simplifies the program representation The program consists of only math-like syntax, is simple and intuitive The compiler translates the recursive structure specified by the programmer into iterative code in Java 2 Lexical Conventions The tokens are identifiers, keywords, and constants Blank lines, newline characters, spaces, tabs and comments are ignored and are used only to separate tokens 21 Comments Single line and multi-line comments are supported Single line comments are specified by two back slashes // at the beginning of the line Multiple line comments are bounded by /* at the beginning and */ at the end 22 Embedded Java Code Embedded java code is bound by $ at either end The embedded code will be inserted verbatim into the generated Java file without alteration No embedded Java code may contain the character $ 23 Identifiers Any string that is not a keyword or an operator, and contains at least one alphabet or an underscore ( ) is an identifier It can also contain numerals and hyphens ( - ) 1

24 Seperators The following characters are used as separators: { } ( ) and ; 25 Keywords The following are reserved as keywords, and should not be used for any other purpose data-init logic if else min max sum product argmax argmin memoize 26 Type Inference The Dynamo language does not have explicitly defined data types The default type of a variable is assumed to be String Type is inferred depending on the operators used in the logic section of the code If conflicting operators are used, then an exception is thrown 27 Constants All the constants behave similarly to the ones in Java, since they will appear verbatim in the Java code The constants are of types: boolean, integer, float, char, string 28 Operators and Overloading 281 Overloaded Operators The following operators are overloaded: + : Integer and Float Addition, String Concatenation - : Integer and Float Subtraction / : Integer and Float Division * : Integer and Float Multiplication = : Integer, Float, Character, Boolean and String Comparison 282 Non-overloaded Operators The following are non-overloaded operators: & : Boolean and : Boolean or : Length of String (i:j) : Subarray from i to j 29 Structure of a typical program <name of the program> { data-init <dataname-1>; data-init <dataname-n>; memoize <table-name>(<dimensions>); 2

} logic { if <conditional1> <statement1 to be executed>; else if <conditional2> <statement2 to be executed>; if <conditional-n> <statement-n to be executed>; } The indentation does not have any semantic implications, it may be used for convenience 291 Grammar Specification DynamoProgram ProblemName Code ProblemName \w+ Code { ( data-init Idenifier ; )+ logic { LogicStatementJavaCode } } Identifier ([ 0-9 \ - ]*[ A - Z a - z \ _ ]+[ 0-9 \ - ]*)+ LogicStatement IfStatement (ElseStatement)+ IfStatement if (expr) expr ; ElseStatement ( else IfStatement)+ else expr ; JavaCode \$ JavaStatements \$ 3

A Sample Code Translation A1 Dynamo Code for calculating Levenshtein Distance 1 LevDist 2 { 3 data-init str1; 4 data-init str2; 5 logic 6 { 7 if (str1 = "" & str2 = "") 8 0; 9 else if (str2 = "") 10 str1 ; 11 else if (str1 = "") 12 str2 ; 13 else if (str1[i] = str2[j]) 14 LevDist(str1(:i-1), str2(:j-1)); 15 else 16 min(levdist(str1(:i-1),str2(:j-1))+1, LevDist(str1(:i),str2(:j-1))+1, 18 } 19 } A2 Corresponding Java Code 1 public class LevDist { 2 public static int LevDist(String str1, String str2) { 3 int temp1r = str1length()+1; 4 int temp1c = str2length()+1; 5 int temp1[][] = new int[temp1r][temp1c]; 6 for(int i=0;i<temp1r;i++) { 7 for(int j=0;j<temp1c;j++) { 8 if(i==0&&j==0) { 9 temp1[i][j]=0; 10 } 11 else if(j==0) { 12 temp1[i][j]=i; 13 } 14 else if(i==0) { 15 temp1[i][j]=j; 16 } 17 else if(str1charat(i-1)==str2charat(j-1)) { 18 temp1[i][j]=temp1[i-1][j-1]; 19 } 20 else { 21 int min = temp1[i-1][j-1]+1; 22 min = min>(temp1[i][j-1]+1)?temp1[i][j-1]+1:min; 23 min = min>(temp1[i-1][j]+1)?temp1[i-1][j]+1:min; 24 temp1[i][j]=min; 25 } 4

26 } 27 } 28 return temp1[temp1r-1][temp1c-1]; 29 } 30 31 public static void main(string args[]) { 32 int LevDist_res = LevDist(args[0], args[1]); 33 } 34 } A3 Notes Essentially, the mapping is done by converting the logic for different possibilities on strings to filling up a table The return types and argument types of the function may be inferred while parsing and used to set the corresponding environment variables which are later used while generating the Java code If any conflict occurs after the environment variables are set, a type-mismatch exception will be reported Lines 5, 6 and 7 in this Java code will be present in almost all the programs (with different data types and dimensions) since any recursive program is mapped to a procedure of filling up a table Lines 8 to 25 in this Java code are the ones mapped from logic in the Dynamo code The length of the sub-strings being dealt with in the Dynamo code are mapped to the indexes of the table being filled So, condition (str1= && str2= ) in the former is mapped to (i==0 &&j==0) in the latter The other conditions follow the same logic Finally the value that has to be returned is LevDist(str1,str2) in Dynamo So, temp1[temp1r-1][temp1c-1] is returned in Java Lines 21 to 24 in Java code will be lines of code that replace the in built function min in Dynamo Corresponding replacements can be defined for max and argmax 5