YAGL: Yet Another Graphing Language Language Reference Manual

Similar documents
Typescript on LLVM Language Reference Manual

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

1 Lexical Considerations

Lexical Considerations

Lexical Considerations

COLOGO A Graph Language Reference Manual

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

Sprite an animation manipulation language Language Reference Manual

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

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

GAWK Language Reference Manual

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

The Warhol Language Reference Manual

corgi Language Reference Manual COMS W4115

JME Language Reference Manual

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

The Decaf Language. 1 Lexical considerations

EZ- ASCII: Language Reference Manual

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

The SPL Programming 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

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

The PCAT Programming Language Reference Manual

egrapher Language Reference Manual

DINO. Language Reference Manual. Author: Manu Jain

ARG! Language Reference Manual

Java+- Language Reference Manual

String Computation Program

FRAC: Language Reference Manual

The Decaf language 1

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

Language Reference Manual simplicity

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

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

Decaf Language Reference Manual

Key Differences Between Python and Java

YOLOP Language Reference Manual

Language Reference Manual

SFPL Reference Manual

CHIL CSS HTML Integrated Language

SSOL Language Reference Manual

VLC : Language Reference Manual

SMURF Language Reference Manual Serial MUsic Represented as Functions

Language Reference Manual

Flow Language Reference Manual

LOON. Language Reference Manual THE LANGUAGE OF OBJECT NOTATION. Kyle Hughes, Jack Ricci, Chelci Houston-Borroughs, Niles Christensen, Habin Lee

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

CS143 Handout 03 Summer 2012 June 27, 2012 Decaf Specification

CLIP - A Crytographic Language with Irritating Parentheses

CSC Web Programming. Introduction to JavaScript

L-System Fractal Generator: Language Reference Manual

Project 2 Interpreter for Snail. 2 The Snail Programming Language

DaMPL. Language Reference Manual. Henrique Grando

d-file Language Reference Manual

Review of the C Programming Language for Principles of Operating Systems

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

GBL Language Reference Manual

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

Introduction to Bioinformatics

Review of the C Programming Language

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual

CS /534 Compiler Construction University of Massachusetts Lowell. NOTHING: A Language for Practice Implementation

ASML Language Reference Manual

IC Language Specification

TED Language Reference Manual

CHAD Language Reference Manual

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.

Decaf Language Reference

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

Language Reference Manual

The Pip Language Reference Manual. PLT (W4115) Fall Frank Wallingford

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

RTL Reference 1. JVM. 2. Lexical Conventions

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

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

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

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

GraphQuil Language Reference Manual COMS W4115

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

MATLIP: MATLAB-Like Language for Image Processing

UNIT- 3 Introduction to C++

Turtle Tango (TT) Language Reference Manual

Chapter 2 Working with Data Types and Operators

Cellular Automata Language (CAL) Language Reference Manual

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

Lecture 2 Tao Wang 1

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

XQ: An XML Query Language Language Reference Manual

Program Fundamentals

A Short Summary of Javali

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

MELODY. Language Reference Manual. Music Programming Language

GOLD Language Reference Manual

La Mesa Language Reference Manual COMS 4115: Programming Languages and Translators Professor Stephen Edwards

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

Chapter 2: Introduction to C++

Language Reference Manual

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

Chapter 2. Lexical Elements & Operators

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

Transcription:

YAGL: Yet Another Graphing Language Language Reference Manual Edgar Aroutiounian, Jeff Barg, Robert Cohen July 23, 2014 Abstract YAGL is a programming language for generating graphs in SVG format from JSON formatted data. 1 Introduction This manual describes the YAGL programming language as specified by the YAGL team. 2 Lexical Conventions A YAGL program is written in the 7-bit ASCII character set and is divided into a number of logical lines. A logical line terminates by the token NEWLINE, where a logical line is constructed from one or more physical lines. A physical line is a sequence of ASCII characters that are terminated by an end-of-line character. All blank lines are ignored entirely. 2.1 Tokens Besides the NEWLINE token, the following tokens also exist: NAME, INTEGER, STRING, and OPERATOR, where a LITERAL is either a String literal or an Integer literal. 1

