Presentation is loading. Please wait.

Presentation is loading. Please wait.

Squirrel Programming Language By Nandini Bhatta CS537 Summer 2008.

Similar presentations


Presentation on theme: "Squirrel Programming Language By Nandini Bhatta CS537 Summer 2008."— Presentation transcript:

1 Squirrel Programming Language By Nandini Bhatta CS537 Summer 2008

2 Contents Introduction Features Development State Keywords & Operators Data types Functions, Class & Class instance Variables Local & Global variables…. Squirrel statements Function declaration Class declaration Array Constructor Groovy Vs Squirrel Syntax Comparision Examples Work in progress References

3 Introduction Started in the year 2003 High level OO programming language Light weight programming language featuring higher- order functions, classes/inheritance Powerful scripting tool that fits in the size, memory bandwidth Real-time requirements of applications like games It has a C-like syntax

4 Features Open Source Inheritance Exception Handling Polymorphism Compiles on both 32-bit & 64-bit architectures Tail Recursion Dymanic Typing Automatic memory management

5 Development State Two versions : 1.01 & 2.2.1 The current stable release is 2.2.1 It can be Compiled and run on Windows and Linux Squirrel is known to run also on MacOS X, GameCube, PSP and XBOX

6 Keywords & Operators Similar to keywords & operators in Java Keyword examples : case, catch, class, constructor, parent, yield, while, return, resume, null default, delegate, delete, else, enum, switch, true, false, throw, try…. Operators examples : !,!=, ||, ==, &&, >, + +,/, /=, *, *=, %, %=, ++, --, <-, =, &, ^………

7 Data types Squirrel is a dynamically typed language so variables have no types They refer to a value that does not have a type Squirrel basic types include integer, float, string, null, table, array, function, generator, class, instance, Boolean

8 Functions, Class & Class instance Functions similar to those in C language Classes created through class expression or class statement. Class members are inherited from another class object at creation time. After creation, members can be added until an instance of the class is created.

9 Variables Two types of variables in squirrel : local and global variables. Global variables stored in tables and hence referred to as table slots

10 Local & Global variables…. Squirrel first checks if an identifier is local variable (function arguments) If not it checks if it is a member of the environment object (this) For example : function testy(arg) { local a=10; print(a); return arg; } will access to local variable 'a' and prints 10. function testy(arg) { local a=10; return arg+foo; } In this case ’foo’ is treated as ‘this.foo’

11 Global variables Global variables are stored in root table Environment object is the root table To explicitly access global table from another scope, the slot name must be pre fixed with ‘::’

12 Example: Accessing global variable To access global variable ‘foo’ function testy(arg) { local a=10; return arg +::foo; }

13 Squirrel statements Squirrel program is a simple sequence of statements Squirrel statements are similar to C statements such as assignment, function calls, program flow control structures etc. Statements can be separated with new lines or using ‘;’ stats := stat [';'|'\n'] stats

14 Function declaration Syntax: funcname := id [ '::' id] stat:= 'function' id [ '::' id]+ '(' args ')'[ ':' '(' args ')'] stat Example: T <- { } function T::ciao(a,b,c) { return a+b-c; }

15 Class declaration To create a new class : Syntax: memberdecl : = id '=' exp [ ';'] | '[ ' exp ']' '=' exp [ ';'] | functionstat | 'constructor' stat:= 'class' derefexp ['extends' derefexp] '{' [memberdecl] '}‘

16 contd… Example : class Foo { //constructor constructor(a) { testy = ["stuff",1,2,3]; } //member function function PrintTesty() { foreach(i,val in testy) { ::print("idx = "+i+" = "+val+" \n"); } //property testy = null; }

17 Array Constructor Syntax: exp := ‘[’ [explist] ‘]’ Example: a <- [ ] //creates an empty array Arrays can be initialized with values during the construction Example: a <- [1,"string!",[ ],{ }] //creates an array with 4 elements

18 Groovy Vs Squirrel Both are object oriented and dynamic languages. Both can be used as a Scripting Language for the Java Platform. Groovy syntax is similar to Java where as Squirrel syntax is similar to C.

19 Syntax Comparision The following presents a side-by-side comparison of Groovy with Squirrel: Example 1: Print Statement: Groovy: println "hello world" Squirrel: Local a= “hello world”; Print (a) ;

20 Example 2 Groovy: def x = 1..10 x.each{println it} Squirrel: local a=0; do { print(a+"\n"); a+=1; } while(a>10

21 Example 3 Groovy: if (a>b) { assert c == a-b println c } else { assert c == b-a println c } Squirrel: if(a>b) { c= a-b; print (c); } else { c=b-a; Print (c); }

22 Inheritance Example class Foo { function DoSomething() { ::print("I'm the base"); } }; class SuperFoo extends Foo { //overridden method function DoSomething() { //calls the base method ::Foo.DoSomething(); ::print("I'm doing something"); }

23 Work in progress Comparision with Groovy and Java Exploring Squirrel with game programming Exploring Squirrel SQL database

24 References www.squirrel-lang.org/doc/squirrel2.pdf www.wikipedia.org www.sourceforge.net www.experiencefestival.com/squirrel_programming_l anguage_-_syntax www.experiencefestival.com/squirrel_programming_l anguage_-_syntax


Download ppt "Squirrel Programming Language By Nandini Bhatta CS537 Summer 2008."

Similar presentations


Ads by Google