FR

pcosmos.ca

Philippe Choquette's universe

Home
News
Profile
Contact
Half-Life
Music
PCASTL
Computer Science
Videos
Readings
OpenGL
Elements
C64 sids
Links
Operators
Data Types
Internal Functions
Tree Structure
Batch Execution
Examples
Interpreter

PCASTL Internal Functions

Categorical Listing

Input and Output Functions

Control Flow Functions

Tree Manipulation Functions

Object Manipulation Functions

Array, Chained List, Statements List and String Manipulation Functions

Dynamic-Link Libraries and Shared Object Libraries Access Functions

Memory Manipulation Functions

ANSI C stdio.h Interface

Type Conversion Functions

Utility Functions

Alphabetical Listing

abort
alloc_copy
appendnode
array
as_array
as_list
as_statements
aton
atovar
clear
clearerr
closelib
cls
codetotree
concat
copystring
copytree
createnode
detachnode
execute
exist
exit
fclose
feof
ferror
fflush
fgetc
fgetpos
fgets
fillobject
fopen
fprintf
fputc
fread
free
freestring
freetree
freopen
fscanf
fseek
fsetpos
ftell
fwrite
getfuncpt
gettype
getwd
info
insert
insertnode
length
list
memclone
memcpy
memory
memset
memtovar
mknode
names
ntoa
openlib
osfamily
popback
popfront
print
printf
prompt
pushback
pushfront
read
remove
repeat
replace
replacenode
return
rewind
rmnode
scan
scanf
setlength
setwd
source
sprintf
sscanf
strclone
strcpy
strlen
subseq
swapnodes
tmpfile
tonode
treetocode
undefine
ungetc
value
vartoa
vartomem
write


abort()

This function stops the execution of the submitted statement list and resets the interpreter to an user input waiting state.


alloc_copy(arg)

This function takes any type of argument, allocates a copy of it and returns a pointer to the copy.


appendnode(parent_node, child_node)

This function adds as child the node which a pointer to is received as second argument to the node which a pointer to is received as first argument. The returned value is the undefined value.

> a = createnode("mathematical operator", "="[0])
        0x2a8110
> appendnode(a, createnode("variable", "builtfact"))
> appendnode(a, createnode("function definition"))
> appendnode(a.childset[1], createnode("list"))
> appendnode(a.childset[1], createnode("list"))
> appendnode(a.childset[1].childset[0], createnode("variable", "x"))
> appendnode(a.childset[1].childset[1], createnode("if"))
> appendnode(a.childset[1].childset[1].childset[0], codetotree("x == 1"))
> appendnode(a.childset[1].childset[1].childset[0], codetotree("return(1)")
)
> appendnode(a.childset[1].childset[1], createnode("function call"))
> appendnode(a.childset[1].childset[1].childset[1], createnode("variable",
"return"))
> appendnode(a.childset[1].childset[1].childset[1], createnode("list"))
> appendnode(a.childset[1].childset[1].childset[1].childset[1], codetotree(
"x * builtfact(x - 1)"))
> printf(concat(treetocode(a), "\n"))
builtfact = function(x)
{
   if (x == 1) return(1)
   return(x * builtfact(x - 1))
}

array([arg1[, arg2[, ...]]])

This function takes as many arguments as you want, evaluates them and return an array of the according length.

> a = array(1, 2, "c_letter")
[0]     1
[1]     2
[2]     "c_letter"
> a[1]
        2
> a[2] = 3
        3
> a
[0]     1
[1]     2
[2]     3
> array(1,2,array(3,4))
[0]     1
[1]     2
[2][0]  3
[2][1]  4

as_array(sequence)

This function takes one argument, which can be a chained list or a pointer to a statement list. The returned value is an array of the same length of the given sequence. If the sequence is a chained list, then the content of each item will be the same. If the sequence is a statement list, then the items of the output will only be defined for corresponding string or number nodes.

> a = scan()
string scanning in progress!
        0x330bf8
