Chapter 2 Lexical Structure

Table of Contents
Overview
Whitespace and Line Breaks
Comments
Literals
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
      

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)