svstuff / systemverilog

SystemVerilog stuff and stuff.
http://svstuff.github.io/systemverilog
MIT License
11 stars 4 forks source link

Keyword as a net name #9

Closed eymre closed 8 years ago

eymre commented 9 years ago

Hello svstuff,

First of all thanks for putting this together. I'm trying to parse a simple SV code but having trouble with the assign with the lvalue in curly braces:

    module MyMod(input op1, input op2, input cin, output sum, output cout);
        assign {cout, sum} = op1 + op2 + cin;
    endmodule

    module TopMod (input clk);
        logic op1, op2, cin, sum, cout;
        MyMod MyInst( op1, op2, cin, sum, cout);
    endmodule

Relevant parts from the debug output:

consume KW_ASSIGN(sample.sv,2,2,assign) rule continuous_assign
enter   list_of_variable_assignments, LT(1)={
enter   variable_assignment, LT(1)={
enter   variable_lvalue, LT(1)={
consume LCURLY(sample.sv,2,9,{) rule variable_lvalue
enter   variable_lvalue, LT(1)=cout
consume ID(sample.sv,2,10,cout) rule variable_lvalue
enter   select, LT(1)=,
enter   bit_select, LT(1)=,
exit    bit_select, LT(1)=,
exit    select, LT(1)=,
exit    variable_lvalue, LT(1)=,
consume COMMA(sample.sv,2,14,,) rule variable_lvalue
enter   variable_lvalue, LT(1)=sum
line 2:19 no viable alternative at input 'sum}'
...
ERROR Driver - Parsing failed. Found:}
Expected one of: identifier $unit ' { and byte int integer local longint option or shortint super this time type unique xor std find find_index find_first find_first_index find_last find_last_index min max unique_index reverse sort rsort shuffle sum product
In: /import/mn-sca-rtl1/eburhan/sysv/systemverilog/systemverilog-develop/sample/sample.sv(2,18)

I.e. the sum wire:

assign {cout, sum} = op1 + op2 + cin;
                      ^

variable_lvalue rule has LCURLY variable_lvalue (COMMA variable_lvalue)* RCURLY pattern which should parse this construct but isn't.

I'm a completely newbie in antlr grammar so any help would be very appreciated.

Thanks,

eymre commented 9 years ago

Found the issue: sum output is detected as a keyword (SV sum method?) and that confuses the parser. Is there an easy workaround for this? Updated the issue title. Thank you.

eriklovlie commented 8 years ago

Oops, sorry, I completely missed your bug report! Much appreciated though! I think this should be an easy fix.

svstuff commented 8 years ago

Thanks @eymre, you nailed it :) Sorry it took so long to notice the bug report; I need to fix the git notification settings it seems.

Btw, the keyword vs identifier thing might be a bit surprising. Basically the LRM has special grammar for certain constructs (such as the builtin array methods), and the ANLTR grammar is much easier to write if, say, the builtin method names are both special tokens and identifiers. So the lexer creates special tokens for many non-keywords and defers to the parser to decide whether it is a keyword or an identifier in that particular context. The problem here was just that the rule bypassed the identifier rule that handles this stuff.

svstuff commented 8 years ago

Fixed my github notification settings :)

eymre commented 8 years ago

Thank you for the fix :)