Skip to main content

Lexical Elements

This section covers the basic building blocks of SHDL syntax.

Comments

SHDL supports three comment styles:

Hash Comments (Single-line)

# This is a comment
A -> B; # Inline comment

String Comments (Single-line)

"This is also a comment"

Triple-quoted Comments (Multi-line)

"""
This is a multi-line comment.
It can span multiple lines.
Useful for documentation blocks.
"""

Identifiers

Identifiers name components, instances, ports, and constants.

Rules

  • Must start with a letter (a-z, A-Z)
  • May contain letters, digits (0-9), and underscores (_)
  • Case-sensitive (MyGatemygate)

Examples

Valid identifiers:

gate1
FullAdder
my_component
ALU_8bit
DataBus

Invalid identifiers:

1gate       # Cannot start with digit
my-gate # Hyphens not allowed
@special # Special characters not allowed

Operators and Delimiters

SymbolNamePurpose
->ArrowConnection operator
::ScopeModule scope resolution
{}BracesBlock delimiters
[]BracketsBit indexing, ranges, generators
()ParenthesesPort lists
:ColonType declaration, range separator
;SemicolonStatement terminator
,CommaList separator
.DotInstance port access
=EqualsConstant assignment
>Greater-thanGenerator prefix

Literals

Decimal Integers

0
42
255
1024

Hexadecimal Integers

Prefix with 0x or 0X:

0xFF
0x1A3B
0X00FF

Binary Integers

Prefix with 0b or 0B:

0b1010
0b11111111
0B0001

Number Formats Summary

FormatPrefixExampleDecimal Value
Decimal(none)100100
Hexadecimal0x0x64100
Binary0b0b01100100100