DOC PREVIEW
Columbia COMS W4115 - CHAD Language Reference Manual

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CHAD Language Reference ManualINTRODUCTIONThe CHAD programming language is a limited purpose programming language designed to allow teachers and students to quickly code algorithms involving arrays, queues and stacks and see graphically how their data is being manipulated. CHAD is an interpreted language in which the interpreter outputs a graphical representation of the data structures used in the program as well as performing any calculations. The goal of CHAD is to make visualization of algorithms easier by providing a way to easily and compactly create graphical representations of them.STRUCTURE OF THE PROGRAMA CHAD language program consists of a series of variable declarations followed by a series of statements to be executed followed by a series of optional user-defined functions. User-defined functions consist of the function keyword followed by the return type of the function (array, int, queue, stack, string or void for no return value) followed by the name of the function. Next comes a list of optional comma separated arguments of the form type name, enclosed in parentheses (which are not optional) and a list of variable declarations followed by a list of statements, and are ended with the endfunction keyword. The last thing before an endfunction keyword must be a return statement, which can only appear there. Note all declarations must be made before any statements in the block that contains them.VARIABLES AND DECLARATIONThe CHAD language has 5 native data-types. They are integers, strings, arrays, queues and stacks. All variables must be declared before they are used and all declarations are to be located at the beginning of a program or function definition. All variables are local in scope. Variable defined within a function can be used only within that function and variable defined in the main body of the program (outside of any function declaration) cannot be used by any functions in the program. Any parameters needed by a function must be explicitly passed to that function and any variables modified by a function must be returned in order to be accessed from elsewhere in the program. The only exception to this is some built in functions which can be called on a variable using a variable.function() syntax which gets the variable as a reference and is able to modify the variable it is given as well as return another value. This will be discussed further when we discuss function calls. When variables are declared they can be declared with or without initializing them. A variable cannot actually be used before it is initialized, however. The syntax for initialization of a variable is exactly the same as the assignment syntax. Variable and function names are identifiers (see later definition of an identifier). IntegersThe integer data type in CHAD supports integers values from –999 to 999 thedeclaration of an integer variable consists of the keyword int followed by the name of the variable. A value may be assigned using standard assignment rules (as described below), and the declaration must terminate in a semicolon.StringsThe string data type in CHAD supports alphanumeric strings up to 30 characters in length. For a list of characters to be interpreted as a string literal by CHAD it must be enclosed in double quotes and can include any characters that are not double quotes or newline characters. The declaration of a string variable consists of the keyword string followed by the name of the variable. Again, it may be assigned immediately, and the declaration must terminate in a semicolon.ArraysThe array data type in CHAD supports arrays of either string or integer types with a fixed length chosen at declaration. The declaration of an array consists of a statement such as array[int, 10] where the first argument is the type of the values to be stored in the array and the second argument is the length of the array. The index of the array begins at 0 and goes to n-1 where n is the length of the array. The length of an array is fixed as soon as it is created. Trying to access an element of the array that does not exist causes an error by the compiler.QueuesThe queue data type supports queues of either string or integer types. Queues are dynamically assigned memory by the interpreter and therefore have no fixed length. However the programmer should use caution to avoid overflowing available memory.The declaration of a queue consists of the queue keyword followed by the type of the queue in square brackets followed by the name of the queue and then a semicolon. e.g. queue[int] myQueue;StacksThe stack data type supports support stacks of either string or integer types. Stacks are dynamically assigned memory as queues are and therefore have no fixed size. The declaration of a stack consists of the stack keyword followed by the type of the stack in square brackets and the name of the stack. e.g. stack[int] myStack;BUILT IN OPERATORSNote that a single variable or a literal value are each considered an expression of the same type as the variable or the literal.ASSIGNMENT (=)The assignment operator,. = is used to give a particular value to a variable after that variable has been declared. The syntax is variable = value where value can be anyexpression that evaluates to the same type as the variable it is being assigned to, or any single literal value of the appropriate type. There are no conversion operators in CHAD, assignments must be of the same type of variable or value.Integers and StringsThese use only basic assignments as shown above. The value of an integer must be a decimal number between -999 and 999. The value of a string may be any sequence of characters except for double quotes and newlines, enclosed in double quotes.Arrays.There are two types of assignments to arrays. The first treats each cell in the array individually. The syntax to extract a single cell from an array is the name of the array followed by the index of the desired value in square brackets e.g. myArray[5] accesses the 6th element of myArray. This syntax is treated as an integer or string depending on the type of the array. If an attempt is made to access an index which is beyond the length of the array an error will be raised. The second method of assignment to an array handles multiple values at the same time. This syntax is variable = {vals} where vals is a comma separated list of n values to be put into the first n cells of the array. All members of vals


View Full Document

Columbia COMS W4115 - CHAD Language Reference Manual

Documents in this Course
YOLT

YOLT

13 pages

Lattakia

Lattakia

15 pages

EasyQL

EasyQL

14 pages

Photogram

Photogram

163 pages

Espresso

Espresso

27 pages

NumLang

NumLang

6 pages

EMPATH

EMPATH

14 pages

La Mesa

La Mesa

9 pages

JTemplate

JTemplate

238 pages

MATVEC

MATVEC

4 pages

TONEDEF

TONEDEF

14 pages

SASSi

SASSi

16 pages

JTemplate

JTemplate

39 pages

BATS

BATS

10 pages

Synapse

Synapse

11 pages

c.def

c.def

116 pages

TweaXML

TweaXML

108 pages

Load more
Download CHAD Language Reference Manual
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CHAD Language Reference Manual and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CHAD Language Reference Manual 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?