sv-parser icon indicating copy to clipboard operation
sv-parser copied to clipboard

parameter array of strings causes an syntax error

Open fpgauserdude opened this issue 1 year ago • 4 comments

localparam string TESTED_VERSIONS[] =
   {
     "2023.1",
     "2023.2"
    };

$ svinst test.sv files: parse failed: "test.sv" test.sv:72:42 | 72 | localparam string TESTED_VERSIONS[] = | ^

The syntax is maybe a little weird, but perfectly legal. This code compiles on a commercial tool.

fpgauserdude avatar Sep 06 '24 22:09 fpgauserdude

According to Formal syntax of LRM, localparam can take unpacked_dimension only, so [] can't be used.

local_parameter_declaration ::= localparam data_type_or_implicit list_of_param_assignments
list_of_param_assignments ::= param_assignment { , param_assignment }
param_assignment ::= parameter_identifier { unpacked_dimension } [ = constant_param_expression ]
unpacked_dimension ::= [ constant_range ] | [ constant_expression ]

dalance avatar Sep 13 '24 06:09 dalance

I changed the code to the following

localparam string TESTED_VERSIONS[2] =
   {
     "2023.1",
     "2023.2"
    };

And the parse does work.

But the only way I discovered this problem was by using sv-parse. Every other SystemVerilog tool that I am aware:.

Vivado, Questa, Quartus, even Verible (another FOSS tool) parse this code just fine.

fpgauserdude avatar Sep 13 '24 14:09 fpgauserdude

For example, Synopsys Formality outputs syntax error to this code. A purpose of sv-parser is detecting such corner cases (almost all tools work fine, but some tools don't) by implementing as Formal syntax is.

dalance avatar Sep 13 '24 15:09 dalance

I can appreciate the value of finding code that is not strictly compliant with the LRM. Sometimes I think that HDL tool vendors do not do the developer community any favors by allowing code that is non-compliant.

fpgauserdude avatar Sep 13 '24 15:09 fpgauserdude