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

Similar documents
GridLang: Grid Based Game Development Language. Programming Language and Translators - Spring 2017 Prof. Stephen Edwards

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

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

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual

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

CHIL CSS HTML Integrated Language

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

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

Typescript on LLVM Language Reference Manual

Language Reference Manual

1 Lexical Considerations

Language Reference Manual

Lexical Considerations

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

GraphQuil Language Reference Manual COMS W4115

Lexical Considerations

CSC Web Programming. Introduction to JavaScript

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

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

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

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

Visual C# Instructor s Manual Table of Contents

Cellular Automata Language (CAL) Language Reference Manual

ARG! Language Reference Manual

Java+- Language Reference Manual

JME Language Reference Manual

Full file at

C: How to Program. Week /Mar/05

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

The SPL Programming Language Reference Manual

Simple Java Reference

Fundamental of Programming (C)

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

Chapter 2 - Introduction to C Programming

BASIC ELEMENTS OF A COMPUTER PROGRAM

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

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

Programming for Engineers Introduction to C

VLC : Language Reference Manual

Chapter 2: Basic Elements of C++

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

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

UNIT- 3 Introduction to C++

The Warhol Language Reference Manual

Chapter 2. Lexical Elements & Operators

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

corgi Language Reference Manual COMS W4115

FRAC: Language Reference Manual

Language Reference Manual simplicity

CGS 3066: Spring 2015 JavaScript Reference

PieNum Language Reference Manual

DEPARTMENT OF MATHS, MJ COLLEGE

Senet. Language Reference Manual. 26 th October Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz

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

The PCAT Programming Language Reference Manual

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

L-System Fractal Generator: Language Reference Manual

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Objectives. In this chapter, you will:

SSOL Language Reference Manual

CSI33 Data Structures

Lesson 3: Basic Programming Concepts

Introduction to C# Applications

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

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

Chapter 2: Using Data

GOLD Language Reference Manual

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

YOLOP Language Reference Manual

Decaf Language Reference Manual

Java Notes. 10th ICSE. Saravanan Ganesh

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

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

Lecture 3 Tao Wang 1

ASML Language Reference Manual

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

Chapter 2: Using Data

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

DINO. Language Reference Manual. Author: Manu Jain

DES CARTES. COMS W4115 Fall 2011 Prof. Stephen Edwards Language Reference Manual

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

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

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

Sprite an animation manipulation language Language Reference Manual

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

CS313D: ADVANCED PROGRAMMING LANGUAGE

JFlat Reference Manual

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

Creating a C++ Program

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

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

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

egrapher Language Reference Manual

Course Outline. Introduction to java

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

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

TED Language Reference Manual

SFPL Reference Manual

Transcription:

GridLang: Grid Based Game Development Language Language Reference Manual Programming Language and Translators - Spring 2017 Prof. Stephen Edwards Akshay Nagpal Dhruv Shekhawat Parth Panchmatia Sagar Damani an2756 @columbia.edu ds3512 @columbia.edu psp2137 @columbia.edu ssd2144 @columbia.edu

Table of Contents 1. Lexical Elements 1.1 Identifiers 1.2 Keywords 1.3 Literals 1.3.1 String literals 1.3.2 Integer literals 1.3.3 Boolean literals 1.4 Delimiters 1.4.1 Parentheses and Braces 1.4.2 Commas 1.4.3 Square Brackets 1.4.5 Curly Braces 1.4.6 Periods 1.4.7 New Line Characters 1.5 Whitespace 2.Data Types 2.1 Primitive Data Types 2.1.1 int 2.1.2 string 2.1.3 boolean 2.1.4 coordinate 2.1.5 void 2.2 Non-primitive Data Types: 2.2.1 Arrays 2.2.1.1 Declaring Arrays 2.2.1.2 Accessing and setting array elements 2.2.1.3 Array Length 2.2.2 Grid 2.2.3 Player 2.2.4 Item 3 Expressions and Operators 3.1 Expressions 3.2 Operators 4. Statements 4.1 The If Statement 4.2 The while statement

5.Functions 5.1 Function Definitions 5.2 Calling Functions 5.3 Built-in functions 5.3.1 drawgrid() 5.3.2 traverse( [ Coordinate c1, Coordinate c2 ], string listtype ) 5.3.3 random(0,1) 5.3.4 gameover() 5.3.5 print(string s) 5.3.6 prompt(string msg, datatype ) 6. Program Structure and Scope 6.1 Layout(int rowcount, int colcount) 6.2 gameloop() 6.3 checkmove() 6.4 Player/Item.colocation(Player/Item, playertype( optional ) ) 6.5 repeat 6.6 checkgameend 6.7 gameover

