Program structure
An OCat file is read top-to-bottom. Every statement must start with a recognized keyword:import, print, a type keyword (number, string, bool), set, func, const, or call. Anything else is a parse error.
Whitespace
Whitespace (spaces, tabs, newlines) is ignored by the parser. You may indent your code freely for readability. There are no significant-indentation rules.Comments
OCat supports both line comments and block comments. Both are skipped by the lexer and have no effect on execution.Line comments
Line comments
A line comment starts with
// and continues to the end of the line.Block comments
Block comments
A block comment is delimited by
/* and */ and may span multiple lines.Keywords
The following words are reserved by the language and cannot be used as identifiers:| Keyword | Purpose |
|---|---|
print | Output a value to the console |
import | Load another OCat file |
number | Declare a numeric variable |
string | Declare a string variable |
bool | Declare a boolean variable |
set | Mutate an existing variable |
const | Mark a variable as immutable |
func | Define a function |
call | Invoke a function |
Identifiers
An identifier is any name that is not a reserved keyword. Identifiers are used for variable names and function names. Pattern:/[a-zA-Z_]\w*/
An identifier must:
- Start with a letter (
a–z,A–Z) or an underscore (_) - Contain only letters, digits (
0–9), or underscores after the first character
Identifiers are case-sensitive:
count, Count, and COUNT are three different names.Operators
OCat currently defines one operator:| Operator | Meaning |
|---|---|
= | Assignment |
Delimiters
The following characters are used as structural delimiters:| Delimiter | Usage |
|---|---|
( ) | Argument lists for print, func, and call |
{ } | Function body |
, | Separator between parameters |
Complete example
The following program demonstrates all major syntactic features together:Variables
Learn how to declare and mutate variables.
Functions
Learn how to define and call functions.