> as_array(a)
[0]     "string"
[1]     "scanning"
[2]     "in"
[3]     "progress"
[4]     "!"
> a = `{0 1 {}}'.childset[0]
        0x332cd0
> as_array(a)
[0]     0
[1]     1
[2]     undefined

as_list(sequence)

This function takes one argument, which can be an array or a pointer to a statement list. The returned value is an chained list of the same length of the given sequence. If the sequence is an array, then the content of each item will be the same. If the sequence is a statement list, then the items of the output will only be defined for corresponding string or number nodes.


as_statements(sequence)

This function takes one argument, which can be an array or a chained list. The returned value is an statement list of the same length of the given sequence. The items of the output will only be defined for corresponding string of number input items. The undefined nodes are given the numerical value zero.

> a = list("ab", "cd")
[0]     "ab"
[1]     "cd"
> b = as_statements(a)
        0x330ba0
> value(b.childset[0])
        "ab"

aton(string)

This function converts the string it receives as parameter to a numeric value. If the function can't convert, the returned value is zero.


atovar(string)

This function creates a node of "variable" type whose name is the string received as parameter. The string must begin by "_" or by a letter. The returned value is a pointer to the new node.

> a = atovar("newname")
        0x258320
> info(a)
[node_type]     "variable"
[nb_children]   0
[name]  "newname"

clear([symbol1[, symbol2[, ...]]])

This function can take no argument, or as many as you want. A call with no argument erases all the symbols in memory, variables and functions. Giving symbol names as arguments will cause their erasement. The returned value is the undefined value. It's like void in C.

> a = 1
        1
> a
        1
> clear(a)
> a
Error: Symbol "a" not found.

clearerr(stream)

Resets the error indicator for a stream. The parameter is a pointer to a FILE structure. The clearerr function resets the error indicator and end-of-file indicator for stream. Error indicators are not automatically cleared; once the error indicator for a specified stream is set, operations on that stream continue to return an error value until clearerr, fseek, fsetpos, or rewind is called.

Text in most part from Microsoft Visual C++ 6.0 Docs.


closelib(handle)

Ends the access to a .dll file on Windows, to a .so file son Linux or to a .dylib file on Mac OS. The parameter is a handle obtained with the openlib function. On Windows, the returned value is one (1) in case of success, while on Linux and Mac OS, the returned value is zero in case of success.


cls()

Clears the console screen. This function does not have parameters. The returned value is the undefined value.


codetotree(string)

This function returns a pointer to the root node of the syntax tree corresponding to the code (program) in the string received as argument.


concat(arg1, arg2[, arg3[, ...]])

This function takes two or more arguments, which can be arrays, chained lists, strings or statement lists. All argument have to be of the same type. The returned value is a concatenation of all the evaluated arguments.


copystring(string)

This function allocates and returns a copy of the string received as argument. Note that assigning of a string from a variable to another points toward the same memory.


copytree(node_pointer)

This function evaluates its argument to a node pointer. The node pointed is the root a tree. This tree is copied entirely and a pointer to the new root is returned. The new root has a NULL parent value.


createnode(string[, spec])

This function creates a node without child and returns a pointer to it. The values of member node_type returned by the info function can be used as first argument to createnode. However, the following aliases are accepted:

first argument alias
"numerical constant" "constant"
"mathematical operator"  
"relational or logical operator" "logical operator"
"relational operator"
"variable"  
"string"  
"function definition"  
"function call" "call"
"if statement" "if"
"if else statement" "if else"
"for statement" "for"
"while statement" "while"
"list"  
"code segment"  
"parent reserved word" "parent"
"childset reserved word" "childset"
"vargenlist"  
"incrementation or decrementation" "decr"
"decrementation"
"incr"
"incrementation"
"object member access list" "access list"
"subscript"  
"stdin FILE* identifier" "stdin"
"stdout FILE* identifier" "stdout"
"stderr FILE* identifier" "stderr"
"cast"  
"structure reference operator (.)" "."
"reference"
"structure reference operator"
"structure dereference operator (->)" "->"
"dereference"
"structure dereference operator"

The second argument depends on the content of the first:

first argument second argument
"numerical constant" a number of type double
"mathematical operator" one of the following c characters: -, +, *, /, ^, =, & which can be defined as: "c"[0]
"relational or logical operator" a string containing one of the following: "||", "&&", "!", ">", ">=", "<", "<=", "==", "!="
"variable" a string which contains the variable name
"string" a string that will be the content of the node
"incrementation or decrementation" a string containing one of the following: "prefix ++", "prefix --", "postfix ++", "postfix --"
"cast" a string containing one of the C data type with the desired number of asterisks (*) for a pointer type
"function definition" do not give a second argument
"function call"
"if statement"
"if else statement"
"for statement"
"while statement"
"list"
"code segment"
"parent reserved word"
"childset reserved word"
"vargenlist"
"object member access list"
"subscript"
"stdin FILE* identifier"
"stdout FILE* identifier"
"stderr FILE* identifier"
"structure reference operator (.)"
"structure dereference operator (->)"

An example of use is given in appendnode documentation.


detachnode(parent_node, position)

This function disconnects the child at the position received as second parameter of the parent node which a pointer to is received as first parameter. The other children of the parent node are shifted to fill the freed space. The returned value is a pointer to the root of the disconnected subtree.


execute(node_pointer)

This function takes a node pointer as parameter. The tree under the node is executed and the returned value is the returned value by the executed code.

> execute(`print("hello")'.childset[0])
        "hello"

exist(symbol)

This function receives a symbol as parameter and returns an integer which value is 1 if the symbol is found in the current scope or 0 if the symbol is not found. Note that if a symbol exists but is not defined, it will be found. Although error messages are displayed in case of non-existence, code execution will go on.


exit()

This function takes no argument and closes the interpreter.


fclose(stream)

Closes the file which pointer is received as argument. The return value is 0 if the file was successfully closed. Otherwise, the return value is -1.