1. Lexical Elements Identifiers are strings for naming variables and functions. The identifiers are case-sensitive. They can consist of letters, digits and underscores, but must always start with a letter. X x a1 b2 1.2 Keywords Keywords are reserved for use in the language and cannot be used as identifiers. These keywords are case sensitive. int function player item grid coordinate float colocation gameloop while checkmove return string drawgrid rand gameover creategrid traverse boolean checkgameend type repeat print prompt playerorder p 1.3 Literals Literals are constant string, numeric, or boolean values, such as abc, 25, or false. Each literal is immutable and has a specific data type corresponding to one of the primitive types. No type casting is allowed. Trying to assign a literal to a variable of mismatching type will cause an error. string x = " abc" 1.3.1 String literals String literals are a sequence of zero or more non-double-quote characters and/or escaped characters, enclosed in double quotes. An escaped character is a character that immediately follow a backslash \. The backslash signals to the compiler to interpret the escaped character in a special way, according to the following table: \n Insert a newline

\t Insert a tab \\ Insert a backslash \" Insert a double quote 1.3.2 Integer literals Integer literals are whole numbers represented by a sequence of one or more digits from 0-9. Integers are assumed to be in decimal (base 10) format. Precede an integer with - to denote a negative number. 31-343 1.3.3 Boolean literals A boolean literal represents a truth value and can have the value true or false (case sensitive). true false 1.4 Delimiters Delimiters are special tokens that separate other tokens, and tell the compiler how to interpret associated tokens. 1.4.1 Parentheses and Braces Parentheses are used to force evaluation of parts of a program in a specific order. They are also used to enclose arguments for a function. int x = 10, y = 20, z = 30, w = 40 w = ( x + y ) * z # here, (x+y) will be executed first and then multiplied with z 1.4.2 Commas Commas are used to separate function arguments and variable declarations. 1.4.3 Square Brackets Square brackets are used for array initialization, assignment, and access. arrayname [ 0 ] = 3 1.4.5 Curly Braces Curly braces are used to enclose function definitions and blocks of code. In general, blocks enclosed within curly braces do not need to be terminated with semicolons.

1.4.6 Periods Periods are used to access attributes of Item and Player data types, as well as to define the event handlers on these types. 1.4.7 New Line Characters New Line Characters (either \n or \r) are used to terminate a sequence of code. 1.5 Whitespace Whitespace (unless used in a string literal) is used to separate tokens, but has no special meaning otherwise. List of whitespace characters: spaces, tabs and newlines. 2.Data Types 2.1 Primitive Data Types 2.1.1 int These are 32-bit signed integers that can range from 2,147,483,648 to 2,147,483,647 2.1.2 string All text values will be of this type. 2.1.3 boolean A truth value that can be either true or false. 2.1.4 coordinate An ordered pair of non-negative integers, used to index the grid. ( 2, 3) 2.1.5 void Used only as a return type in a function definition; specifying void as the return type of a function means that the function does not return anything. 2.2 Non-primitive Data Types: 2.2.1 Arrays Arrays are ordered, fixed-size lists that can be used to hold both primitive and non-primitive data-types. All elements of an array must be of the same type. An array must be initialized with its size.

2.2.1.1 Declaring Arrays You can declare an array by indicating the type of the elements that the array will contain, followed by brackets enclosing the number of elements an array will hold, followed by an identifier for the array. For example: int [ 5 ] myarray This declares an array named myarray that can hold 5 integers. 2.2.1.2 Accessing and setting array elements Array elements can be accessed by providing the desired index of the element in the array you wish to access enclosed within brackets next to the identifier of the array. For example: myarray [ 1 ] This returns the element in myarray at index 1. Array elements can be set by accessing the element via the desired index in which to place the item and then assigning the desired value to the entry. For example: myarray [ 1 ]= 4 sets the element in myarray at index 1 to 4. 2.2.1.3 Array Length To get an array s length, simply call the len function on the array. For example: int size = len ( my_array) 2.2.2 Grid Grid is a global 2-dimensional array of cells. Each cell holds an array of Players (called playerlist) and an array of Items (called itemlist). A specific cell in the grid can be referenced by its coordinates. Eg: Grid(3,4) will be the grid cell on the fourth row and the fifth column. These can be referenced as Grid(3,4).playerList and Grid(3,4).itemList. 2.2.3 Player Player has the following in-built attributes: position: a coordinate denoting the position of the Player on the grid. win: a boolean value. If this values is set, then the Player is removed from the playerorder.

