corgi Language Reference Manual COMS W4115

Similar documents
Language Reference Manual

Java+- Language Reference Manual

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

SMURF Language Reference Manual Serial MUsic Represented as Functions

1 Lexical Considerations

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Typescript on LLVM Language Reference Manual

ARG! Language Reference Manual

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

Lexical Considerations

Basics of Java Programming

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

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

C-Major Language Reference Manual

GraphQuil Language Reference Manual COMS W4115

ECE 122 Engineering Problem Solving with Java

FRAC: Language Reference Manual

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

CGS 3066: Spring 2015 JavaScript Reference

Program Fundamentals

Full file at

Declaration and Memory

CSC Web Programming. Introduction to JavaScript

UNIT- 3 Introduction to C++

JME Language Reference Manual

Language Reference Manual

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Lexical Considerations

BoredGames Language Reference Manual A Language for Board Games. Brandon Kessler (bpk2107) and Kristen Wise (kew2132)

CMPT 125: Lecture 3 Data and Expressions

d-file Language Reference Manual

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.

Chapter 2. Lexical Elements & Operators

GOLD Language Reference Manual

Crayon (.cry) Language Reference Manual. Naman Agrawal (na2603) Vaidehi Dalmia (vd2302) Ganesh Ravichandran (gr2483) David Smart (ds3361)

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

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

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual

MELODY. Language Reference Manual. Music Programming Language

Java Primer 1: Types, Classes and Operators

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)

Key Differences Between Python and Java

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

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

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Language Reference Manual simplicity

Programming Languages & Translators. XML Document Manipulation Language (XDML) Language Reference Manual

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Full file at C How to Program, 6/e Multiple Choice Test Bank

egrapher Language Reference Manual

3. Java - Language Constructs I

Program Elements -- Introduction

CSI33 Data Structures

Sprite an animation manipulation language Language Reference Manual

CS313D: ADVANCED PROGRAMMING LANGUAGE

VLC : Language Reference Manual

Angela Z: A Language that facilitate the Matrix wise operations Language Reference Manual

Visual C# Instructor s Manual Table of Contents

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

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

XQ: An XML Query Language Language Reference Manual

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

Lecture 3 Tao Wang 1

COLOGO A Graph Language Reference Manual

TED Language Reference Manual

SSOL Language Reference Manual

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

Operators. Java operators are classified into three categories:

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Getting started with Java

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

YAGL: Yet Another Graphing Language Language Reference Manual

CHIL CSS HTML Integrated Language

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

Decaf Language Reference Manual

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

4 Programming Fundamentals. Introduction to Programming 1 1

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Java Notes. 10th ICSE. Saravanan Ganesh

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

Pace University. Fundamental Concepts of CS121 1

Lecture 2 Tao Wang 1

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Chapter 6 Primitive types

A variable is a name for a location in memory A variable must be declared

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Objectives. In this chapter, you will:

Fundamental of Programming (C)

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

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Reserved Words and Identifiers

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321

Chapter 2, Part III Arithmetic Operators and Decision Making

QUIZ: What value is stored in a after this

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

Chapter 2: Using Data

Transcription:

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 is a language centered on music translation, generation, and analysis. It will be able to read in a MusicXML file which are both standardized digital file formats for interpreting music and translate the files into the appropriate data structures. Similarly, a user will be able to generate music directly through the implementation of our musical data structures. These data structures will allow our language to quantitatively analyze and find patterns in music that would be difficult to do manually. Why is it called corgi? According to wikipedia: So yeah! Corgis are very active and energetic. They have a strong desire to please and should receive both physical and mental exercise regularly. They should be socialized early on because they tend to be shy and cautious with strangers and other dogs. They have a tendency to be very vocal, and for this reason make good alarm dogs. They are typically good with children, but due to their herding behavior, may nip at their heels during play.

Chapter 2: Types and Type Declaration Type Declaration Data is expressed in explicitly declared types similar to Java. Primitive Types Character A character in corgi is a primitive type denoted by the keyword char. A char is declared as such: char c = c ; Integer Much like Java, an integer in corgi is a primitive type denoted by the keyword int and representing values ranging from 0 to 2^32 1. An int is declared by: int i = 7; Non Primitive Types String A String is an array of chars. For example a String can be declared by: String str = music ; Fractions A fraction is reduced division of two integers. It s type declaration is denoted by the keyword frac and each value definition begins with the character <, followed by the numerator of the fraction, separated by the denominator of the fraction by a / and ending with the character >. For example a fraction can be declared as: frac f = <¾>; Duration Duration is fraction that meets the constraint that the numerator is less than the denominator. It is used to represent the length of a chord and can be either declared directly or cast from a fraction as shown: duration d = <¼>; fraction f = <¾>; duration fd = duration(f); Pitch Pitch is defined by an integer. It is declared using the keyword pitch, for example: pitch p = 4;

Rhythm Rhythm refers to a sequential list of durations. It is declared using the keyword rhythm as shown: duration d = <¼>; rhythm r = [d,d,d]; Chord A chord is a sequential list of (pitch, duration) tuples. A chord can be declared using the keyword chord as follows: pitch p1 = 4; pitch p2 = 5; duration d1 = <¼>; duration d2 = <⅛>; chord c = [(p1,d1), (p1,d2), (p2, d2)]; Track A track is a sequential list of chords which can be declared using the keyword track. For example: pitch p1 = 4; pitch p2 = 5; duration d1 = <¼>; duration d2 = <⅛>; chord c1 = [(p1,d1), (p1,d2), (p2, d2)]; chord c2 = [(p1,d1), (p1,d2), (p2, d2), (p2, d1)]; track t = [c1, c2, c2]; Composition A composition is a sequential collection of tracks. A composition can be declared using the keyword composition as follows: pitch p1 = 4; pitch p2 = 5; duration d1 = <¼>; duration d2 = <⅛>; chord c1 = [(p1,d1), (p1,d2), (p2, d2)]; chord c2 = [(p1,d1), (p1,d2), (p2, d2), (p2, d1)]; track t1 = [c1, c2, c2]; track t2 = [c1, c1]; composition x = [t1, t2, t1];

Chapter 3: Lexical Conventions In corgi, a token is a string of one or more characters consisting of letters, digits, or underscores. corgi has 5 kinds of tokens: Identifiers Identifiers Keywords Constants Operators Newlines The first character must be a letter and identifiers are case sensitive. The letters are the ASCII characters a z and A Z. Digits are the ASCII characters 0 9. Keywords letter [ a z A Z ] digit [ 0 9 ] underscore _ identifier letter (letter digit underscore) * The following identifiers are strictly reserved for use as keywords: Keywords int frac duration pitch rhythm chord track composition True / False Description standard 32 bit integer two integers that represent a fraction wrapper around fraction wrapper around integer, this can also be instantiated as 'C+4' a collection of durations a collection of pitch duration tuples a sequential list of chords a collection of tracks Boolean constants

if / elif / else random print main return Conditional expressions generate random numbers Print information to stdout Declaration of the main program specifies a return statement. Literals Strings will be a list of characters in corgi. Declaring string literals in corgi is fine, but will be immediately converted to a list of characters. Defining a string literal is simply done with a sequence of one or more characters enclosed by single quotes. The only special escape characters are: Escaped Description \ single quote \n new line \t tab Punctuation Punctuation Use Example, list element separator, function parameters array = [1, 2, 3] [] list delimiter, list access array[0] = 3 () conditional parameter delimiter, function parameter delimiter if (array[0] == 3) {} statement list delimiter if (array[0] == 3) { /* work */}

string literal delimiter s = what\ s up? ; end of statement array = [1, 2, 3]; Comments Comments are super useful and corgi supports comments in two flavors. Comment Symbols Description Example /* */ Multiline comments /* This is a comment */ // Single line comment // This is a comment Operators An operator is a token that specifies an operation on at least one operand and yields some result. int frac duration pitch rhythm chord track compositio n "=" assignment assignment assignment assignment assignment assignment assignment assignment "+" addition addition addition " " subtraction subtraction subtraction "*" multiplication multiplication multiplication adds the pitch values subtracts the pitch values multiplies two pitch values "/" division division division [] accessor accessor accessor accessor > value value duration duration < value value duration duration "==" check equality check equality check equality check equality

"!=" check equality check equality check equality check equality "." invoke method invoke method invoke method "++" increment increment increment " " decrement decrement decrement increment pitch value decrement pitch value Operator precedence from greatest to least precedence:. ++ * / % < > <= >= ==!= =

