Skip to content

handle [ in var declaration and ( or [ in scope declaration - #29

Closed
andreabellizzi wants to merge 2 commits into
SanDisk-Open-Source:masterfrom
andreabellizzi:master
Closed

handle [ in var declaration and ( or [ in scope declaration#29
andreabellizzi wants to merge 2 commits into
SanDisk-Open-Source:masterfrom
andreabellizzi:master

Conversation

@andreabellizzi

@andreabellizzi andreabellizzi commented Jul 10, 2023

Copy link
Copy Markdown

some var are declared like:
$var integer 32 p&! varname [1423][SOMENAME][2] $end

some scope are declared like:
$scope begin scope_name(432) $end
which is out of spec but seen in vcd dump

some var are declared like:
$var integer  32 p&!  varname [1423][2] $end

some scope are declared like:
$scope begin scope_name(432) $end 
which is out of spec but seen in vcd dump
@andreabellizzi andreabellizzi changed the title handle [ in var declaration and ( in scope declaration handle [ in var declaration and ( or [ in scope declaration Jul 17, 2023
jpgrayson added a commit that referenced this pull request Aug 10, 2026
Scope identifiers and variable references in real VCD files routinely
contain characters that IEEE 1800-2023 21.7 admits only within escaped
identifiers, e.g. verilator's mem_array[0] and genblock[3].mod, UVM's
uvm_phase::m_wait_for_pred, and cva6's scope_name(432). Extending the
simple identifier character set once per newly reported character does
not converge, so lex these names as everything up to whitespace instead,
and keep the identifier lexer for keywords, types, and units, where the
character set of a simple identifier does apply. For scopes this also
matches the grammar, which gives scope_identifier ::= { ASCII character }
rather than an identifier.

A variable reference is ambiguous once brackets are part of a name:
mem_array[0] is indistinguishable from a bit select of mem_array.
Whitespace cannot separate the two, as the reference in the standard's
own example is unspaced:

    $var reg 32 (k accumulator[31:0] $end

So only the final bracketed section of a reference is treated as a bit
index, and only when it holds decimal indices. This preserves the
existing interpretation of accumulator[31:0] and foo [17] while
admitting references such as varname[1423][SOMENAME][2]. Brackets within
an escaped identifier are always part of the name.

Resolves issues #22 and #35 and supersedes PRs #29, #40, and #41.
@jpgrayson

Copy link
Copy Markdown
Collaborator

Thanks for this, and sorry for the long delay. Fixed in 92b8181 by a different route.

Rather than special-casing brackets and parens in the parser, $scope identifiers and $var references are now lexed as everything up to whitespace, and the bit index is split back off the reference afterwards.

Both of your cases are covered, including $var integer 32 p&! varname [1423][SOMENAME][2] $end, which now gives reference='varname[1423][SOMENAME]' and bit_index=2. A non-numeric index stays part of the reference. $scope begin scope_name(432) $end was already working.

I added test cases from your report.

Closing in favor of the version on master.

@jpgrayson jpgrayson closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants