MatchaScript: Language Reference Manual Programming Languages & Translators Spring 2017

Similar documents
Client-Side Web Technologies. JavaScript Part I

Java+- Language Reference Manual

Language Reference Manual simplicity

CGS 3066: Spring 2015 JavaScript Reference

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

Sprite an animation manipulation language Language Reference Manual

3. Java - Language Constructs I

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Typescript on LLVM Language Reference Manual

Introduction to Programming Using Java (98-388)

CSC Web Programming. Introduction to JavaScript

Program Fundamentals

1 Lexical Considerations

Decaf Language Reference Manual

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

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Language Reference Manual

CHIL CSS HTML Integrated Language

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

JME Language Reference Manual

Lexical Considerations

Lexical Considerations

Programming for the Web with PHP

JScript Reference. Contents

GOLD Language Reference Manual

2 rd class Department of Programming. OOP with Java Programming

Computer Components. Software{ User Programs. Operating System. Hardware

do fifty two: Language Reference Manual

Introduce C# as Object Oriented programming language. Explain, tokens,

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

The Warhol Language Reference Manual

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

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

Index COPYRIGHTED MATERIAL

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

SSOL Language Reference Manual

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

UNIT- 3 Introduction to C++

Twister: Language Reference Manual

JewelScript Reference Manual

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

corgi Language Reference Manual COMS W4115

The Arithmetic Operators

CSC 1214: Object-Oriented Programming

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

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

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

FRAC: Language Reference Manual

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

BASIC ELEMENTS OF A COMPUTER PROGRAM

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

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

Introduction to C++ with content from

Chapter 2: Basic Elements of C++

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

Language Reference Manual

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

egrapher Language Reference Manual

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

Computer Components. Software{ User Programs. Operating System. Hardware

DEPARTMENT OF MATHS, MJ COLLEGE

JFlat Reference Manual

3. Java - Language Constructs I


JavaScript CS 4640 Programming Languages for Web Applications

Language Reference Manual

Accelerating Information Technology Innovation

Java Notes. 10th ICSE. Saravanan Ganesh

BCA-105 C Language What is C? History of C

JavaScript: Sort of a Big Deal,

IC Language Specification

JavaScript CS 4640 Programming Languages for Web Applications

.Net Technologies. Components of.net Framework

Java Primer 1: Types, Classes and Operators

Funk Programming Language Reference Manual

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

Decaf Language Reference

Operators and Expressions

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual

Coral Programming Language Reference Manual

EZ- ASCII: Language Reference Manual

The Decaf Language. 1 Lexical considerations

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Ruby: Introduction, Basics

ARG! Language Reference Manual

The MaSH Programming Language At the Statements Level

Java Bytecode (binary file)

Cellular Automata Language (CAL) Language Reference Manual

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

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

QUIZ: What value is stored in a after this

Programming Lecture 3

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

Transcription:

MatchaScript: Language Reference Manual Programming Languages & Translators Spring 2017 Language Guru: Kimberly Hou - kjh2146 Systems Architect: Rebecca Mahany - rlm2175 Manager: Jordi Orbay - jao2154 Tester: Ruijia Yang - ry2277 Table of Contents Preface / Introduction Lexical Structure Types Expressions Statements (if, while, for, case, etc.) Functions Classes Introduction MatchaScript is a general-purpose statically typed programming language that is convenient for both imperative and functional programming. It will be compiled to LLVM using our OCaml compiler, and will from LLVM be compiled to native code. Features include: Optimized for event-driven programming Garbage collection, implemented similarly to OCaml No type inference Lexical scoping Lexical Structure Tokens in MatchaScript include identifiers, keywords, constants, literals, operators, and separators. Tokens are separated by whitespace (blanks, tabs, and newlines) or comments. Comments in MatchaScript are C-style comments, beginning with /* and terminating with */. Identifiers are sequences of letters and, optionally, one or more digits or underscores. Identifiers must begin with a letter. CamelCase is suggested. The following are reserved keywords in MatchaScript:

For declarations, const is reserved to declare constants, and fun to declare functions. The following are reserved for primitives: int, float, double, char, String, Boolean, and null. The following are reserved for control flow: while, do/while, for, for/in, for/each, if/else if/else, switch, try/catch/finally, continue, break. The keywords class and constructor are reserved for implementing classes. The keyword let is reserved for block scoping. The keyword log is used for print statements in MatchaScript. Unlike JavaScript, semicolons are mandatory for all MatchaScript statements. A simple sample program with this structure can be seen below: /**** Similar to JavaScript's console.log(), log.nl() adds a newline at the end of its print statement while log() does not. ****/ function void helloworld() { log.nl( "Hello World!" ); // prints "Hello World!" String world = "World." ; log( "Goodbye " + world); // prints "Goodbye World." Types, Values, and Variables Primitives - strict type system Name Description int char Integer Character String Sequence of characters surrounded by and! Boolean float Boolean Single-precision floating point number

double Matrix null Double-precision floating point number Matrix of int, float, or double. Nullable type; All variables are automatically assigned to it when not explicitly assigned We will implement the const keyword for constant variables. Expressions Expressions in MatchaScript are assignments, function declarations, and function calls. The following is a list of all operators in MatchaScript, in their order of precedence: Operator Operation ++ Pre- or post-increment -- Pre- or post-decrement - Negate number + Convert to number ~ Invert bits! Invert Boolean value delete typeof void Remove a property Determine type of operand Return undefined value *, /, % Multiply, divide, modulo +, - Add, subtract + Concatenate strings << Shift left >> Shift right with sign extension >>> Shift right with zero extension <, <=, >, >= Numeric or alphabetic comparison

instanceof in Returns object class Test existence of property == Test strict equality!= Test strict inequality & ^ Compute bitwise AND Compute bitwise XOR Compute bitwise OR && Compute logical AND Compute logical OR?: Choose second or third operand = Assignment *=, /=, %=, +=, -=, &=, ^=, =, <<=, >>=, >>>= Operate and assign eval Evaluate or execute the argument(s) For arithmetic expressions, MatchaScript, like JavaScript, will attempt to convert operands to numbers; if they cannot, they will be converted to NaNs. Notes on differences from JavaScript: We will not implement the comma operator. We implement strict equality and inequality only (=== and!== in JavaScript), but for simplicity s sake they will be implemented using the following operators: == and!=. We will implement eval() as an operator, rather than a function. Statements For the most part, MatchaScript syntax for statements is similar to JavaScript syntax. Conditional Statements if else if Completes block of statements when a boolean expression is evaluated as TRUE Follows a preceding if when the if is false. Acts

similar to an if. else switch OHMSS Follows a preceding if when the if is false. Completes block of statements as long as preceding if is false. Completes one of multiple statements based off of the value of a particular evaluation Completes block of statement if the reserved variable OHMSS is set to true. Used normally for testing and print statements. Loop Structures while for Completes an entire block of statements until a boolean expression is evaluated as FALSE A while loop that also increments a designated variables that may or may not be used in the boolean expression Error Structures try catch finally A structure that may or may not throw an exception A structure that may or may not handle particular exceptions. Multiple catch clauses can be used. A structure that always executes when the try block exits. Useful for mandatory clean up procedures Will not be implemented in MachaScript: with use strict With blocks allow a series of statements to be performed on a specified object. Will not be used because it is prone to misuse. Blocks that do not allow the use of undeclared variables. Will not be used because is rarely helpful to anyone.

As stated previously: unlike in JavaScript, semicolons are mandatory for all MatchaScript statements. Functions Function Declaration A function returns to its caller by either return; or return <type>;, the first case being valid if the function return type is void and the function is to end early, and the second being valid otherwise. Functions are declared using the function keyword. They may also be assigned to variables using the fun keyword, or they can be anonymous functions. Below is an example of a simple function call. Note that the void keyword is similar to C-based languages unlike JavaScript. function void add( int x, int y) { int z = x + y; log.nl(z); // this is the same as log.nl(x + y); function void main() { add(x,y); Functions can be assigned to variables using the fun keyword. function int factorial( int x) { if (x === 1) { return x; else { return x * factorial(x - 1); function void main() { fun f = factorial(10); log.nl(f); // prints 3628800 Closures

MatchaScript supports closures, meaning when functions are nested within each other, the inner function has access to variables in the outer function. Note that the inner function stores references to these outer variables, not actual values. Closures are implemented by function String myname(string firstname) { String intro = "My name is " ; function String mysurname(string lastname) { return intro + firstname + " " + lastname; return lastname; function void main() { fun thename = myname( "Stephen" ); // outer function returns log.nl(thename( "Edwards" )); // closure (inner function) returns; statement //prints "My name is Stephen Edwards" Currying Currying and higher-order functions are supported, allowing for detailed custom functions. Below, note the use of anonymous functions which may be utilized as well. fun motto = function fun(string statement) { return function fun(string name) { return function void (String punctuation) { log.nl(statement + ", " + name + punctuation); ; ; ; fun pokemonmotto = motto( "Gotta catch 'em all" ); pokemonmotto( "Ash" )( "!" ); // prints "Gotta catch 'em all, Ash!" fun edisonquote = motto( "Vision without execution is hallucination" )( "Thomas" ); edisonquote( "?" ); // prints "Vision without execution is hallucination, Thomas?"

Classes As MatchaScript is statically typed, the language implements classical OOP inheritance. This is a departure from JavaScript, which uses prototype-based inheritance. Since variables are loosely typed in JavaScript, if it cannot find attributes for a given object in its own definition, it will fall back on each of its prototypes and look at their attributes to match which properties an object the user declared can be assigned to without error. This fallback mechanism is one of the defining characteristics of prototypical inheritance, where objects with loosely defined types can morph into other types at runtime. For the purposes of a statically typed language, much of the power of prototypical inheritance would be nullified because all variables have to be of one type throughout the runtime of a program. Thus, a classical OOP inheritance model is better suited for MatchaScript. Below is an example of class creation: class Animal { constructor(string name, int weight) { this.name = name; this.weight = weight; class BunnyRabbit extends Animal { constructor(string name, int weight, String ears) { super (name, weight); this.ears = ears; function int getweight() { return this.weight; function void setweight( int newweight) { this.weight = newweight; function String getname() { return this.name; function String getears() { return this.ears; function void setears(string newears) { this.ears = newears; BunnyRabbit bugsbunny = new BunnyRabbit( "Bugs Bunny", 15, "Floppy" );

Note that even though the syntax resembles the ES2015 syntactic sugar keyword set to implement classes, the underlying mechanism for MatchaScript inheritance is still object-oriented based, not prototypical.