PCASTL Data Types
C data types
To display the type of an expression, call gettype.
C data types
For detailed information about those types, see Wikipedia.
Numbers in a PCASTL syntax tree are 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". When casted and stored in a variable or displayed, numbers can have any of the C base data types.
> 0xA3 163 > 0xF0000000 -268435456 > 4.0 4 > a = (char)64 @ > gettype(a) "char" > a = (int)3.1416 3 > gettype(a) "int"
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. The first index is zero.
> a = "hello" "hello" > b = a e > gettype(b) "char" > "hello" l
In a string, an escape sequence indicate a special character. Escape sequences begin with a backslash (\) 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.
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")  28  "alpha" > a 28 > gettype(a) "array"
List are implemented as linked lists. They are created with the list function. The data is accesible with subscripts.
> b = list(3, 2, 1)  3  2  1 > b = 0 0 > b  3  2  0
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 0x378630 > gettype(a) "node pointer" > b = function() print("hello") 0x37f110 > gettype(b) "node pointer"
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.
Raw memory is a buffer dynamically allocated and can be obtained by functions vartomem, memclone and memory. Each byte of raw memory can be read or written with the subscript operator.
> a = memory(4) > gettype(a) "raw memory" > a 0x0 > a = 0xe1 0xe1
A byte is represented by an unsigned char and is the type received when applying the subscript operator in reading mode to raw memory.
> a = memory(4) > b = a 0x0 > gettype(b) "byte" > (byte) 255 0xff
Memory address is the type obtained when applying the address-of operator "&" to a variable of raw memory or string type to which we already applied the subscript operator.
> a = memory(4) > &a 0x335128 > b = &a 0x335129 > gettype(b) "memory address" > c = "abc" "abc" > gettype(&c) "memory address"
Pointer to types above.
If you apply the address-of (&) operator to a variable of any of the types given above, you will get a pointer to its space in memory. If you apply the indirection (*) operator to a variable containing a pointer, you will get the value of the first variable.
If you apply the address-of operator to a variable holding a pointer, you will get a pointer to a pointer. With this result you can apply the indirection operator twice.
If you apply the address-of operator to a variable holding an object, you can acces its contents with the pointer using the structure dereference (->) operator.
A number can also be casted to a pointer to one of the C data type. For the moment, we cannot cast to pointer to string, object, array or list.
> a = 42 42 > b = &a 0x2d0838 > gettype(b) "double*" > c = &b 0x2d08d8 > gettype(c) "double**" > **c 42 > a = names("x", "y") [x] undefined [y] undefined > b = &a 0x2d0838 > b->x = 5 5 > b->y = -5 -5 > a [x] 5 [y] -5