| Accueil | Profil | Contact | Arrière plan |
|
|
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"
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.
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.
Pointer to types above.
If you apply the reference (&) 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 reference 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 reference operator to a variable holding an object, you can acces its contents with the pointer using the 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
|