feof(stream)

Tests for end-of-file on a stream. The parameter is a pointer to a FILE structure. The feof function returns a nonzero value after the first read operation that attempts to read past the end of the file. It returns 0 if the current position is not end of file. There is no error return.

The feof routine determines whether the end of stream has been reached. When end of file is reached, read operations return an end-of-file indicator until the stream is closed or until rewind, fsetpos, fseek, or clearerr is called against it.

Text in most part from Microsoft Visual C++ 6.0 Docs.


ferror(stream)

Tests for an error on a stream. The parameter is a pointer to a FILE structure. If no error has occurred on stream, ferror returns 0. Otherwise, it returns a nonzero value.

The ferror routine tests for a reading or writing error on the file associated with stream. If an error has occurred, the error indicator for the stream remains set until the stream is closed or rewound, or until clearerr is called against it.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fflush(stream)

Flushes a stream. The parameter is a pointer to a FILE structure. fflush returns 0 if the buffer was successfully flushed. The value 0 is also returned in cases in which the specified stream has no buffer or is open for reading only. A return value of -1 (EOF) indicates an error.

The fflush function flushes a stream. If the file associated with stream is open for output, fflush writes to that file the contents of the buffer associated with the stream. If the stream is open for input, fflush clears the contents of the buffer. fflush negates the effect of any prior call to ungetc against stream. The stream remains open after the call. fflush has no effect on an unbuffered stream.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fgetc(stream)

Read a character from a stream. The parameter is a pointer to a FILE structure. fgetc return the character read in a string of length 2 (the second character is null) or return "\xff" (end-of-file) to indicate an error or end of file. Use feof or ferror to distinguish between an error and an end-of-file condition. If a read error occurs, the error indicator for the stream is set.

fgetc reads a single character from the current position of the file associated with stream. The function then increments the associated file pointer (if defined) to point to the next character. If the stream is at end of file, the end-of-file indicator for the stream is set.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fgetpos(stream, variable)

Gets a stream's file-position indicator. The first parameter is a pointer to a FILE structure. The second parameter is an already defined variable who will receive a pointer to a fpos_t structure. If the variable is not already a pointer to a fpos_t structure, it is converted to this type. If successful, fgetpos returns 0. On failure, it returns a nonzero value.

The fgetpos function gets the current value of the stream argument's file-position indicator and stores it in the object pointed to by variable. The fsetpos function can later use information stored in variable to reset the stream argument's pointer to its position at the time fgetpos was called. The fpos_t pointer type is intended for use only by fgetpos and fsetpos.

Text in most part from Microsoft Visual C++ 6.0 Docs.

> a = fopen("alphabet.txt", "r")
        0x462b50
> b = "    "
        "    "
> fread(b, 1, 4, a)
        4
> c = 0
        0
> fgetpos(a, c)
        0
> fread(b, 1, 4, a)
        4
> b
        "efgh"
> fread(b, 1, 4, a)
        4
> fsetpos(a, c)
        0
> fread(b, 1, 4, a)
        4
> b
        "efgh"
> fclose(a)
        0

fillobject(object, sequence)

This function takes two arguments. The first parameter is a symbol containing an object. The second parameter can be an array, a chained list or an object. If the sequence has less items than the object has member, then only the first members will receive a value. If the sequence has more items than the object has members, then the last items will be ignored. The returned value is the undefined value.

> a = names("b", "c", "d")
[b]     undefined
[c]     undefined
[d]     undefined
> fillobject(a, array(1,2))
> a
[b]     1
[c]     2
[d]     undefined

fgets(variable, count, stream)

The first parameter is a variable holding a string. The second parameter is the maximal number of characters to read. The last parameter is a pointer to FILE structure.

This function reads a string from the input stream argument and stores it in the string held by variable. The reading is done from the current stream position to and including the first newline character, to the end of the stream, or until the number of characters read is equal to count-1, whichever comes first. The result stored in the string of variable is appended with a null character. The newline character, if read, is included in the string of variable.

The returned value is the variable received as first argument. If there is an error or if the end of the stream occurs, an empty new string ("") is returned.

The above text comes in part from msdn.microsoft.com.


fopen(filename, mode)

The first parameter is a string holding the name of the file to be opened. The second parameter is a string holding the type access permitted. The return value is a pointer to the open file. A null pointer value indicates an error.

mode meaning
"r" Opens for reading. If the file does not exist or cannot be found, the fopen call fails.
"w" Opens an empty file for writing. If the given file exists, its contents are destroyed.
"a" Opens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; creates the file first if it doesn't exist.
"r+" Opens for both reading and writing. (The file must exist.)
"w+" Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed.
"a+" Opens for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn't exist.

When a file is opened with the "a" or "a+" access type, all write operations occur at the end of the file. The file pointer can be repositioned using fseek or rewind, but is always moved back to the end of the file before any write operation is carried out. Thus, existing data cannot be overwritten.