displaystring: a string that will be displayed at the position of the Player in drawgrid() type: an enum that denotes the type of the Player Exists: boolean. When this is set to false, the Player is removed from the gameloop, and removed from the Grid. Moreover, additional attributes can be added to Player using the following syntax: Player { Datatype attr1 Datatype attr2 Datatype attr3 #specify player-type specific attributes type = " evil " { Datatype attr4 type = " good " { Datatype attr5 Handlers can be defined on players for colocation and movement. These will be described further in Section 6. 2.2.4 Item An item is anything on the board other than the player. Item has the following attributes: position: a coordinate denoting the position of the Item on the grid. displaystring: Denotes the string that will be displayed at the position of the Item in drawgrid(). Exists: boolean. When this is set to false, the item is removed from the Grid. Moreover, additional attributes can be added to Item using the following syntax: Item ItemName { Datatype attr1 Datatype attr2 3 Expressions and Operators 3.1 Expressions Expressions are made up of one or more operands and zero or more operators. Innermost expressions are evaluated first, as determined by grouping into parentheses,

and operator precedence helps determine order of evaluation. Expressions are otherwise evaluated left to right. 3.2 Operators The table below presents the language operators (including assignment operators, mathematical operators, logical operators, and comparison operators), descriptions, and associativity rules. Operator precedence is highest at the top and lowest at the bottom of the table. + (Addition) : Adds values on either side of the operator. - (Subtraction) : Subtracts right-hand operand from left-hand operand. * (Multiplication) : Multiplies values on either side of the operator. / (Division) : Divides left-hand operand by right-hand operand. % (Modulus) : Divides left-hand operand by right-hand operand and returns remainder. ++ (Increment) : Increases the value of operand by 1. -- (Decrement) : Decreases the value of operand by 1. Relational Operators: >, <, =, ==, <=, >=,!= (standard meanings) Logical Operators: and, or,! (standard meanings) Assignment Operators: =, +=, -=, *=, /=, %= (standard meanings) 4. Statements 4.1 The If Statement The if statement is used to execute a statement if a specified condition is met. If the specified condition is not met, the statement is skipped over. The general form of an if statement is as follows: if ( condition) { statement1 statement2 statement3 else { statement4

4.2 The while statement The while statement is used to execute a block of code continuously in a loop until the specified condition is no longer met. If the condition is not met upon initially reaching the while loop, the code is never executed. The general structure of a while loop is as follows: while ( condition) { Action1 Action2 Action3 5.Functions 5.1 Function Definitions Function definitions consist of an initial keyword function a return type, a function identifier, a set of parameters and their types, and then a block of code to execute when that function is called with the specified parameters. An example of an addition function definition is as follows: function sum ( int a, int b ): int { return a +b 5.2 Calling Functions A function can be called its identifier followed by its params in parentheses. for example: sum(1,2) 5.3 Built-in functions 5.3.1 drawgrid() Draws the grid on the console 5.3.2 traverse( [ Coordinate c1, Coordinate c2 ], string listtype ) Traverses a row, a column or a diagonal in the grid with start coordinate c1 and end coordinate c2. Returns a list of the listtype specified. Valid listtypes are playerlist and itemlist. Eg: traverse([(1,1), (3,3) ], playerlist ) returns a list of all the players in the cells along the diagonal from (1,1) to (3,3)

5.3.3 random(0,1) Generate a pseudo-random number between 0.000 to 1.000. 5.3.4 gameover() Displays the winner and exits the program. 5.3.5 print(string s) prints s on console. 5.3.6 prompt(string msg, datatype ) prompts user for input of a certain datatype. 6. Program Structure and Scope The entire game code will be in 1 source file. The flow followed by the code, written by any developer, will be as follows:

The aforementioned blocks imply the following: 6.1 Layout(int rowcount, int colcount) This block of code is executed first. It is used to set up the game Grid. It takes two parameters: rowcount and colcount, which describe its size. Creation of items, players, playerorder and the location of these items and players on the Grid will be described here. 6.2 gameloop() This block of code gets executed repeatedly until the game ends. Each execution of this block signifies one turn in the game. The gameloop reads the order of turns from a

built-in list called playerorder which is defined by the programmer in the layout block. For e.g playerorder = [' p1 ', ' p2 ', ' p3 ', ' p4 '] Whenever a player exits the game the programmer deletes this player from the list. As a result, the gameloop will only run for the remaining players. Inside the gameloop, the programmer can use a placeholder p which at runtime gets replaced by the player whose turn is executing. 6.3 checkmove() This is an event handler for which the trigger is only checked after the gameloop block finishes one iteration. It is used to verify valid movement of the Player or Item. The trigger for this block of code is the change of the location of a Player or Item in the grid during the gameloop(). If checkmove returns false, the location change of the Player/Item is invalidated. The code inside the checkmove block is written by the programmer. Eg: bishop. checkmove ( coordinate start, coordinate end) { #Developer code here 6.4 Player/Item.colocation(Player/Item, playertype( optional ) ) This block of code gets triggered when the Player or Item specified in the argument moves to the same location as the Player or Item on which this colocation handler is defined. It is executed only after the move made is validated by the checkmove block. The significance of this block is to determine if the Player or Item s resultant position on the board leads to an interaction with an existing Player or Item on the board in that position. Eg: Bonus. colocation ( Player) { Player. score ++ 6.5 repeat If repeat is called anywhere in the program, the control shifts back to the beginning of gameloop. 6.6 checkgameend This block of code gets executed after every iteration of the gameloop (and after any colocation events have been handled). The developer would place the logic to test the end of the game in this block. If checkgameend returns false, execution returns to the next

iteration of gameloop(). If it returns true, execution flows to the gameover block. As in gameloop(), p refers to the current player. Eg: checkgameend () { if ( p. score == 100) return true return false 6.7 gameover This block of code gets executed once checkgameend returns true. Announcing the winner of the game, and any clean-up code, can be placed in this block. gameover () { # The programmer enters code here