[{{mminutes}}:{{sseconds}}] X
Пользователь приглашает вас присоединиться к открытой игре игре с друзьями .
Squirrel — учебник по ЯП
(0)       Используют 5 человек


Ни одного комментария.
Написать тут
Учебник по данному языку программированию
до 15 июня 2009 (текущая версия от 24 июля 2011 в 17:19)
Тип словаря:
Последовательные отрывки из загруженного файла.
234 отрывка, 127754 символа
1 Chapter 1. Introduction
Squirrel is a high level imperative-OO programming language, designed to be a powerful scripting tool that fits in the size, memory bandwidth, and real-time requirements of applications like games. Although Squirrel offers a wide range of features like dynamic typing, delegation, higher order functions, generators, tail recursion, exception handling, automatic memory management, both compiler and virtual machine fit together in about 6k lines of C++ code.
2 1
Chapter 2. The language
This part of the document describes the syntax and semantics of the language.
Lexical structure
Identifiers start with a alphabetic character or '_' followed by any number of alphabetic characters, '_' or digits (0-9). Squirrel is a case sensitive language, this means that the lowercase and uppercase representation of the same alphabetic character are considered different characters.
3 For instance "foo", "Foo" and "fOo" will be treated as 3 distinct identifiers. id:= a-zA-Z_+a-zA-Z_0-9*
The following words are reserved words by the language and cannot be used as identifiers: base continue extends local throw instanceof break const for null try true case default foreach resume typeof false catch delete function return while static class else if switch yield clone enum in this constructor
Keywords are covered in detail later in this document.
4 Operators
Squirrel recognizes the following operators: ! <=> *= & != + % ^ += %= == ++ ~ && -= ->> <= <<< => = = >>> > *
Other tokens
Other used tokens are: { } . : :: ' ; " @"
The language
Squirrel accepts integer numbers, floating point numbers and stings literals. 34 0xFF00A120 0753 'a' 1.52 1.e2 1.e-2 "I'm a string" @"I'm a verbatim string" @" I'm a multiline verbatim string " Integer number(base 10) Integer number(base 16) Integer number(base 8) Integer number Floating point number Floating point number Floating point number String String String
IntegerLiteral := 0-9+ '0x' 0-9A-Fa-f+ ''' .+ ''' 00-7+ FloatLiteral := 0-9+ '.' 0-9+ FloatLiteral := 0-9+ '.' 'e''E' '+''-' 0-9+ StringLiteral:= '"'.* '"' VerbatimStringLiteral:= '@''"'.* '"'
A comment is text that the compiler ignores but that is useful for programmers.
5 Comments are normally used to embed annotations in the code. The compiler treats them as white space. The * (slash, asterisk) characters, followed by any sequence of characters (including new lines), followed by the * characters. This syntax is the same as ANSI C. * this is a multiline comment. this lines will be ignored by the compiler *
The (two slashes) characters, followed by any sequence of characters.
6 A new line not immediately preceded by a backslash terminates this form of comment. It is commonly called a "single-line comment." this is a single line comment. this line will be ignored by the compiler
Values and Data types
Squirrel is a dynamically typed language so variables do not have a type, although they refer to a value 3
The language
that does have a type. Squirrel basic types are integer, float, string, null, table, array, function, generator, class, instance, bool, thread and userdata.
7 Integer
An Integer represents a 32 bits (or better) signed number. local local local local a b c d = = = = 123 decimal 0x0012 hexadecimal 075 octal 'w' char code
A float represents a 32 bits (or better) floating point number. local a=1.0 local b=0.234
Strings are an immutable sequence of characters to modify a string is necessary create a new one. Squirrel's strings, behave like C or C++, are delimited by quotation marks(") and can contain escape sequences(\t,\a,\b,
8 Verbatim string literals begin with @" and end with the matching quote. Verbatim string literals also can extend over a line break. If they do, they include any white space characters between the quotes:
local a = "I'm a wonderful string
" has a newline at the end of the string local x = @"I'm a verbatim string
" the
is copied in the string same as \
in a regular string "I'm a verbatim s The only exception to the "no escape sequence" rule for verbatim string literals is that you can put a double quotation mark inside a verbatim string by doubling it: local multiline = @" this is a multiline string it will ""embed"" all the new line characters "
The null value is a primitive value that represents the null, empty, or non-existent reference.
9 The type Null has exactly one value, called null. 4
The language
local a=null
the bool data type can have only two. They are the literals true and false. A bool value expresses the validity of a condition (tells whether the condition is true or false). local a = true;
Tables are associative containers implemented as pairs of keyvalue (called a slot). local t={} local test= { a=10 b=function(a) { return a+1; } }
Arrays are simple sequence of objects, their size is dynamic and their index starts always from 0.
10 local a="I'm","an","array" local b=null b0=a2;
Functions are similar to those in other C-like languages and to most programming languages in general, however there are a few key differences (see below).
Classes are associative containers implemented as pairs of keyvalue. Classes are created through a 'class expression' or a 'class statement'. class members can be inherited from another class object at creation time.

Выделите фрагменты страницы, относящиеся к вашему сообщению
Скрыть сведения
Скрыть всю личную информацию