The "a+" mode is required for appending to a stream file that is terminated with the CTRL+Z EOF marker.

When the "r+", "w+", or "a+" access type is specified, both reading and writing are allowed (the file is said to be open for "update"). However, when you switch between reading and writing, there must be an intervening fflush, fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation, if desired.

In addition to the above values, the b character can be included in mode. It opens in binary (untranslated) mode; translations involving carriage-return and linefeed characters are suppressed.

Text in most part from Microsoft Visual C++ 6.0 Docs.

> a = fopen("test.txt", "w")
        0x462b50

fprintf(stream, string[, argument]...)

Prints formatted data to a stream. The first parameter is a pointer to a FILE structure. You can also write stdout or stderr. The second argument is the string to be written, which can include format specifications for the other arguments, if any. Each other argument is converted and output according to the corresponding format specification in format. The returned value is the undefined value.

> a = fopen("test.txt", "w")
        0x462b50
> fprintf(a, "text")
> fclose(a)
        0
> fprintf(stdout, "%s\n", "hello")
hello

fputc(string, stream)

Writes a character to a stream. The first parameter is a string containing the character to write at position 0 and null terminated at position 1. The second parameter is a pointer to a FILE structure. The return value is a string containing the character written. A return value of "\xff" (EOF) indicates an error.

fputc writes the single character string[0] to a file at the position indicated by the associated file position indicator (if defined) and advances the indicator as appropriate. The file is associated with stream. If the file cannot support positioning requests or was opened in append mode, the character is appended to the end of the stream.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fread(variable, size, count, stream)

Reads data from a stream. The first parameter is a variable of the string type where to store the read data. The second parameter is the size in bytes of the items read. The third parameter is the maximum number of items read. The last parameter is a pointer to a FILE structure.

fread returns the number of full items actually read, which may be less than count if an error occurs or if the end of the file is encountered before reaching count. Use the feof or ferror function to distinguish a read error from an end-of-file condition. If size or count is 0, fread returns 0 and the variable contents are unchanged.

The fread function reads up to count items of size bytes from the input stream and stores them in variable. The file pointer associated with stream (if there is one) is increased by the number of bytes actually read. If the given stream is opened in text mode and if the operating system is Windows, carriage return-linefeed pairs are replaced with single linefeed characters. The replacement has no effect on the file pointer or the return value. The file-pointer position is indeterminate if an error occurs. The value of a partially read item cannot be determined.

Text in most part from Microsoft Visual C++ 6.0 Docs.

> b = ""
        ""
> setlength(b, 10)
> a = fopen("alphabet.txt", "r")
        0x462b50
> fread(b, 2, 3, a)
        3
> b[6] = "\0"
        ""
> fclose(a)
        0
> b
        "abcdef"

free(pointer)

Deallocate memory allocated by the alloc_copy function. The argument is the return value of that function. The returned value is the undefined value.


freestring(variable)

This function frees the memory allocated for a string in the variable received as argument. The returned value is the undefined value.


freetree(node_pointer)

Deallocate a syntax tree of which the root is received as parameter. The returned value is the undefined value.


freopen(path, mode, stream)

Reassign a file pointer. The first parameter is a string containing the path of the file to associate with stream. The second parameter is a string specifying the access mode as with fopen. The last parameter is a pointer to a FILE structure. freopen returns a pointer to the newly opened file. If an error occurs, the original file is closed and the function returns a null pointer value. The freopen function closes the file currently associated with stream and reassigns stream to the file specified by path.

Text in most part from Microsoft Visual C++ 6.0 Docs.

> a = freopen("err.txt", "w", stderr)
        0x462b30
> if (a) print(1)
        1
> fprintf(stderr, "test\n")
> a == stderr
        1
> fclose(a)
        0

fscanf(stream, format[, argument]...)

The fscanf function reads data from the current position of stream into the locations given by argument (if any). Each argument must be a variable already defined of a type that corresponds to a type specifier in format. format controls the interpretation of the input fields and has the same form and function as the format argument for scanf. If copying takes place between strings that overlap, the behavior is undefined. For more information, see Format Specification Fields. The returned value is the indefined value.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fseek(stream, offset, origin)

Moves the file pointer to a specified location. The first parameter is a pointer to a FILE structure. The second parameter is the number of bytes from origin. The last parameter is the initial position. If successful, fseek returns 0. Otherwise, it returns a nonzero value. On devices incapable of seeking, the return value is undefined.

The fseek function moves the file pointer (if any) associated with stream to a new location that is offset bytes from origin. The next operation on the stream takes place at the new location. On a stream open for update, the next operation can be either a read or a write. The argument origin must be one of the following values:

origin value Meaning
0 Beginning of file
1 Current position of file pointer
2 End of file

You can use fseek to reposition the pointer anywhere in a file. The pointer can also be positioned beyond the end of the file. fseek clears the end-of-file indicator and negates the effect of any prior ungetc calls against stream.

