Chapter 2 Lexical Structure

Table of Contents
Overview
Whitespace and Line Breaks
Comments
Literals
Operators and Special Symbols
Identifiers

Overview

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 and Line Breaks

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.

Comments

Scaly supports two forms of comments:


; This is a single-line comment

;* This is a
   multi-line comment *;
    

Literals

Integer Literals

Integer literals represent whole numbers. They can be written in decimal or hexadecimal notation.


42        ; decimal
0x2A      ; hexadecimal (same value)
      

Floating-Point Literals

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

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

Character literals represent single Unicode code points, enclosed in backticks.


`a`           ; lowercase a
`\n`          ; newline character
`\u{1F600}`   ; emoji (grinning face)
      

Boolean Literals

Boolean literals are true and false.


true
false
      

Operators and Special Symbols

The Equals Sign

Unlike many programming languages, Scaly reserves the equals sign (=) exclusively for equality comparison. It is not used for variable declarations or assignments.


; Equality comparison
if x = 42 { ... }         ; tests if x equals 42

; Variable declaration (NO equals sign)
let x 42                  ; declares x with value 42
let y: i32 100            ; with type annotation

; Assignment (uses colon)
set x: 43                 ; assigns 43 to x
      

This design eliminates the classic confusion between assignment and comparison that leads to bugs in C-style languages (if (x = 42) vs if (x == 42)).

Note: Because = is just an operator like any other, the standard library could define a unary = operator that returns its argument unchanged. This would allow the syntax let x = 42 to parse as let x (= 42), for those who prefer traditional declaration style.

Identifiers

Identifiers name variables, functions, types, and other entities. Scaly supports three forms of identifiers:


myVariable        ; alphanumeric
calculate_total   ; with underscore
++                ; operator identifier
'my identifier'   ; string identifier (with spaces)