This chapter describes the lexical structure of Scaly: how source text is divided into tokens. The lexer transforms a sequence of characters into a sequence of tokens that the parser then processes.
Whitespace characters (space, tab) separate tokens but are otherwise insignificant. Line breaks, however, are syntactically meaningful in Scaly — they can terminate statements and declarations.
A colon (:) can be used in place of a line break when multiple statements should appear on a single line.
Scaly supports two forms of comments:
Single-line comments start with a semicolon (;) and extend to the end of the line.
Multi-line comments start with ;* and end with *;.
; This is a single-line comment
;* This is a
multi-line comment *;
Integer literals represent whole numbers. They can be written in decimal or hexadecimal notation.
42 ; decimal
0x2A ; hexadecimal (same value)
Floating-point literals represent decimal numbers with a fractional part or an exponent.
3.14159 ; pi
2.5e10 ; scientific notation
1.0e-5 ; small number
String literals are enclosed in double quotes. They support standard escape sequences.
"Hello, World!"
"Line 1\nLine 2" ; with newline escape
"Tab:\tValue" ; with tab
"Quote: \"nested\"" ; escaped quotes
Strings can span multiple lines without any special syntax — newlines are simply included as part of the string content:
"This is a string
that spans multiple
lines."
Character literals represent single Unicode code points, enclosed in backticks.
`a` ; lowercase a
`\n` ; newline character
`\u{1F600}` ; emoji (grinning face)
Identifiers name variables, functions, types, and other entities. Scaly supports three forms of identifiers:
Alphanumeric identifiers start with a letter and continue with letters, digits, or underscores.
Operator identifiers consist of operator characters such as +, -, *, /.
String identifiers are enclosed in single quotes and can contain any characters.
myVariable ; alphanumeric
calculate_total ; with underscore
++ ; operator identifier
'my identifier' ; string identifier (with spaces)