EMPATH LANGUAGE REFERENCE MANUAL

Similar documents
Empath. A Modeling Language for Living Beings. White Paper. Jeremy Posner, Nalini Kartha, Sampada Sonalkar, William Mee

Typescript on LLVM Language Reference Manual

1 Lexical Considerations

Lexical Considerations

Lexical Considerations

Decaf Language Reference Manual

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

ASML 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

The PCAT Programming Language Reference Manual

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

The Decaf Language. 1 Lexical considerations

The SPL Programming Language Reference Manual

The Decaf language 1

Full file at

JME Language Reference Manual

Language Reference Manual simplicity

Decaf Language Reference

CS143 Handout 03 Summer 2012 June 27, 2012 Decaf Specification

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

corgi Language Reference Manual COMS W4115

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

FRAC: Language Reference Manual

SSOL Language Reference Manual

Java Notes. 10th ICSE. Saravanan Ganesh

ARG! Language Reference Manual

UNIT- 3 Introduction to C++

VLC : Language Reference Manual

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

Key Differences Between Python and Java

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

RSL Reference Manual

GOLD Language Reference Manual

d-file Language Reference Manual

COLOGO A Graph Language Reference Manual

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

YOLOP Language Reference Manual

Flow Language Reference Manual

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

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

SMURF Language Reference Manual Serial MUsic Represented as Functions

Language Reference Manual

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

IC Language Specification

Language Reference Manual

Chapter 2: Basic Elements of C++

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

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

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual

A Short Summary of Javali

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

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

TML Language Reference Manual

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

Data Types and Variables in C language

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

FSASIM: A Simulator for Finite-State Automata

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

B E C Y. Reference Manual

Pace University. Fundamental Concepts of CS121 1

CSC 467 Lecture 3: Regular Expressions

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

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

String Computation Program

easel LANGUAGE REFERENCE MANUAL

Expr Language Reference

GAWK Language Reference Manual

The MaSH Programming Language At the Statements Level

Chapter 2 Basic Elements of C++

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567)

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

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

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

Lecture 2 Tao Wang 1

Basic Types, Variables, Literals, Constants

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Slang Reference Manual

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

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

Visual C# Instructor s Manual Table of Contents

YAGL: Yet Another Graphing Language Language Reference Manual

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

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

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

Petros: A Multi-purpose Text File Manipulation Language

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.

L-System Fractal Generator: Language Reference Manual

BASIC ELEMENTS OF A COMPUTER PROGRAM

Java+- Language Reference Manual

Language Reference Manual

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

PLT 4115 LRM: JaTesté

CMAT Language - Language Reference Manual COMS 4115

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

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

PYTHON- AN INNOVATION

3. Java - Language Constructs I

NAME CHSM-Java Concurrent, Hierarchical, Finite State Machine specification language for Java

CA4003 Compiler Construction Assignment Language Definition

Transcription:

EMPATH LANGUAGE REFERENCE MANUAL Jeremy Posner jp2288@columbia.edu Nalini Kartha nkk2106@columbia.edu Sampada Sonalkar ss3119@columbia.edu William Mee wjm2107@columbia.edu COMS4115 Programming Languages and Translators 19 October 2006

Introduction This document is a formal reference for the Empath language, which is designed to model living beings in a simplified form. Grammar notation We use standard regular expression for expressing the production rules of the language. Symbols enclosed in single quotes are terminals. All other symbols are non-terminals. * represents zero or more occurrences of the preceding expression and + represents one or more occurrences. represents a choice between the two expressions on either side of the character and? means that the preceding expression is optional. Braces are used to give precedence and denote the scope of an operator. Lexical conventions Comments The // character combination represents a single line comment. For multi-line comments the /* character combination indicates start of comment block and character combination indicates end of comment block. The symbol sequence cannot appear within a multi-line comment. Tokens Tokens include identifiers, keywords, constants, operators, and punctuations. Identifiers Identifiers are represented by a sequence of letters and digits starting with an alphabetic character or an underscore character ( _ ). An identifier represents a name for one of the following constructs: variable, function, event, trigger, state. digit ( 0.. 9 ) letter id ( a.. z A.. Z ) ( _ letter) ( _ letter digit)* Keywords The following identifiers are reserved keywords and may not be used otherwise: boolean entity event float for 2/14

