Chaga Programming Language: Chapter 1

About the language

  • The Chaga programming language began as a derivative of the C programming language. I developed the Chaga programming language to serve as a teaching tool for my programming languages class at Sonoma State University in the Department of Computer Science.
  • I've forked the Chaga programming language into two languages: Chaga (detailed below) and ChagaLite. ChagaLite is a subset of the Chaga programming language. ChagaLite is an interpreted language while Chaga is a compiled language.

Language design philosophy

  • The Chaga programming language focus is computation for the engineering and science disciplines.
  • The Chaga programming language has some object-oriented influences via the attributes feature. For simplicity, the language is otherwise non-object oriented.

Notable features of the Chaga programming Language

  • All string, list, and number-based datatypes are dynamically scalable at run-time.
  • All one, two, or three dimensional arrays (regardless of datatype) are dynamically resizeable at run-time.
  • Chaga supports integer, real, complex, and imaginary datatypes.
  • Chaga utilizes an internal string-based mathematics library to support computation of arbitrarily large or small numbers.

Language specification in Backus-Naur Form (BNF)

Embedding comments

The Chaga programming language supports single-line and multi-line comments within a Chaga program. Note: If //, /*, or */ appear within a quoted string, the Chaga compiler will not regard it as a comment.

  • Single line comments are denoted by double-slashes: //
  • Multi-line comments begin with slash-asterisk: /* and are terminated with an asterisk-slash: */

Example: Single-line and multi-line comments within a Chaga program.

// This is a single-line comment.

/*
This
is
a
multi-line
comment
*/

Variables

  • Chaga supports global and local variables.
  • Variables are case-sensitive meaning My_string is different from MY_STRING or my_string.
  • Variables must begin with a letter or an underscore. Following the first character, a variable may contain letters, digits, or underscores.
  • Variables contain metadata attributes which can be referenced anywhere the variable has scope.
  • TENTATIVE: a global variable indicating memory allocation on the heap is labeled ".heap". This variable is a single-element array. Example usage .heap[0] = pointer to first allocated memory, .heap[1] = pointer to second allocated memory, etc. When memory is released, the heap is a READ-ONLY variable. When memory is allocated from the heap, the user defines the metadata attributes for the heap memory allocated. Those attributes indicate attributes such as "expiration_scope_threshold" which means the memory is automatically purged when current scope (defined in the program counter is lower than the value stored in metadata attribute ".expiration_scope_threshold".

Scope

  • Variables defined outside the boundaries of a procedure definition or a function definition are global. Global variables may not be redefined locally within a function or procedure definition
  • Variables defined within the statement block (denoted by curly-brace) for a function or procedure are local variables. Multiple functions or procedures may use identical identifiers for local variables declarations. The identically-named variables will not clash since each variable is within a different scope.

Datatypes (built-in)

The following datatypes are built-in to the Chaga programming language. However, one can also define user-defined datatypes using the define statement.

  • attribute: This datatype stores attribute data for other variables. It is useful when one wants to store and retrieve the metadata for other variables.
  • bool: This datatype stores a TRUE or FALSE Boolean value. The bool datatype can be utilized in an array.
  • char: This datatype stores one unsigned byte.
  • complex: This datatype stores arbitrarily large or small complex numbers which contain both a real component and an imaginary (square-root of negative one) component.
  • date: This datatype stores dates in the format YYYY-MM-DD format where YYYY = four digits representing year, MM = two digits representing the month, and DD = two digits representing the day.
  • datetime: This datatype stores both date and time in the format YYYY-MM-DD HH:MM:SS.
  • enum: This is an enumerated datatype. The user specifies the set of values the enumerated datatype may contain.
  • file: This datatype represents a file handle.
  • imaginary: This datatype stores arbitrarily large or small imaginary numbers.
  • int: This datatype stores arbitrarily large or small integer values.
  • pointer: This datatype designates a variable as a pointer to a memory location. A pointer datatype can examine the memory (contents) of any other datatype on a byte-for-byte basis.
  • list: This datatype stores an arbitrary number of mixed datatypes as a list of items. Each element of the list can be accessed via an index starting from zero.
  • real: This datatype stores arbitrarily large or small real numbers.
  • string: This datatype stores arbitrarily large or small unsigned bytes as a character string.
  • time: This datatype stores time in the format HH:MM:SS format where HH = two digits representing the hour, MM = two digits representing the minute, and SS = two digits representing the second.
  • void: This datatype designates an empty datatype which holds nothing. No values may be stored in this datatype. It is primarily used as a placeholder when a datatype field is required.

Arrays

  • A variable declared as an array may have one, two, or three dimensions and must indicate the maximum size of each dimension. Example: pixel_value[255][255][255] is a three-dimensional array with each dimension holding 255 possible values. In this example, the dimensions are accessed from 0 to 254.

Metadata attributes

  • Datatypes in the Chaga programming language may contain metadata attributes, depending on the datatype. Some attributes are read-only while others are read/write.

ARRAY: metadata attributes

  • .size1: this read-write attribute sets the maximum size of the first dimension in a one, two, or three-dimensional array.
  • .size2: this read-write attribute sets the maximum size of the second dimension in a two or three-dimensional array.
  • .size3: this read-write attribute sets the maximum size of the third dimension in a three-dimensional array.

POINTER: metadata attributes

  • .content: this read-only attribute returns the content (value) in the memory location pointed to by the pointer.
  • .scope_memory_release_threshold: TENTATIVE: this read-only attribute denotes when a block of allocated memory will be released back to the heap. The threshold value is a non-negative integer. When the program counter enters a scope less than the threshold value, the memory is automatically marked for removal.

REAL: metadata attributes

  • .status_flag: this read-only attribute returns the STATUS FLAG(s) bits set during a mathematical operation.
  • .scale: this read/write attribute describes the number of digits right of the decimal to be retained during a real division. This is especially useful when the division remainder is REPEATING, NON-TERMINATING (e.g. 1/3).
  • STATUS_FLAG attribute values for the REAL datatype.
    • NONE: this read-only attribute indicates no status flag bits are set.
    • INTERNAL_ERROR: This read-only attribute is set when an internal error occurred durng a mathematical operation.
    • DIVIDE_BY_ZERO: This read-only attribute is set when the denominator is zero during a division operation occurs.
    • REPEATING_NONTERMINATING: This read-only attribute is set when the denonominator contains any factors other than 1, 2, or 5 which results in a repeating, non-terminating condition in which the number of digits RIGHT of the decimal is truncated to the number of digits defined by the metadata attribute scale.
    • IMAGINARY: This read-only attribute is set on integer and real datatypes when the result is imaginary (e.g. a real datatype variable is assigned the square root of negative one from a mathematical operation).

Example: using scale attribute with a REAL datatype to truncate decimal remainder on a repeating, non-terminating division operation.

define procedure main (void)
{
  declare real quotient_and_remainder;
  set quotient_and_remainder.scale = 5;
  quotient_and_remainder = 1/3; /* the quotient_and_remainder = 0.33333 */
}

STRING: metadata attributes

  • .length: this read-only attribute returns the length (in bytes) for a string datatype.

Example: determining string length

declare string input_string;

set input_string = "haystack needle haystack needle";
call print (input_string.length, "\n");

Output from example: determining string length

31


Copyright © 2025, 2026 Robert James Bruce.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is available at https://www.gnu.org/licenses/fdl-1.3.html