pcosmos.ca

le domaine de Philippe Choquette

Accueil Profil Contact Arrière plan
PCASTL
Half-Life
Informatique
OpenGL
Linux
Grow
Elements
Lecture
Liens

PCASTL Data Types

Page en français

Number
String
Array
List
Object
Pointer to node
Pointer to FILE structure
Pointer to fpos_t

To display the type of an expression, call gettype.

Number

Numbers in PCASTL are internally stored as C double. When entered in hexadecimal notation, they are taken as signed integers berfore being casted to double. Hexadecimal notation have to begin with "0x". Even if they are displayed without a decimal point and trailing zeros, they are still double.

> 0xA3
        163
> 0xF0000000
        -268435456
> 4.0
        4
String

Strings in PCASTL are dynamically allocated C char arrays. When you call function length, you receive the length of the allocated memory. To get the number of characters before the ending null character, call strlen.

To get a character in a string at a given index, you can use a subscript if the string is in a variable. The first index is zero. The result is a string of one character before the null ending.

> a = "abc"
        "abc"
> a[1]
        "b"

In a string, an escape sequence indicate a special character. Escape sequences begin with a backslash (\) character.

Sequence Name
\a Alert (bell)
\b Backspace
\f Formfeed
\n Newline
\r Carriage return
\t Horizontal tab
\v Vertical tab
\? Literal quotation mark
\' Single quotation mark
\" Double quotation mark
\\ Backslash
\ddd ASCII character in octal notation
\xdd ASCII character in hex notation
\0 Null character

Note that for characters notated in hexadecimal, the interperter ignores all leading zeros. It establishes the end of the hex-specified escape character when it encounters either the first non-hex character or more than two hex characters — not including leading zeros.

Table and following paragraph are from Microsoft Visual C++ 6.0 Docs.

Array

Arrays are dynamically allocated arrays of variable like elements. They are contiguous in memory. Unlike in C or R, each of those variables can have a different type. Arrays are created with the array function. The data is accesible with subscripts.

> a = array(28, "alpha")
[0]     28
[1]     "alpha"
> a[0]
        28
> gettype(a)
        "array"
List

List are implemented as linked lists. They are created with the list function. The data is accesible with subscripts.

> b = list(3, 2, 1)
[0]     3
[1]     2
[2]     1
> b[2] = 0
        0
> b
[0]     3
[1]     2
[2]     0
Object

Objects are created with the names function. An object is a group of variables, accessibles with the dot (.) operator. If a member of an object is a function, variables accessed inside this function are searched inside the object's context before looking outside.

> id = names("name", "age")
[name]  undefined
[age]   undefined
> id.name = "Philippe"
        "Philippe"
> id.age = 29
        29
> id
[name]  "Philippe"
[age]   29
> gettype(id)
        "object"
Pointer to node

A function definition return a node pointer, as well as a genealogical dotted list. An explicit code segment also give a node pointer. Nodes are basic elements of the syntax tree of the code. The syntax tree structure is illustrated in the Tree Structure page.

> a = parent
        0x3308e8
> gettype(a)
        "reference"
> b = function() print("hello")
        0x333068
> gettype(b)
        "reference"
Pointer to FILE structure

A FILE structure pointer is given by the fopen function. This type is used by the stream manipulation functions. Predefined stream identifiers stdin, stdout and stderr are of the FILE pointer type.

Pointer to fpos_t

The pointer to fpos_t type is exclusively used by functions fgetpos and fsetpos. It's a position in a file.

back to PCASTL