Skip to main content

Lexicon & Literals

This page covers the fundamental tokens and literal types in TypR.

Semicolons

Every top-level instruction ends with ;. The parser tolerates missing semicolons (emitting a SyntaxError::ForgottenSemicolon warning), except for the last expression in a block, which acts as an implicit return value — just like in R.

let x <- 42;        # explicit semicolon
let y <- 42 # tolerated, warning emitted

Literals

LiteralSyntaxNote
Integer42, -7Lang::Integer
Number3.14, -0.5a decimal point is required for Number; otherwise it's an Integer
String"text" or 'text'single and double quotes are interchangeable; escapes: \" \' \\ \n \t
Booleantrue / TRUE, false / FALSEboth lowercase and uppercase forms accepted
Nullnull / NULLLang::Null — distinct from NA
Missingna / NALang::NA — distinct from null

Literal types

Literals can also appear as types (singleton types): 3, 3.14, true, "chat" are valid types, more precise than int/num/bool/char.


Identifiers

KindConventionExampleEnforcement
Variablesnake_casemy_varmust start with a-z or _
TypePascalCaseMyTyperequired for type/opaque/alias declarations
Quotedbackticks`+`, `weird name`useful for naming custom operators

The parser explicitly rejects casing mistakes:

  • let PascalCase <- ... triggers LetInsteadOfType
  • type snake_case <- ... triggers TypeInsteadOfLet

Comments

# This is a comment

Only # is recognized. There is no // syntax — a .ty file containing // will fail silently (see Known Pitfalls).