Chapter 4: Syntax Program Structure A program in corgi is made up of one or more valid statements. A Program begins in a main function which needs to be defined for any statements to be executed. Expressions In corgi, an expression is made up of variables, operators, and method calls. An expression must evaluate to a value of one of corgi s data types. An expression is evaluated from left to right as shown: 10 2 3 4 //evaluates to 1 Variables A variable refers to a data type. They type and value of a variable is declared and initialized with the type keyword, variable name, and value in a single line as follows: int a = 4; For type specific examples refer to Chapter 2. Binary Operators Binary operators can connect variables to create composite expressions. These operators are of the form. x operator x //with x representing an expression Types of Binary Operators include: Arithmetic operators such as addition (+), subtraction ( ), multiplication(*), division (/), and modulus (%). The expressions acting as operands for an arithmetic operator must be both the same type and that type must be int, frac, or duration. The resulting value of the expression composed of two expressions of the same type is a value of that type. Relational operators such as less than (<), greater than (>), equal (==), or not equal (!=) require operands to be of the same type and of types including int, frac, duration, pitch, or rhythm. The result of a relational operator invoked on two operands of the same type is an integer equal to 0, if the expression evaluates to false or 1 otherwise. The Role of Parentheses Parentheses may guide the order of operations on expressions as the expression inside a set of parentheses must be evaluated before that expression can be evaluated with respect to other operators. The surrounding of a set of parentheses around an expression does not change the subexpressions value. Statements

A statement is an instruction to be executed. An expression on its own is not a valid statement, with the exception of a function call. It is either a single instruction that ends in a ; or begins a list of statements contained between curly braces ({ }). There are four types of statements in corgi: Assignment An expression s value can be assignment to a variable with this statement. int a = 4; int b = a + 1; Function Creation Functions can be created much in the style of C functions. The method header includes the return type, function name, and parameters. The return type can be omitted in the case of a function that does not return a value, but the function must return the type declared in the header. This is a function with no parameters which returns a chord: chord function1() { chord c = [(1, <1/2>)]; return c; } a function with no return value and two parameters: function2(chord c, int i) { } Return Statement Return statements are specified Function Calls A function call consists of the function's name followed by its parameters in parentheses and surrounded by commas. The parameters and the function call itself are expressions whose type are determined from a previous function definition. The function call's value is the function's return value. Functions can be called with no parameters but the parentheses cannot be omitted. chord c = function1(); function2(c, 2); A function call can be used as a stand alone statement but its return value will be lost if it is not assigned to a variable. Control Statements for loop A for statement takes two assignment statements and a Boolean expression and executes its statement list until its condition evaluates to False, the first

assignment is executed when the for statement is encountered and the second one after each iteration of the loop: for ( assignment1; condition; assignment2 ) { } while loop A while statement takes a Boolean expression and executes its statement list until the expression evaluates to False: while ( condition ) { } if elif else An if else statement takes a Boolean expression and executes one statement list if its value is True and the other statement list otherwise: if (condition) { // condition is not 0 } else { // condition is 0 } if else statements can be chained to test several conditions with elif: if ( condition1 ) { } elif ( condition2 ) { } elif ( condition3 ) { } else { } Scope Block scoping A block is a list of statements enclosed between two braces. Blocks can be nested and have their own local variables. A variable is only accessible in the block in which it was defined and blocks inside this one. int x = 5; { int y = x + 1; x = y + 1; } if (x > 5) { // This is true y = 0; // This is not allowed, y has no type or value

} Function scoping Functions only have access to variables in their parameter list and local variables declared inside the function.

Chapter 5: Standard Library import() Usage: composition c = import("filepath/test.xml"); By using the import function, one can read in a music xml file from the file system into a composition variable. export() Usage: export(c, filepath/masterpiece.xml ); By using the export function, one can export a composition c of theirs to a music xml file for further processing and alteration. print() Usage: print( Hello, World! ); print( Hello, World! ); By using the print function, one can print to either stdout or to a file. The parameter must be of type string which will be written to standard out. list.add() We can add elements to a list. The parameter passed in must be of the same type as the list elements. list.remove() We can remove elements to a list. The parameter passed in must be of type int. // start with 1 5 mycollection = [1,2,3,4,5]; // let s add 6 mycollection.add(6); // [1,2,3,4,5,6];

// then we can take away the element at index 3 mycollection.remove(3); //[1,2,3,5,6];