When a file is opened for appending data, the current file position is determined by the last I/O operation, not by where the next write would occur. If no I/O operation has yet occurred on a file opened for appending, the file position is the start of the file.

For streams opened in text mode, fseek has limited use, because carriage return-linefeed translations can cause fseek to produce unexpected results. The only fseek operations guaranteed to work on streams opened in text mode are:

  • Seeking with an offset of 0 relative to any of the origin values.
  • Seeking from the beginning of the file with an offset returned value from a call to ftell.

Also in text mode, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading/writing, fopen and all related routines check for a CTRL+Z at the end of the file and remove it if possible. This is done because using fseek and ftell to move within a file that ends with a CTRL+Z may cause fseek to behave improperly near the end of the file.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fsetpos(stream, variable)

Sets the stream-position indicator. The first parameter is a pointer to a FILE structure. The second parameter is a variable of type pointer to fpos_t structure. If successful, fsetpos returns 0. On failure, the function returns a nonzero value.

The fsetpos function sets the file-position indicator for stream to the value of variable, which is obtained in a prior call to fgetpos against stream. The function clears the end-of-file indicator and undoes any effects of ungetc on stream. After calling fsetpos, the next operation on stream may be either input or output.

Text in most part from Microsoft Visual C++ 6.0 Docs.


ftell(stream)

Gets the current position of a file pointer. The parameter is a pointer to a FILE structure. The returned value by ftell may not reflect the physical byte offset for streams opened in text mode, because text mode causes carriage return-linefeed translation. Use ftell with fseek to return to file locations correctly. On error, ftell returns -1. On devices incapable of seeking (such as terminals and printers), or when stream does not refer to an open file, the return value is undefined.

The ftell function gets the current position of the file pointer (if any) associated with stream. The position is expressed as an offset relative to the beginning of the stream.

Note that when a file is opened for appending data, the current file position is determined by the last I/O operation, not by where the next write would occur. For example, if a file is opened for an append and the last operation was a read, the file position is the point where the next read operation would start, not where the next write would start. (When a file is opened for appending, the file position is moved to end of file before any write operation.) If no I/O operation has yet occurred on a file opened for appending, the file position is the beginning of the file.

Also in text mode, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading/writing, fopen and all related routines check for a CTRL+Z at the end of the file and remove it if possible. This is done because using fseek and ftell to move within a file that ends with a CTRL+Z may cause fseek to behave improperly near the end of the file.

Text in most part from Microsoft Visual C++ 6.0 Docs.


fwrite(string, size, count, stream)

Writes data to a stream. The first parameter is a string containing the data to be written. The second parameter is the item size in bytes. The third parameter is the maximum number of items to be written. The last parameter is a pointer to a FILE structure. fwrite returns the number of full items actually written, which may be less than count if an error occurs. Also, if an error occurs, the file-position indicator cannot be determined.

The fwrite function writes up to count items, of size length each, from string to the output stream. The file pointer associated with stream (if there is one) is incremented by the number of bytes actually written. If stream is opened in text mode and if the operating system is Windows, each carriage return is replaced with a carriage-return - linefeed pair. The replacement has no effect on the return value.

Text in most part from Microsoft Visual C++ 6.0 Docs.


getfuncpt(handle, string)

Gets a pointer to a function in a .dll file on Windows, in a .so file on Linux or in a .dylib file on Mac OS. The first parameter is the handle obtained with the openlib function. The second parameter in a string holding the name of the function. The returned value is a pointer to a function. The variable holding this pointer is used the same way as a variable holding a pointer to a PCASTL function definition node.


gettype(expr)

This function takes one argument, evaluates it and returns a string containing its type.


getwd()

This function returns a string containing the path of the current working directory.


info(node_pointer)

This function returns in an object information about the node pointer it receives as parameter. The two members always in the returned object are named node_type and nb_children.

value of node_type member optional member name
"numerical constant" value
"mathematical operator" operator
"relational or logical operator" operator
"variable" name
"string" value
"function definition" parameters
"function call" nb_args
"if statement"  
"if else statement"  
"for statement"  
"while statement"  
"list"  
"code segment"  
"parent reserved word"  
"childset reserved word"  
"vargenlist"  
"incrementation or decrementation" operator
"object member access list"  
"subscript"  
"stdin FILE* identifier"  
"stdout FILE* identifier"  
"stderr FILE* identifier"  
"cast" cast_type
"structure reference operator (.)"  
"structure dereference operator (->)"  

insert(symbol, content, position)

This function inserts the "content" in "symbol" at position "position". Symbol and content have to be of the same type. The type can be array, chained list, string or pointer pointing to a statement list. The returned value is the undefined value.

> a = "ad"
        "ad"
> insert(a, "bc", 1)
> a
        "abcd"

insertnode(parent_node, child_node, position)

This function inserts as child the node which a pointer to is received as second argument to the node which a pointer to is received as first argument at position "position". The returned value is the undefined value.


length(sequence)

