Typescript on LLVM Language Reference Manual

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

JME Language Reference Manual

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

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

1 Lexical Considerations

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

Language Reference Manual simplicity

Lexical Considerations

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

SFPL Reference Manual

Lexical Considerations

Language Reference Manual

Decaf Language Reference

Sprite an animation manipulation language Language Reference Manual

GAWK Language Reference Manual

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

The SPL Programming Language Reference Manual

Language Reference Manual

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

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

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

ASML Language Reference Manual

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++

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

Full file at

DaMPL. Language Reference Manual. Henrique Grando

EZ- ASCII: Language Reference Manual

The Warhol Language Reference Manual

Java+- Language Reference Manual

L-System Fractal Generator: Language Reference Manual

ARG! Language Reference Manual

Chapter 2. Lexical Elements & Operators

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

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

UNIT- 3 Introduction to C++

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

DINO. Language Reference Manual. Author: Manu Jain

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

SMURF Language Reference Manual Serial MUsic Represented as Functions

Objectives. In this chapter, you will:

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

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual

d-file Language Reference Manual

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

The PCAT Programming Language Reference Manual

BASIC ELEMENTS OF A COMPUTER PROGRAM

Creating a C++ Program

HAWK Language Reference Manual

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

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

SSOL Language Reference Manual

Visual C# Instructor s Manual Table of Contents

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Decaf Language Reference Manual

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

Language Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science

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

MR Language Reference Manual. Siyang Dai (sd2694) Jinxiong Tan (jt2649) Zhi Zhang (zz2219) Zeyang Yu (zy2156) Shuai Yuan (sy2420)

IT 374 C# and Applications/ IT695 C# Data Structures

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

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

COAL (COmplex Arithmetic Language) Reference Manual

The C++ Language. Arizona State University 1

C: How to Program. Week /Mar/05

Flow Language Reference Manual

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

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

CLIP - A Crytographic Language with Irritating Parentheses

Language Reference Manual

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

YAGL: Yet Another Graphing Language Language Reference Manual

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

DEPARTMENT OF MATHS, MJ COLLEGE

4. Inputting data or messages to a function is called passing data to the function.

corgi Language Reference Manual COMS W4115

Funk Programming Language Reference Manual

LECTURE 02 INTRODUCTION TO C++

Chapter 2 - Introduction to C Programming

Introduction to C# Applications

The MaSH Programming Language At the Statements Level

2 nd Week Lecture Notes

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

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

Reference Grammar Meta-notation: hfooi means foo is a nonterminal. foo (in bold font) means that foo is a terminal i.e., a token or a part of a token.

MELODY. Language Reference Manual. Music Programming Language

GraphQuil Language Reference Manual COMS W4115

CA4003 Compiler Construction Assignment Language Definition

PLT 4115 LRM: JaTesté

Review of the C Programming Language for Principles of Operating Systems

A Simple Syntax-Directed Translator

Introduction to Programming Using Java (98-388)

VLC : Language Reference Manual

TML Language Reference Manual

FRAC: Language Reference Manual

CSC Web Programming. Introduction to JavaScript

CHAPTER 3 BASIC INSTRUCTION OF C++

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

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

Transcription:

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 Literals 2.6 Operators 2.6.1 Associativity 2.7 Other Separators 3. Expressions 3.1 Operator Expressions 3. Statements 3.1 Conditionals 3.2 Looping 4. Functions 4.1 Function Definition 5. Variables and Constants 5.2.1 The let keyword 5.2.2 The const keyword 6 Types 6.1 boolean 6.2 number 6.3 string 6.5 void 6.4 Array References 1

1. Introduction This manual describes the Typescript on LLVM Language, as described in the project proposal. In the following I borrow heavily from the language, format, and structure used in The C Programming Language, Second Edition (Kernighan and Ritchie, 1988) since many of same syntactic and semantic rules for C apply to Typescript on LLVM. 2. Lexical Conventions 2.1 Tokens There are six kinds of tokens: Identifiers Keywords String literals Operators Other separators Whitespace (defined here) and comments (described below) are ignored except as they separate tokens: Blanks Horizontal and vertical tabs Newlines Some whitespace is required in order to separate otherwise adjacent identifiers, keywords, and constants. If the input stream has been separated into tokens up to a given character, the next token is the longest string of characters that could constitute a token. 2.2 Comments Comments begin with the characters /* and end with the characters */. Comments do not nest and do not occur within string literals. 2

2.3 Identifiers An identifier (or name) is a sequence of letters and digits with the following properties: The first character must be a letter or an underscore ( _ ). Identifiers are case sensitive. Identifiers may have any length. Generally, identifiers are names that are bound to functions or variables in a scoped namespace, as explained below. 2.4 Reserved Keywords The following identifiers are used as keywords, and may not be used otherwise: and boolean const else false for function if let null number or return true string void while 2.5 String Literals A String Literal is a sequence of one or more characters enclosed in double quotes, e.g. foo. In order to include a double quote in a string constant, the escape character slash ( \ ) may be used. To include a slash in a string, use another slash, e.g. \\x may be used to represent the literal string \x. 3

