Lexical Conventions
Table of contents
Comments
Behl uses C-style comments:
// Single-line comment
/* Multi-line
comment */
/* Nested /* comments */ are not supported */
Identifiers
Identifiers must start with a letter or underscore, followed by letters, digits, or underscores:
let validName = 1;
let _private = 2;
let name123 = 3;
Naming Conventions
While not enforced, these conventions are recommended:
- Variables:
camelCaseorsnake_case - Constants:
UPPER_CASEorPascalCase - Functions:
camelCaseorsnake_case - Private/internal: prefix with
_
Keywords
Reserved keywords cannot be used as identifiers:
let const function return
if else elseif
while for in
true false nil
break continue
Context-Sensitive Keywords
Some identifiers have special meaning in specific contexts but can be used as variable names:
defer- Statement keyword, but can be a variable nameimport- Function name, can be shadowed
Whitespace
Whitespace (spaces, tabs, newlines) is generally ignored except to separate tokens:
// These are equivalent
let x=1;
let x = 1 ;
let x =
1;
However, meaningful newlines can improve readability:
// Preferred
for (let i = 0; i < 10; i++) {
print(i);
}
// Works but discouraged
for(let i=0;i<10;i++){print(i);}
Semicolons
Semicolons are optional in Behl. The language supports automatic semicolon insertion:
// With semicolons
let x = 10;
print(x);
// Without semicolons (also valid)
let x = 10
print(x)
Both styles work. Semicolons are helpful for clarity when putting multiple statements on one line:
let x = 10; let y = 20; print(x + y)