LRM expression definition oddities?

E

Evan Lavelle

Guest
The definition of an expression seems to be rather curious:

expression ::=
primary
| unary_operator { attribute_instance } primary
| expression binary_operator { attribute_instance } expression
| conditional_expression
| string
From a C point of view, you might expect a string to be a primary, and
not an expression. I've checked 3 sims, and they all seem to think
that a string actually *is* a primary (code below; see the line 'c =
~stringvar'), so presumably all 3 sims are non-conforming.

Secondly, with a C world view you might expect to be allowed to do 'c
= ~~a' (see below), but all 3 sims agree that this is illegal
(because, from the production above, '~a' is an expression, so you
can't apply another unary op to it). This is slightly surprising,
because it's an arbitrary limitation, and the rest of the expression
syntax is fairly C-like.

Thoughts?

Evan

--------------------------------------------------------------
module test;
reg [8*11:1] stringvar;
initial
main;
task main;
integer a, b, c;
begin
stringvar = "Hello world";
a = 3;
b = ~a;
// c = ~~a; syntax error
c = ~stringvar;
$display("a: %h; b: %h; c: %h\n", a, b, c);
end
endtask
endmodule
 
Evan Lavelle wrote:
The definition of an expression seems to be rather curious:

expression ::=
primary
| unary_operator { attribute_instance } primary
| expression binary_operator { attribute_instance } expression
| conditional_expression
| string

From a C point of view, you might expect a string to be a primary, and
not an expression. I've checked 3 sims, and they all seem to think
that a string actually *is* a primary (code below; see the line 'c =
~stringvar'), so presumably all 3 sims are non-conforming.
You should recognize that the BNF that is in the LRM was written
long after the language already existed. If you are used to regarding
the BNF in an LRM as the golden specification of the language
grammar, you should adjust your expectations. It would be more
realistic to view it as an attempt to document the grammar than as the
golden specification in this case. If there is disagreement between
the
BNF and something else in the LRM, the BNF is probably wrong. It
is not what a historian would call a primary source, and there are
aspects of figuring out the LRM that are more like historical research
than interpreting a technical specification. The BNF has been
improved since the 2001 LRM, but probably still has some errors.

Anyway, this particular production was changed in the Verilog-2005
LRM, so that a string literal is now a primary.


Secondly, with a C world view you might expect to be allowed to do 'c
= ~~a' (see below), but all 3 sims agree that this is illegal
(because, from the production above, '~a' is an expression, so you
can't apply another unary op to it). This is slightly surprising,
because it's an arbitrary limitation, and the rest of the expression
syntax is fairly C-like.
I haven't considered it very deeply, but suspect that it may be
related
to the existence of some extra operators that don't exist in C. For
example, there are the unary bitwise reduction operators that use the
same syntax as binary bitwise operators.
 
On 2 May 2007 15:57:35 -0700, sharp@cadence.com wrote:


Anyway, this particular production was changed in the Verilog-2005
LRM, so that a string literal is now a primary.
Thanks. I was using 2005-D3, so I've spent the money and got the real
thing. Which leads me on to a rant, directed at no-one in particular:

1 - Why does the IEEE charge $120 for a document that it didn't write
or fund, which the authors received no payment for, and which is
simply a fix to other documents that I've already bought anyway?

2 - And why is the IEEE illegally charging UK VAT on this document? It
charged an additional $21 to my card to cover VAT. There's no VAT
registration number on their invoice, and they're almost certainly not
registered for VAT. Even if they were registered, and there was VAT
due, it would be accounted for using a reverse charge; in other words,
the customer accounts for it, it's a paper transaction, and no money
changes hands. Where I come from, this looks suspiciously like fraud.

Evan
 
Evan Lavelle wrote:
1 - Why does the IEEE charge $120 for a document that it didn't write
or fund, which the authors received no payment for
The people who invest their efforts in revising it actually have to
pay
dues to the IEEE for the privilege of doing so. But that is a
slightly
different rant...
 

Welcome to EDABoard.com

Sponsor

Back
Top