2.2 Comments Comments are introduced by the # character and last until they encounter a NEWLINE token, comments do not nest. 2.3 Identifiers An identifier is a sequence of ASCII letters including underscores where upper and lower case count as different letters; ASCII digits may not be included in an identifier. 2.4 Keywords The following is an enumeration of all the keywords required by a YAGL implementation: if, elif, for, in, break, func, else, return, continue, print, while 2.5 String Literals YAGL string literals begin with a double-quote ( ) followed by a finite sequence of ASCII characters and close with a double-quote ( ). YAGL strings do not recognize escape sequences. An example of a YAGL string literal is String Bar = Hello World. YAGL strings are not iterable and hence may not be used in the declaration of a for loop. 2.6 Integer Literals YAGL supports plain integer literals. Integer literals are the only type of numeric literal recognized by the language, not that numeric literals do not include a sign. YAGL integer literals do not recognize prefixes that are commonly found in other languages such as b 123. An example of a YAGL integer literal is: Int foo = 123 2.7 Operators The following tokens are operators: +, -, *, /, >, <, <=, >=, ==, %, = 3 Meaning of Identifiers Identifiers either refer to functions, builtin Objects or user defined variables. 2

3.1 Basic Types YAGL features four builtin data types, String, Array, Integer, and Dictionary. String represents string objects, Arrays represent an ordered sequence of Integers or Dictionaries. Arrays must have all elements of the same type. Dictionaries represent an implementation of a hashtable and are mainly used as a YAGL container for JSON data. Dictionaries may have only Strings as keys but their values may be either Strings, Arrays, Integers or other Dictionaries. Arrays and Dictionaries are iterable and hence may be used in the declaration of a for loop. 4 Data Model As YAGL s primarily purpose is a language to programmatically create SVGs (scalable vector graphics), it makes sense to have just one global SVG Object. This is similar in spirit to EmcaScript s global this object which represents the host environment. Although end users in YAGL may not get a handle on the SVG Object, they may interact with it using builtin library functions such as title, addrect, addcircle, etc. This data model simplifies the end user s experience by allowing them to focus on their algorithmic manipulation of their data. A call to makegraph along with initial parameters executes the code from top to bottom. All code written after a call to makegraph is not executed. 5 Expressions The precedence of expression operators follows the regular laws of mathematics aside from division, which returns integer division as YAGL only features integers as its native numeric type. 6 Array References An array identifier followed by a set of square brackets enclosing an integer literal to denote the index denotes array indexing, i.e. myarray[4]. Indexing out of bounds in an array causes a compile time error. 3

7 Dictionary References A Dictionary identifier followed by a set of square brackets enclosing a string literal performs a lookup. Performing a lookup on a Dictionary where the key does not exist returns -1, else it returns the value associated with the key. 8 Function Calls A function call is a postfix expression which is performed by the identifier of the function followed by a possibly empty set of parentheses. Functions may return an explicit value to their caller if they have a return expression defined in their body, else they return 0. 9 Operators 9.1 Multiplicative Operators The multiplicator operators *, /, division by 0 causes an exception. 9.2 Additive Operators The additive operators +, - group left to right where + denotes addition and - denotes subtraction 9.3 Relational Operators The relational operators group left to right and return back 1 if the operator evaluates to true and 0 if the operator evaluates to false. 9.4 Equality Operators The equality operator == is only valid for either Integer or String types and returns 1 if the operands are equal, 0 otherwise. 4