2.6 Operators Typescript on LLVM only supports binary operators. The table below summarizes the operators supported: Operator Use + Arithmetic addition Arithmetic subtraction * Arithmetic multiplication / Arithmetic division = Assignment!= Not equal boolean comparison < Less than boolean comparison <= Less than or equal to boolean comparison > Greater than boolean comparison >= Greater than or equal to boolean comparison == Equals boolean comparison 2.6.1 Associativity The assignment operator, =, is right associative. The remaining operators are left associative, with the following rules: = takes precedence over!= The following operators are in precedence order, left to right: < > <= >= + takes precedence over * takes precedence over / 4

2.7 Other Separators The other separator tokens include: the semicolon ; for sequencing of statements the comma,, for separating items in an array curly braces, { and } for block scoping parentheses, ( and ) for parameter lists in function definitions 3. Expressions Expressions refer to program code that may be evaluated in a particular scope. There are two two kinds of top level expressions: primary and postfix. Primary expressions have the following form: primary expression: identifier boolean value number value string value Postfix expressions group operators left to right: postfix expression: primary expression postfix expression [ expression ] postfix expression ( argument expression list opt ) argument expression list: assignment expression list argument expression list, assignment expression Assignment expressions are covered in Section 3.1. As shown here, array indexing is done via a postfix expression in which the expression inside brackets resolves to the integer index of the array. Similarly, function calls are postfix expressions that contain zero or more argument expressions within parentheses. 5

3.1 Operator Expressions For the non assignment operators described in Section 2.6, the following forms are used: binary expression: expression + expression expression expression expression * expression expression / expression conditional expression: expression < expression expression > expression expression <= expression expression >= expression expression == expression expression and expression expression or expression Assignments take the following form: assignment expression: identifier = primary expression ; identifier : type specifier = primary expression ; Assignments are described in more detail in Section 5. 3. Statements Statements are sequences of expressions, and have the following form: statement: expression statement compound statement conditional statement loop statement expression statement: 6

expression opt ; compound statement: { statement list opt } statement list: statement statement list statement Conditional and loop statements are defined in Section 3.1 and Section 3.2, respectively. 3.1 Conditionals Conditional statements allow for flow control based on the boolean value of a given conditional expression: conditional statement: if ( conditional expression ) compound statement if ( conditional expression ) compound statement else compound statement For example: if (x < y) { print(x); } if (x > y) { print(y); } else { print(x); } 3.2 Looping Looping is supported using the while construct, and has the following form: loop statement: while ( conditional expression ) compound statement 7

For example: while (x < 100) { printandincrement(x); } 4. Functions Functions are optionally parameterized scoped blocks of code that are given identifiers in the global namespace. 4.1 Function Definition Function definitions have the form function D : T compound statement, where D has the form D ( parameter list ) D denotes the identifier for the function T denotes the return type of the function The syntax of parameters is: parameter list: parameter list parameter list, parameter declaration parameter declaration: identifier : type specifier For example: function add(x : number, y : number) { return x + y; } Here: add corresponds to D above x : number, y : number is the parameter list { return x + y; } is the compound statement 8

5. Variables and Constants Variables and constants are bindings of expressions that may be assigned to identifiers in a scoped namespace. 5.2.1 The let keyword The let keyword is used to define a scope for an expression and assign that expression to a variable. let assignment has the following form: let expression: let assignment expression For example: let s = "Hello world!"; 5.2.2 The const keyword A constant is an immutable binding of an identifier to a value. Constants are declared using the const keyword, which binds an expression to a constant (non reassignable) identifier. const assignment has the following form: const expression: const assignment expression For example: const s = "Hello world!"; 9

6 Types A type constrains the value of an expression to adhere to a particular space of values. There are five fundamental types in Typescript on LLVM, namely: boolean, number, string, void, and Array. The type specifiers are: type specifier: boolean boolean[] number number[] string string[] void These types are defined below. 6.1 boolean A value has boolean type if it is either true or false. 6.2 number All numbers in Typescript on LLVM are floating point values consisting of decimal literals, represented as a sequence of digits, optionally followed by a single. and a trailing sequence of digits. Hexadecimal values are not supported. Examples of numbers are 1, 3.14, etc. 6.3 string A String is a sequence of one or more characters enclosed in double quotes, e.g. foo. In order to include a double quote in a string constant, the escape character slash ( \ ) may be used. To include a slash in a string, use another slash, e.g. \\x may be used to represent the literal string \x. 10

Examples of strings are: x, foo, foo bar baz, etc. 6.5 void The void type is used to indicate the absence of a value being returned from a function. For example: function sleep(): void { /*... */ } 6.4 Array An Array is an indexable collection of values of the same type. It may be declared using let or const, as described in Section 5. For example, to declare an array of numbers: let values: number[] = [1, 2, 3]; 11

References In preparing this LRM and the scanner/parser code, I consulted the following: Kernighan & Ritchie, The C Programming Language, Second Edition, 1988. Parsing with ocamllex and Menhir Menhir Reference Manual ocamlyacc Tutorial The MicroC Compiler code on the class website ( referenced in Piazza ) ANSI C yacc Grammar 12