LRM読解(Chap.2 字句定義/語彙規約)

2008/08/31Verilog::文法import

字句定義/語彙規約 ~ Lexical conventions (LRM-Chap.2)

LRMから,少し抜粋.

数値表現

| binary  | [size]*'[s|S]*(b|B)[01]+
| octal   | [size]*'[s|S]*(o|O)[0-7]+
| hexa    | [size]*'[s|S]*(h|H)[0-9a-fA-F]+
| decimal | ([size]*'[s|S]*(d|D)[0-9]+)|([0-9]+)

LRM 2.5.1 Integer constants

Example 3 Using sign with constant numbers

8'd-6   // 構文違反.
-8'd6   // 6の2の補数を示します.8bitサイズを保持します.
4'shf   // これはbinaryで 4bitの'1111'と書き直せます.
        // 2の補数表現では-1になります.
        // 即ち,これは -4'h1と等価です.
-4'sd15 // 同様にして,これは 4'd1と等価です.(-(-4'd1))

LRM 2.6 Strings

一行内で,double quotes("")で閉じられた部分を文字列とみなします.unsigned int定数として 8bit ASCII文字を取り扱うことができます.

文字列変数?の定義と使い方

stringvarというレジスタ変数を用意し,"Hello world!"を代入してみましょう.

 reg [8*12:1] stringvar;
 initial begin
   stringvar = "Hello world!";
 end

8bit widthの[12:1]配列,と見ればいいんですかねぇ.[8*(欲しい文字数):1]とすればよいようです.C言語と違い,NULL挿入はされない模様です.


LRM 2.6.2 の NOTE

意訳で敵どうだけれど,まぁ,こんなもんで.

When a variable is larger than required to hold a value being assigned,
the contents on the left are padded with zeros after the assignment.
This is consistent with the padding that occurs during assignment of nonstring values.

変数のほうが,文字列よりも大きい場合には,左側がゼロパディングされます.これは,定数のパディングと矛盾しないようになっているからである.(意訳)

If a string is larger than the destination string variable,
the string is truncated to the left, and the leftmost characters will be lost.
文字列のほうが長い場合には,文字列の左側が失われます.
LRM 2.6.3 特殊文字

C言語と同様に,下記の特殊文字が定義されます.エスケープ記号とか..

Escape Stringescape stringで示される文字
\n改行文字
\tタブ文字
\\\(バックスラッシュ, \x5C)
\"double quote(",\x22)
\dddキャラクタコード指定. dは0~7の数値を示す. ただし, 1~3個で構成する(3個必要なわけではない).

LRM 2.7 Identifiers, keywords, and system names

識別子は、それに参照をつけることができるようにユニークな名前をオブジェクトに与えるのに使用されます。識別子は、簡単な識別子かエスケープされた識別子(LRM 2.7.1参照)のどちらかです。簡単な識別子は 文字、数字、ドル記号($)、およびアンダースコア(_)の組み合わせである。簡単な識別氏の一文字目は,数値やドル記号にすべきではないです.英字か,アンダースコアなら可能です.識別子は大文字と小文字を区別するでしょう.

原文

An identifier is used to give an object a unique name so it can be referenced.
An identifier is either a simple identifier or an escaped identifier (see 2.7.1).
A simple identifier shall be any sequence of letters, digits, dollar signs ($), and underscore characters (_).
The first character of a simple identifier shall not be a digit or $;
it can be a letter or an underscore. Identifiers shall be case sensitive.

naming rule?
  • System task/functionの名前は,'$'で始まる.[LRM2.7.4]

2.8 Attribute[LRM 2.8]

syntax

attribute_instance ::= (From Annex A - A.9.1)
  (* attr_spec { , attr_spec } *)

attr_spec ::=
  attr_name = constant_expression
  | attr_name

attr_name ::=
  identifier