9.5 Logical And The && operators groups left to right and returns 1 if both its operands compare unequal to zero with 9 otherwise, logical and is only defined for integers. 9.6 Logical Or The operators group left to right and returns 1 if either of its operands compares unequal to zero and 0 otherwise. 9.7 Assignment Expressions There is only one assignment operator, =. The equals operator accepts a type declaration along with a NAME token for its left operand and an expression for its right operand. 9.8 Comma Operator A pair of expressions separated by a comma is strictly evaluated left-to-right and the value of the left expression is discarded. 10 Type Specifiers The type specifiers are: Array, Dict, Int, String They are used in declaring variables, see Assignment Expressions. 11 Function Declarators A YAGL function has the form: func functionname (argument_list) { #some code #optional return expression } a function returns any primitive type: Array, Int, Dict, or String. Execution of function code terminates upon flow of execution reaching the return statement, at which point the return 5

expression evaluated value is returned to the caller. If no return statement is present, then the function returns 0 without need of an explicit return declaration. The parameter list is a comma-separated series of identifiers with type names (for example, (int a, int b, int c). The parameter list can also be empty and just be an empty set of parenthesis. 12 Scope 12.1 Lexical Scope Identifiers are placed into non-intersecting namespaces. The two namespaces are functions and file level. The lexical scope of an object or function identifier that appears in a block begins at the end of its declarator and persists to the end of the block in which it appears. The scope of a parameter of a function begins at the start of the function block and extends to the end. If an identifier is reused at the head of a block or as a function parameter, any other declaration of the identifier is shadowed until the end of the block or function. 13 Statements 13.1 Compound Statements Compound statements are a series of statements enclosed in braces that define their own lexical block. 13.2 Iteration Statements For loops iterate through Arrays or Dictionaries. The type specifier is given as a parameter in the for loop. If the array contains no objects of the specified type, the loop simply does not execute. For an array, the variable specified will be bound to each of the elements of the array sequentially and the loop statement will run. For a Dictionary, the string key will be bound to the variable specified in the for loop; moreover, the only allowed type for the iterated variable is String. Example Code: for (String a in mydict) { #body code 6

} for (Int i in myarray) { #body code } While loops execute after their boolean expression evaluates to 1 and continue onward until their test condition evaluates to 0. 13.3 Break and Continue The break keyword may only be used within the body of a for loop or a while loop. The break prematurely ends execution of the for or while loop. Analogously, the continue keyword may only be used within the body of a for or while loop and it signals the flow of control to move onto the next item in iteration. 13.4 If Statements In an if statement, the expression is evaluated, including side-effects, and if the result is not 0, the first substatement is executed. If it is equal to 0, the else substatement is executed if it exists. 14 Print Statements The print keyword takes an expression, evaluates it, then prints the result to standard output. If the expression evaluates to an int, it prints a string representation of the int, a string will output the ascii representation of the string, a dict will print Dict(%i) where %i would be replaced by the number of key-object pairs in the Dictionary, and similarly Array would print Array(%i) where %i is the number of elements in the array. 15 Example Code Below is an example program written in the YAGL language. 7

# This is an example of a YAGL program. # There is one global object always available, the Graph object that you # don t have a handle on, but will manipulate with makegraph Array myjson = jsonarray("/path/to/json/data.json") #Could also do jsondict which returns Dict func creategraph() { for (Dict item in myjson) { # Assuming everything in item["foo"] is string and adding a rect to the global singlet svg object. addrect(item["xcoord"], item["ycoord"], item["height"], item["width"]) #OR! addcircle(item["cx"], item["cy"], item["r"] } #Builtin function that provides a title to the global singleton svg object. title("yaet, Yet Another Example Title") } creategraph() # Need to call makegraph for the graph to be actually made makegraph(<nameoffile>, <width>, <height>) 16 Grammar This is the comprehensive Grammar for the YAGL programming language. The grammar has terminal symbols NAME, INTEGER, STRING, NEWLINE, OPERATORs, which includes +, -, /, *, %, and PUNCTUATION which includes (, ), {, and }. Note that * after a regular expression denotes zero or more instances of the expression, + denotes one or more instances and? denotes one or zero. type_spec: Array Dict Int String flow_stmt: break_stmt continue_stmt return_stmt break_stmt: break 8

continue_stmt: continue return_stmt: return [expr] func_definition: func NAME parameters { suite } suite: simple_stmt compound_stmt simple_stmt: (expr_stmt print_stmt) NEWLINE expr_stmt: asn_stmt, NEWLINE expr asn_stmt: type_specifier, NAME = expr expr: add_expr mult_expr div_expr sub_expr neg_int mod_expr INTEGER func_expr: NAME parameters add_expr: expr + expr mod_expr: expr % expr mult_expr: expr * expr div_expr: expr / expr sub_expr: expr - expr neg_int: - INTEGER print_stmt: print (NAME STRING INTEGER expr) compound_stmt: func_definition ( if_stmt while_stmt for_stmt simple_stmt )+ if_stmt: if ( bool_expr ) suite ( elif suite)* ( else suite)? while_stmt: while ( bool_expr ) suite for_stmt: for ( type_spec NAME in NAME ) { suite } bool_expr: 1 0 logic_and logic_or logic_and: expr && expr logic_or: expr expr comp_op: < > == >= <=!= parameters: ( [args_list] ) args_list: (type_spec NAME)* 9