if init int label output range return state string tick to transition trigger void while The keywords may only be used in the lower case alphabet. The language is case sensitive, so an identifier age is distinct from AGE or Age. The Java convention of identifiers starting with lower case alphabet and judicious use of upper case characters as separators is encouraged. Operators The language supports a small set of mathematical and logical operators for manipulating entity characteristics. The precedence and associativity rules for these operators are the same as those of mainstream programming languages, specifically C 1, hence we will not redefine them in this manual. Arithmetic operators + - * / % Shorthand arithmetic operators += -= *= /= Relational operators < > <= >= ==!= Logical operators && Punctuation The following characters are used for punctuation in the language ; statement end, argument list separator = declaration initializer string literal.. range specifier [ ] range delimiter or array index delimiter { function body or block statement delimiter ( ) function parameter list delimiter Constants The language defines integer constants, real constants (including only a fractional part, no exponents), boolean constants and string constants Const IntConst RealConst BoolConst StrConst IntConst digit + RealConst (digit) *. (digit) + 1 For a definition of this precedence, see the C Reference Manual (Ritchie) available online at http://cm.bell-labs.com/cm/cs/who/dmr/cman.pdf 3/14

BoolConst ( true false ) StrConst ( letter digit! # % ^ & * ( ) - _ = + ~ ' : ;? / \ { [ ],. < > $ )* A can be included within a string by escaping it with another, i.e.. Line Terminators and Whitespace ASCII spaces, tabs, new line, carriage returns and form feeds are all considered as whitespaces. Whitespace is ignored except as a token separator. In-built functions The following function names are not keywords but similar to the main function name in languages like C and Java - if present have a special meaning for the runtime environment: onclocktick onentry onexit This is explained in more detail below. 4/14

Empath Language Specification Overview An Empath program essentially consists of a description of the characteristics of an entity, a finite state machine (FSM) for representing its lifecycle, and a set of options (known as events) available to the user for interacting with the entity. An example piece of Empath code and an accompanying FSM is given in an appendix at the end of this document to make the understanding of this language reference manual easier. In general, Empath is a C-like language (similar to Java or C#) in its use of curly braces, operators, function definitions etc. The nature of the Empath language necessitates the use of such constructs for performing simple arithmetic and logical operations on entity characteristics; and we did not want to reinvent the wheel in defining an unusual syntax. Entity Specification The entity specification gives a name to the entity being modeled and specifies the associated variables (usually characteristics of the entity), functions, states and transitions. The entity specification may also optionally include an embedded specification for one or more of the states of the entity. There can be only one entity specification in an empath program and the program must begin with it. All other constructs of the empath program are embedded in the entity specification block. EntitySpec entity id ProgramBody State Specification A state specification is very similar to an entity specification. A simple state is one defined as an FSM without any FSMs embedded inside it, and including at most one or more of the special functions onclocktick(), onentry() and onexit() functions, but no more. If a state is complex (with a single FSM embedded inside it to form a hierarchy), it may include the above mentioned functions, but also a description of the embedded FSM. This distinction is important conceptually, but is not part of the language specification per se. Figure 1 in Appendix describes a dog entity. Here Dead is a simple state. The Puppy state is a complex state and includes a description of the daily activities of a puppy. StateSpec state id ProgramBody ProgramBody ( label StrConst)? 5/14

{ (Decls)? (FuncDef)? (States Trans)? (StateSpec)* The label keyword is used to specify a string that is passed to the user interface for display purpose. The id is used as an internal handle. Labels are used for states and functions, particularly events. States This lists the names of the set of possible states that the entity can be in. It works like a forward declaration for states, and is helpful to the programmer while specifying the transitions. The detailed definition for a state can be defined later in the StateSpec block. The initial state (the default state which the entity will be in at the beginning of execution of the program) is marked by including the keyword init before the corresponding state name. If the initial state is not thus explicitly marked then it is assumed to be the first state listed. The suggested convention for state names is that they be capitalized however this is not a requirement. States state (init)? id (, (init)? id) * ; Transition Specification A transition specification defines the possible transitions that can occur between the entity s states. Each transition must specify a from state, a to state, a trigger and, optionally, an action. The trigger may be an expression which evaluates to a boolean value or a trigger function. Trans transition ((id * ) to id if ( Condition ) ( / FuncCall)?) (, (id * ) to id if ( Condition ) ( / FuncCall)?)* ; Condition -> Expr FuncCall A * in place of a from state is a shorthand operator signifies that a transition can be taken from any of the states in this FSM to a state outside the FSM. In general we allow inter-level transitions from an inner-level state to a higher level state. It would be useful to mention here that the semantics of execution of this FSM are as follows: Transitions are evaluated from outside to inside A transition triggered at an outer level preempts transitions triggered at an inner level. Variable Declarations: Decls Decl Decls ε 6/14

Decl Type (id ( = Const)? ((, id ( = Const)?) *) ; Type int float boolean string range [ (digit+).. (digit+) ] ; Function Definitions Because of the problem domain which Empath is addressing, in particular its use of FSMs to define the states that an entity is in, there are several different categories of functions. These are described below. Event: An event is a special type of function which is qualified with the keyword event. These functions are marked to be visible to the user interface. They provide a means of interaction with the Empath program, and it is necessary to mark a function so that it can be recognized as a user input by the user interface. Trigger: A trigger is a special type of function which is qualified with the keyword trigger. These functions have the sole purpose of evaluating if a threshold has been reached and if the corresponding transition will be carried out. As such they are subject to the following restrictions: cannot modify characteristics return type must be boolean can optionally modify variables in local scope but cannot modify those which have global scope Action: An action is a function defined in the action part of a transition definition. The instructions in an action function will be executed if the trigger corresponding to the transition has been evaluated as true and the transition is fired. An action cannot return a value i.e. the return type of an action must be void. Any function whose return type is void can be an action. FuncCall id ( (id (, id)*)? ) FuncDef Func RetType FuncBody Statement Func FuncDef ε ( trigger event RetType) ( label StrConst)? id ( (Type id ((, Type id)*)? ) { FuncBody void Type Statement* Decls Expr ; if ( Expr ) (Statement StatementBlock) if ( Expr ) (Statement StatementBlock) else (Statement StatementBlock) for ( (Expr)? ; (Expr)? ; (Expr)? ) (Statement StatementBlock) 7/14

while ( Expr ) (Statement StatementBlock) output ( Expr ) ; return (Expr)? ; StatementBlock { Statement + Expr ( Expr ) id Const FuncCall id = Expr IncrExpr ArithExpr RelExpr LogicalExpr tick IntConst id @max id @min IncrExpr id ++ id -- ArithExpr Expr * Expr Expr / Expr Expr % Expr Expr + Expr Expr - Expr id += Expr id -= Expr id *= Expr id /= Expr RelExpr Expr == Expr Expr!= Expr Expr > Expr Expr < Expr Expr >= Expr Expr <= Expr LogicalExpr Expr && Expr Expr Expr Most of the statements and expressions are similar to those in the C or Java language. We describe the new ones: output(x): The parameter of this statement is passed to the UI for displaying tick n: This expression is useful in the onclocktick() method where on every nth clock tick some characteristic is changed. id @max: This expression checks whether a range type variable has attained the maximum value defined in the range. id @min: Similarly, this expression checks whether a variable has attained the minimum value defined in the range. 8/14

Special Functions As already mentioned, Empath attaches special meaning to certain function names to provide FSM functionality. These function names and how they are handled are given in the table below onclocktick onentry onexit executed for every clock cycle that an entity is in a state executed once when a state is entered executed once when a state is exited 9/14

Appendix A: Example FSM for Dog Entity Here we give the FSMs which are described by the example code in Appendix B. Wagging Tail happiness <=3 happiness==10 Puppy Whining Barking timesincelast Walk >= 115 timesincelast Walk ==30 Needs Walk Adult hunger >=8 hunger @min hunger >=8 milkdrunk>50 && age >=10 hunger >=8 hunger ==0 hunger >=8 Hungry Hungry starve() / bury() age >= MAX_AGE hunger @max Dead Figure 1: Lifecycle of a Dog entity 10/14

Appendix B: Example Empath Code for Dog Entity /* The following defines the high level entity or creature that is being simulated. The definition of the entity includes a set of characteristic variables, a set of events that can occur while interacting with the entity, a set of states that the entity can be in, the possible transitions between states as well as any possible subentities or substates entity dog label Pet Tommy { /* Set of characteristics for the dog entity which are seen * within this scope * Empath supports the following characteristics * int - integer * float - floating point value * string - text value * boolean - boolean value * range - bounded range of values defined by two ints as inclusive upper and lower bounds string name = Tommy ; float age = 0.0; /* a range characteristic range [0.. 10] happiness = 5; //range is inclusive range [0.. 100] hunger = 70; //syntatic sugar for range [0..100] int MAX_AGE = 20; /* events are marked functions which are visible to the user interface * they offer a means of interaction event feed() label "Feed the Dog" { hunger=0; /* this is a function which is used as a threshold trigger * triggers * - cannot modify characteristics * - must return a boolean value * - can optionally modify variables in local scope trigger starve() { if (hunger>95) { returnvalue= true; else { return false; /* this is an action (i.e. emission) which is called when a transition is taken. It * cannot return a value 11/14

* any function can be an action void bury() { /* this is a normal function string getname() { return name; /* "onclocktick" is a special function which is called on every * clock cycle. onclocktick() { if (tick 4) { hunger++; else { age+ = 0.1; /* The following is the set of states that the "dog" entity * can be in. The first state in the list is taken to be the * initial state by default. * * By convention, states are capitalized - this is not enforced * state init Puppy, Adult; state Dead; /* The following is the list of transitions defined between * states of the dog entity. This list must begin with the * keyword "transition". The individual transition definitions * must be separated by commas and the list must be terminated * with a semicolon. * Each transition must be defined in the * following format * From_state to To_state if (condition) / action * the condition can be an inline conditional or a function which * returns a boolean value. The condition is always evaluated for * each transition so cannot update characteristics. * the action is optional and is invoked when the transition is triggered transition Puppy to Dead if (starve()) / bury() ; /* range support special operators @max and @min which return true if the * range is currently at its max or min limit respectively transition Adult to Dead if (age>=max_age hunger @max); 12/14

can /* The following defines the "lifecycle" states which this entity * be in during its life * the init keyword state Puppy label "Puppy" { int happiness = 10; range [0..100] milkdrunk=0; onclocktick() { hunger+ = 1; happiness=1; /* onentry() and onexit() are functions which, if defined, are invoked when * a state is entered or exited onentry() { output Hello world!!! My name is ; output name; onexit() { output I've grown up!!! ; event play() { happiness = 10; event suckle() { milkdrunk++; /* states Whining and Hungry have no further definition state init WaggingTail, Whining, Hungry; target transition WaggingTail to Hungry if (hunger >= 8), WaggingTail to Whining if (happiness <=3), Hungry to WaggingTail if (hunger @min), Whining to WaggingTail if (happiness == 10), Whining to Hungry if (hunger >=8); /* a wildcard * is used to denote from *any* state, and the state is normally at the parent level transition * to Adult if (milkdrunk>50 && age>=10); state WaggingTail { onentry() { happiness = 10; /* an adult dog state Adult { int timesincelastwalk = 0; onentry() { 13/14

onclocktick() { hunger+ = 1; timesincelastwalk++; onexit() { event walk() { timesincelastwalk = 0; state Barking, Hungry, NeedsWalk; transition Barking to Hungry if (hunger >= 8), Hungry to Barking if (hunger == 0), Barking to NeedsWalk if (timesincelastwalk > 115 ), NeedsWalk to Barking if (timesincelastwalk == 30), NeedsWalk to Hungry if (hunger >=8); state Barking { onentry() { timesincelastwalk = 0; /* the Dead state state Dead { onentry() { /* make the owner feel bad if the dog starved to death if ((hunger @max) && (age<max_age)) /* output is understood differently by the different ui's output ("Shame on you!! Your dog died!!"); else output ("Dog died of old age"); 14/14