Cind programming language

Language definition Examples Download Contact

Cind console application

A console application is a program executed inside system terminal, having only binary stream interface.
This kind of application is widely used as a basic program, which interacting via text, usually by writing characters on the console display and reading input characters from the keyboard.

To create console application in the Cind language, compile it with cindcompiler and execute with cindexec launcher inside system terminal (see Compilation and execution).

Basic console application

The Hello World application in the Cind language:

execute() { host.println("Hello World!"); }

For more about language writing style see Code writing style.
For making a program see Compilation and execution.

Section execute()

Every console application needs to have one execute section, which is an application starting point. Parameters passed to the executed program will be received in header of execute section.
For example, while executing program:

$ cindexec myprog.soft -p x1 x2 x3

text entered after the -p parameter will be received as a string objects in parameters of execute section:

execute(p1,p2,p3) { // here p1 = "x1", p2 = "x2", p3 = "x3" // ... }

For definition of parameters declaration in the Cind language see Parameters of function.

Main classes

The main classes of application should be added in the code, above the execute section declaration, for example:

class c { ... } ... execute() { ... var x = new c(); ... }

Notice, that any other classes can still be declared in any other place in the code.
For more about classes see Classes.

Host object

Object host, in console application, responds to following messages:

method parameters description result
print (...) prints list of parameters to standard output, in given order,
converting them to strings, and then writes in UTF-8 charset
println (...) prints out parameters, as in above method,
and also end-of-line character at the end
openFile (filename) opens existing file for reading file object
createFile (filename) creates new file with given name, and opens it for writing
(see below)
file object
exit (exitCode) exits console application with given exit value
(see below)
outputStream () returns standard output stream of console application
as file object in write-only mode
file object
errorStream () returns standard error stream of console application
as file object in write-only mode
file object
inputStream () returns standard input stream of console application
as file object in read-only mode
file object

Caller object

In console application the caller object has no methods.

Accessing files

A file object represents data stream or file from the operating system, from which it is possible to read or write data. The file can be opened for read-only or for write-only mode, and therefore, file object allows to access only read or write methods. A file object can be received, for example, from host's methods createFile and openFile.

Methods of the file object opened in write-only mode:

method parameters description result
write (sheet s,
int offset,
int count)
writes data to the stream, starting at given offset position,
it will write count bytes or less, depending on the condition
or capabilities of the file, and on the other circumstances
int - number of written bytes
writeByte (byte b) writes single byte to the stream bool - true when ok, false means failed
close () closes file (and releases any holded resources)
print (...) prints list of parameters in given order,
converting them to strings, and then writes in UTF-8 charset
println (...) prints out parameters, as in above method,
and also end-of-line character at the end

Methods of the file object opened in read-only mode:

method parameters description result
read (int count) reads data from the stream, it will try to read
count bytes or less, depending on the condition
or capabilities of the file, and on the other circumstances
sheet - sheet with readed data
readByte () reads single byte from the stream byte - when ok, null means failed
close () closes file (and releases any holded resources)

A sheet type, used in above data transfer methods, is a type of an object, that represents a part of memory, and in this case, a set of readed or written bytes.
For more about sheet data type see Sheet object.



Cind programming language 1.0.4