This function returns the number of elements of the sequence it receives as parameter. The sequence can be an array, a chained list, a string, a pointer to a statements list or raw memory. If the sequence is a string, the length is the amount of allocated memory, not the number of characters before the NULL ending.


list([arg1[, arg2[, ...]]])

This function takes as many arguments as you want, evaluates them and return a chained list of the according length.


memclone(raw_memory)

This function returns a clone newly allocated of the first argument which must be raw memory. Other functions returning raw memory are vartomem, memclone and memory. The returned value is of raw memory type.


memcpy(addresse, address2, length)

This function copies "length" bytes from address2 to address1. The first two arguments can be a variable of raw memory type, string type, memory address type or a pointer to any other type. The return value is address1 in a variable of memory address type.


memory(length)

This function returns raw memory initialized to zero of length specified in the argument.


memset(address, value, length)

This function assigns the "value" value converted to an unsigned char to the "length" bytes present at the address given as first argument. The first argument can be a variable of raw memory type, string type, memory address type or a pointer to any other type. The return value is "address" in a variable of memory address type.


memtovar(var, memory)

This function do the inverse operation of vartomem function. The first argument must be a variable of one of fundamental C types, an array, an object or any combination of these types. The second argument must be a variable of raw memory type with length big enough to contain all members of the first argument. This argument can be the value returned by the vartomem, memclone or memory function. The returned value is the undefined value. For an example of use, see function getfuncpt.


mknode(list, source, index)

This function adds a node to list node that it receives the pointer as first parameter. The second parameter, "source", is the code to insert in the list. This parameter can be a code segment or a node pointer. The subtree inserted is copied entirely. The last parameter is the position index where to insert the code in the list. First place is 0 and last place is the list size. The returned value is the undefined value.

> a = function(x) {}
        0x3308b8
> a(2)
> mknode(a.childset[1], `x*2', 0)
> a(2)
        4
>
> a = function()
+ {
+    mknode(parent.parent.parent, `print(3)', 3)
+    print(1)
+    print(2)
+ }
        0x3334b0
> a()
        1
        2
        3
> a()
        1
        2
        3
        3

names(string1[, string2[, ...]])

This function takes at least one string argument. The returned value is an object with members named according to the strings given. If a member of an object is a function, the context of this function when called will already contain the member variables of the object.

> a = names("b", "c")
[b]     undefined
[c]     undefined
> a.b = 0
        0
> a.c = function() { b = 1 }
        0x333028
> a.c()
        1
> a
[b]     1
[c]     0x333028

ntoa(expr)

This function evaluates its argument, converts it to a string if it is numerical and returns it.


openlib(string)

Opens a .dll file on Windows, a .so file on Linux or a .dylib file on Mac OS. The name of this file is in the string received as argument. On Linux and Mac OS, if the file is in the working directory, you must begin its name by "./". The returned value is a handle to the library which will have to be used with the function getfuncpt.


osfamily()

If this function is called in the interpreter built for Windows 32-bit, the returned value will be the string "win32". For Windows 64-bit: "win64", for Linux 32-bit: "lin32", for Linux 64-bit: "lin64" and for Mac OS: "mac64".


popback(list_or_array_address)

This function removes the last element of the chained list or array whose address is received as argument and returns this element. If the container is empty, the returned value is the undefined value.


popfront(list_or_array_address)

This function removes the first element of the chained list or array whose address is received as argument and returns this element. If the container is empty, the returned value is the undefined value.


print(expr)

This function evaluates and prints its argument. The returned value is the undefined value.


printf(string[, argument]...)

Displays a formatted output in the standard output stream, stdout. The string argument consists of ordinary characters, escape sequences, and (if arguments follow the string) format specifications. The ordinary characters and escape sequences are copied to stdout in order of their appearance.

Format specifications always begin with a percent sign (%) and are read left to right. When printf encounters the first format specification (if any), it converts the value of the first argument after the string and outputs it accordingly. The second format specification causes the second argument to be converted and output, and so on. If there are more arguments than there are format specifications, the extra arguments are ignored. The results are undefined if there are not enough arguments for all the format specifications. The returned value is the undefined value.

Text in most part from Microsoft Visual C++ 6.0 Docs.

> printf("%s %f %c\n", "abc", 2.3, (char)61)
abc 2.300000 =

prompt(string)

This function lets you change the prompt to any string you want. The returned value is the undefined value.

> prompt("input: ")
input: print("hello")
        "hello"
input: prompt("")
a = 1
        1
a + 2
        3
prompt("> ")
> 

pushback(list_or_array_address, element)

This function evaluates its second argument and appends the result at the end of the chained list or array whose address is received as first argument. The returned value is the undefined value.


pushfront(list_or_array_address, element)

This function evaluates its second argument and inserts the result at the beginning of the chained list or array whose address is received as first argument. The returned value is the undefined value.


read(filename)

