Bitvector Literal
Overview
In the Sail ISA Specification Language, a bitvector literal is a lexical literal form that directly denotes a bitvector value of a specific width. Bitvector literals are part of Sail's general lit category, which appears in expressions (<exp>, <atomic_exp>), patterns (<pat>, <atomic_pat>), and atomic type contexts (<atomic_typ>).
Grammar Position
The <lit> non-terminal in the Sail grammar is the single production point at which bitvector literals are introduced. From the Sail grammar, <lit> is defined as:
<lit> ::= true
| false
| ()
| NUMBER
| undefined
| bitzero
| bitone
| BINARY_LITERAL
| HEXADECIMAL_LITERAL
| STRING_LITERAL
Within this production, the members that denote bitvector values are:
BINARY_LITERAL— a binary-formatted bitvector literal.HEXADECIMAL_LITERAL— a hexadecimal-formatted bitvector literal.bitzero— a named literal whose value is a bitvector consisting entirely of zero bits.bitone— a named literal whose value is a bitvector consisting entirely of one bits.
The two numeric literal forms (BINARY_LITERAL, HEXADECIMAL_LITERAL) provide explicit, width-carrying representations of bitvectors in source code, while bitzero and bitone provide convenient names for the all-zero and all-one bitvectors.
Occurrences in the Grammar
The <lit> production containing bitvector literals appears in several places in the Sail grammar:
- In atomic patterns (
<atomic_pat>), allowing bitvector literals to be used as pattern matches. - In atomic expressions (
<atomic_exp>), allowing bitvector literals as values in expressions. - In atomic types (
<atomic_typ>), allowing bitvector literals to be used in type-level contexts.
These appearances mean bitvector literals can be written both as values and within pattern-matching positions during match expressions.
Related Concepts
- Sail ISA Specification Language — The language in which bitvector literals are defined.
- BNF Grammar — The grammar formalism used to specify the syntax of bitvector literals.
References
- Sail language specification (grammar excerpt).