This function reads a text file with name given in a string as parameter. The return value is a pointer to a list node that has a string node for each word or punctuation mark read. The recognized punctuation marks are ,.!?


remove(symbol, start[, end])

Removes items from a sequence. The first parameter is a variable holding a string, an array, a list or a pointer to a statements list. The second parameter is a number telling at which index begin to delete. If there is no third argument, only one item is removed. If there is a third argument, items are deleted from indexes start to end inclusively. The returned value is the undefined value.


repeat(expr, n)

Evaluates its first argument and repeat the result in an array of length n. See function getfuncpt for an example of use.


replace(symbol, sequence, position)

This function replace the items in "symbol" from "position" by "sequence". The symbol can contain an array, a chained list, a string or a pointer pointing to statement list. The sequence has to be of the same type. The returned value is the undefined value.


replacenode(parent_node, replacing_node, position)

This function replaces the child node at position "position" of the node from which a pointer to is received as first argument by the node from which a pointer is received as second argument. The returned value is the undefined value.


return([value])

This function stops the execution of the called function one level up. If you give a parameter, it will be the returned value. If you don't give a parameter, the returned value is the undefined value.


rewind(stream)

Repositions the file pointer to the beginning of a file. The parameter is a pointer to a FILE structure. The returned value is the indefined value. The rewind function repositions the file pointer associated with stream to the beginning of the file. A call to rewind is similar to:

fseek(stream, 0, 0)

However, unlike fseek, rewind clears the error indicators for the stream as well as the end-of-file indicator. Also, unlike fseek, rewind does not indicate whether the pointer was successfully moved in its return value.

To clear the keyboard buffer, use rewind with the stream stdin, which is associated with the keyboard by default.

Text in most part from Microsoft Visual C++ 6.0 Docs.


rmnode(node_pointer, index)

This function removes a node from the child nodes of a node that it receives a pointer as first parameter. The second parameter is the position where to delete the node. First place is 0 and last place is the number of direct children - 1. The returned value is the undefined value.


scan()

This function scans input from the keyboard until a character not in the set {A-Za-z0-9,.!? } is encountered. The return value is a pointer to a list node that has a string node for each word or punctuation mark scanned.

> a = scan()
Hello World!!
        0x330908
> length(a)
        4
> value(a.childset[0])
        "Hello"
> value(a.childset[3])
        "!"

scanf(format[, argument]...)

The scanf function reads data from the standard input stream stdin and writes the data into the location given by argument. Each argument must be a variable already defined of a type that corresponds to a type specifier in format. If copying takes place between strings that overlap, the behavior is undefined. For more information, see Format Specification Fields. The returned value is the undefined value.

Text in most part from Microsoft Visual C++ 6.0 Docs.

> a = (int)0
        0
> b = 0
        0
> c = "      "
        "      "
> scanf("%i %lf %s", &a, &b, c)
100 2.4 hello
> a
        100
> b
        2.4
> c
        "hello"

setlength(symbol, length)

This function has two parameter. The first is a symbol which can contain an array, a chained list, a string, a pointer pointing to a statement list or raw memory. The second parameter is the new length of the symbol content. When the symbol contains a string, the new length include the space for the NULL terminating character.


setwd(path)

This function sets the current working directory to the path it receives in a string as parameter. The returned value is the undefined value.

> setwd("d:\\temp")
> getwd()
        "d:\temp"
> setwd("d:/temp/install")
> getwd()
        "d:\temp\install"
> setwd("..")
> getwd()
        "d:\temp"

source(filename)

This function receives one string argument and execute the statements in the file specified by "filename". The returned value is the undefined value.


sprintf(variable, format[, argument]...)

Write formatted data to a string. The first parameter is an already defined variable of the string type that will receive the ouput. The second parameter is the string to be written, which can include format specifications for the other arguments, if any. Each argument (if any) is converted and output according to the corresponding format specification in format. A null character is appended after the last character written. If copying occurs between strings that overlap, the behavior is undefined. The returned value is the undefined value.

Text in some part from Microsoft Visual C++ 6.0 Docs.

> a = "                 "
        "                 "
> sprintf(a, "%s %f %i", "word", 2.01, (int)40)
> a
        "word 2.010000 40"

sscanf(string, format[, argument]...)

Read formatted data from a string. The sscanf function reads data from string into the location given by each argument. Each argument must be a variable already defined of a type that corresponds to a type specifier in format. format controls the interpretation of the input fields and has the same form and function as the format argument for scanf. If copying takes place between strings that overlap, the behavior is undefined. For more information, see Format Specification Fields. The returned value is the indefined value.

Text in some part from Microsoft Visual C++ 6.0 Docs.


strclone(string)

Duplicates the string received as argument. The returned value is the new string.


strcpy(string1, string2)

Calls strcpy from string.h. Does copy characters from string2 to string1 including the terminating null character. The allocated string1 length must be greater or equal to string2 length + 1. The behavior is undefined is string1 and string2 overlap. The returned value is string1.


strlen(string)

This function receives one string argument and returns the number of characters before the NULL ending.


subseq(entity, start, end)

This function returns a sub sequence of the entity it receives as first parameter. The entity can be an array, a chained list, a string or a statements list. The second parameter is the index where the sub items of "entity" are beginning to be copied. The last parameter is the index of the last copied sub item of "entity".

> a = `{
+    print(1)
+    print(2)
+    print(3)
+    print(4)
+ }'.childset[0]
        0x330960
>
> b = subseq(a, 0, 1)
        0x332fa0
> c = function() {}
        0x3332d0
> c.childset[1] = b
        0x3332a8
> c()
        1
        2

swapnodes(parent_node1, position1, parent_node2, position2)

This function swap the child node at position position1 of parent_node1 with the child node at position position2 of parent_node2. Subtrees below the children nodes follow their parents.

> t1 = `(1 + 2) / (3 + 4)'.childset[0]
        0xbed50
> t2 = `(5 + 6) / (7 + 8)'.childset[0]
        0xbf310
> swapnodes(t1, 0, t2, 1)
> treetocode(t1)
        "(7 + 8) / (3 + 4)"
> treetocode(t2)
        "(5 + 6) / (1 + 2)"

tmpfile()

Creates a temporary file. Takes no parameter. The tmpfile function creates a temporary file and returns a pointer to that stream. If the file cannot be opened, tmpfile returns a null pointer. This temporary file is automatically deleted when the file is closed, when the program terminates normally. The temporary file is opened in w+b (binary read/write) mode.

Text in most part from Microsoft Visual C++ 6.0 Docs.


tonode(expr)

This function evaluates its argument and if the result is a numeric value or a string, then the return value is a pointer to a new node containing the number or the string.


treetocode(node_pointer[, string])

This function returns a string containing the code (program) corresponding to the syntax tree from which a pointer to the root is received as first argument. If it is given, the second parameter is a string indicating the spaces to insert for indent. The default value is "   " (three spaces).

> fact = function(x)
+ {
+    if (x == 1) return(1)
+    return(x * fact(x - 1))
+ }
        0x11f2f0
> mknode(fact.childset[1], `if (x < 1) {
+    print("Parameter must be greater than zero.")
+    abort()
+ }', 0)
> printf(concat(treetocode(fact, "   "), "\n"))
function(x)
{
   if (x < 1)
   {
      print("Parameter must be greater than zero.")
      abort()
   }
   if (x == 1) return(1)
   return(x * fact(x - 1))
}

undefine(symbol)

This function sets the type of the symbol it receives as argument to "undefined". The returned value is the undefined value.


ungetc(string, stream)

Pushes a character back onto the stream. The first parameter is a string containing the character to push and a null terminating character. The second parameter is a pointer to a FILE structure.

The ungetc function pushes the first character of string back onto stream and clears the end-of-file indicator. The stream must be open for reading. A subsequent read operation on stream starts with string[0]. An attempt to push "\xff" (EOF) onto the stream using ungetc is ignored.

Characters placed on the stream by ungetc may be erased if fflush, fseek, fsetpos, or rewind is called before the character is read from the stream. The file-position indicator will have the value it had before the characters were pushed back. The external storage corresponding to the stream is unchanged. On a successful ungetc call against a text stream, the file-position indicator is unspecified until all the pushed-back characters are read or discarded. On each successful ungetc call against a binary stream, the file-position indicator is decremented; if its value was 0 before a call, the value is undefined after the call.

Results are unpredictable if ungetc is called twice without a read or file-positioning operation between the two calls. After a call to fscanf, a call to ungetc may fail unless another read operation (such as fgetc) has been performed. This is because fscanf itself calls ungetc.

Text in most part from Microsoft Visual C++ 6.0 Docs.


value(node_pointer)

This function returns the numeric value or the string value of a node pointer it receives as argument. The node must contain a number or a string.


vartoa(node_pointer)

This function receive as parameter a pointer to a node of "variable" type. The returned value is a string containing the name of the variable.

> a = `i + 1'.childset[0]
        0x3c7b30
> vartoa(a.childset[0])
        "i"

vartomem(expr)

This function can receive as argument an expression of one of C fundamental types, an array, an object or any combination of these types. By combination, we mean by example an object containing arrays, an array of objects, an object containing another, etc. The received objects are converted to C structures with adequate member variables alignment. A received array must have all elements of the same type and is converted to a C array. The returned value is a variable of raw memory type which can be passed as argument to a function of a dynamic-link library or a shared object library. For an example of use, see function getfuncpt.


write(filename, list, separator)

The first parameter is a string containing the file name where to write the text. The second parameter is a pointer to a list node where each subnode contains a string. The last parameter is a string containing the text to insert between each strings of the list in the output file. The returned value is the undefined value.

write("write.txt", `{"Hello" "World" "!" "!"}'.childset[0], " ")

back to PCASTL

Mobile
linkedin
bandcamp
steam