verilog_parser.y 120.6 KB
Newer Older
饶先宏's avatar
饶先宏 已提交
1 2 3 4 5 6
%require  "3.0"
%defines 
%define parse.trace
%verbose

%define parse.error verbose
7
 
饶先宏's avatar
饶先宏 已提交
8
%{
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/*
** HDL4SE: 软件Verilog综合仿真平台
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** LCOM: 轻量级组件对象模型
** Copyright (C) 2021-2021, raoxianhong<raoxianhong@163.net>
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
**
** * Redistributions of source code must retain the above copyright notice,
**   this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright notice,
**   this list of conditions and the following disclaimer in the documentation
**   and/or other materials provided with the distribution.
** * The name of the author may be used to endorse or promote products
**   derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
** THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
* verilog_parser.y
  修改记录:
    202105280612: rxh, initial version
饶先宏's avatar
饶先宏 已提交
44
    202106291739: rxh, 表达式运算符优先级的语法实现,规范中没有给出运算符优先级的语法表达
45 46
*/

47
    #include <stdio.h> 
饶先宏's avatar
饶先宏 已提交
48 49
    #include <string.h>
    #include <assert.h>
50 51
    #include "object.h"
    #include "dlist.h"
52
    #include "conststring.h"
53
    #include "verilog_keyword.h"
饶先宏's avatar
饶先宏 已提交
54 55 56
    #include "bignumber.h"
    #include "mapstr2ptr.h"
    #include "verilog_parsetree.h"
饶先宏's avatar
饶先宏 已提交
57 58 59 60 61

    extern int yylex();
    extern int yylineno;
    extern char * yytext;

饶先宏's avatar
饶先宏 已提交
62 63
    HOBJECT lastport = NULL;
    HOBJECT lastparameter = NULL;
饶先宏's avatar
饶先宏 已提交
64
    HOBJECT currentmodule = NULL;
65
    static char logbuf[2048];
饶先宏's avatar
饶先宏 已提交
66
    void yyerror(const char *msg){
67
        IConstStringVar *pfilename;
68 69 70
        int lineno;
        int linepos;
        int filepos;
71 72 73 74 75 76 77
        pfilename = NULL;
        if (0 == hdl4se_parser_GetCurrentFile(&pfilename, &lineno, &linepos, &filepos)) {
            if (pfilename != NULL) {
                sprintf(logbuf, "file %s line %d - ERROR: %s\n - '%s'", pfilename->string, lineno, msg, yytext);
                hdl4se_parser_AddLog(logbuf);
            }
        }
饶先宏's avatar
饶先宏 已提交
78
    }
79 80
%} 
 
饶先宏's avatar
饶先宏 已提交
81 82 83 84
%code requires{
#include "stdio.h"
#include "object.h"
#include "dlist.h"
85
#include "bignumber.h"
86
#include "conststring.h"
饶先宏's avatar
饶先宏 已提交
87
#include "mapstr2ptr.h"
饶先宏's avatar
饶先宏 已提交
88 89 90
#include "verilog_parsetree.h"
#include "verilog_root.h"
#include "verilog_module.h"
91
#include "verilog_keyword.h"
92
#include "verilog_attrspec.h"
饶先宏's avatar
饶先宏 已提交
93
#include "verilog_parameter.h"
饶先宏's avatar
饶先宏 已提交
94
#include "verilog_expr.h"
饶先宏's avatar
饶先宏 已提交
95
#include "verilog_port.h"
饶先宏's avatar
饶先宏 已提交
96
#include "verilog_vardecl.h"
97
#include "verilog_varsel.h"
饶先宏's avatar
饶先宏 已提交
98 99
#include "verilog_paraminst.h"
#include "verilog_moduleinst.h"
饶先宏's avatar
饶先宏 已提交
100
#include "verilog_assignment.h"
饶先宏's avatar
饶先宏 已提交
101
#include "verilog_statement.h"
饶先宏's avatar
饶先宏 已提交
102 103 104 105 106
}

/* token types */
%union {
	HOBJECT treenode;
饶先宏's avatar
饶先宏 已提交
107
    HOBJECT obj;
饶先宏's avatar
饶先宏 已提交
108 109 110 111 112
    struct _mul_obj {
      int type;
      int objcount;
      HOBJECT obj[16];
    }mul_obj;
113
    struct _str_bind_obj {
饶先宏's avatar
饶先宏 已提交
114
        IConstStringVar * key;
115 116
        HOBJECT obj;
    }str_bind_obj;
饶先宏's avatar
饶先宏 已提交
117
	IConstStringVar * string;
饶先宏's avatar
饶先宏 已提交
118 119
	int token;
	int operator;
120
	int ival;
饶先宏's avatar
饶先宏 已提交
121
	IDListVar* list;
饶先宏's avatar
饶先宏 已提交
122 123 124 125 126 127 128 129
}

%token <string> END  ANY  NEWLINE  SPACE  TAB

%token <string> BIN_VALUE  OCT_VALUE  HEX_VALUE  DEC_VALUE  
				DEC_BASE  BIN_BASE  OCT_BASE  HEX_BASE  
				NUM_REAL  NUM_SIZE  UNSIGNED_NUMBER  
				SYSTEM_ID  SIMPLE_ID  ESCAPED_ID  DEFINE_ID  
饶先宏's avatar
饶先宏 已提交
130 131 132
				STRING 
 
/* Operators Precedence fdsa */
133
%token <token> '@' ',' '#' '.' '=' ':' ';' '(' ')' '[' ']' '{' '}' '+' '-' '*' '/' '%' '>' '<' '!' '&' '|' '^' '~' '?' 
饶先宏's avatar
饶先宏 已提交
134

饶先宏's avatar
饶先宏 已提交
135
%token <token> ATTRIBUTE_START ATTRIBUTE_END ASL ASR LSL LSR GTE LTE L_AND L_OR L_EQ C_EQ L_NEQ C_NEQ B_EQU B_NAND B_NOR IDX_PRT_SEL POW  T_AND
饶先宏's avatar
饶先宏 已提交
136
               STARTPLUSWIDTH STARTMINUSWIDTH MINUSGT EQGT STARGT
饶先宏's avatar
饶先宏 已提交
137

138
%token <token>  KW_ALWAYS  KW_AND  KW_ASSIGN  KW_AUTOMATIC  KW_BEGIN  KW_BUF  KW_BUFIF0  KW_BUFIF1  KW_CASE  KW_CASEX  
饶先宏's avatar
饶先宏 已提交
139 140 141 142 143 144 145 146 147 148 149 150
				KW_CASEZ  KW_CELL  KW_CMOS  KW_CONFIG  KW_DEASSIGN  KW_DEFAULT  KW_DEFPARAM  KW_DESIGN  KW_DISABLE  
				KW_EDGE  KW_ELSE  KW_END  KW_ENDCASE  KW_ENDCONFIG  KW_ENDFUNCTION  KW_ENDGENERATE  KW_ENDMODULE  
				KW_ENDPRIMITIVE  KW_ENDSPECIFY  KW_ENDTABLE  KW_ENDTASK  KW_EVENT  KW_FOR  KW_FORCE  KW_FOREVER  KW_FORK  
				KW_FUNCTION  KW_GENERATE  KW_GENVAR  KW_HIGHZ0  KW_HIGHZ1  KW_IF  KW_IFNONE  KW_INCDIR  KW_INCLUDE  
				KW_INITIAL  KW_INOUT  KW_INPUT  KW_INSTANCE  KW_INTEGER  KW_JOIN  KW_LARGE  KW_LIBLIST  KW_LIBRARY  
				KW_LOCALPARAM  KW_MACROMODULE  KW_MEDIUM  KW_MODULE  KW_NAN  KW_NEGEDGE  KW_NMOS  KW_NOR  KW_NOSHOWCANCELLED  
				KW_NOT  KW_NOTIF0  KW_NOTIF1  KW_OR  KW_OUTPUT  KW_PARAMETER  KW_PATHPULSE  KW_PMOS  KW_POSEDGE  KW_PRIMITIVE  
				KW_PULL0  KW_PULL1  KW_PULLDOWN  KW_PULLUP  KW_PULSESTYLE_ONEVENT  KW_PULSESTYLE_ONDETECT  KW_RCMOS  
				KW_REAL  KW_REALTIME  KW_REG  KW_RELEASE  KW_REPEAT  KW_RNMOS  KW_RPMOS  KW_RTRAN  KW_RTRANIF0  KW_RTRANIF1  
				KW_SCALARED  KW_SHOWCANCELLED  KW_SIGNED  KW_SMALL  KW_SPECIFY  KW_SPECPARAM  KW_STRONG0  KW_STRONG1  
				KW_SUPPLY0  KW_SUPPLY1  KW_TABLE  KW_TASK  KW_TIME  KW_TRAN  KW_TRANIF0  KW_TRANIF1  KW_TRI  KW_TRI0  
				KW_TRI1  KW_TRIAND  KW_TRIOR  KW_TRIREG  KW_UNSIGNED  KW_USE  KW_VECTORED  KW_WAIT  KW_WAND  KW_WEAK0  
饶先宏's avatar
饶先宏 已提交
151 152 153
				KW_WEAK1  KW_WHILE  KW_WIRE  KW_WOR  KW_XNOR  KW_XOR KW_NAND KW_UWIRE 
                KW_SYS_SETUP KW_SYS_HOLD KW_SYS_SETUPHOLD KW_SYS_RECOVERY KW_SYS_REMOVAL KW_SYS_RECREM KW_SYS_SKEW 
                KW_SYS_TIMESKEW KW_SYS_FULLSKEW KW_SYS_PERIOD KW_SYS_WIDTH KW_SYS_NOCHANGE 
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170

/* Operator Precedence */


%right  '?'                 /* Lowest Precedence */
%left   L_OR
%left   L_AND
%left   '|' B_NOR
%left   B_EQU '^'
%left   B_NAND '&'
%left   L_EQ C_EQ L_NEQ C_NEQ
%left   '>' '<' GTE LTE
%left   LSL LSR ASR ASL
%left   '+' '-'
%left   '*' '/' '%'
%left   POW
%right  '!' '~'    /* Highest Precedence. */
饶先宏's avatar
饶先宏 已提交
171 172 173
				
%start grammar_begin

174 175
%type <string> attr_name identifier module_identifier 
               topmodule_identifier parameter_identifier
饶先宏's avatar
饶先宏 已提交
176
               port_identifier net_identifier
饶先宏's avatar
饶先宏 已提交
177
               module_instance_identifier
饶先宏's avatar
饶先宏 已提交
178
               number string unsigned_number 
179

180 181 182
%type <ival> parameter_type 
             unary_operator 
             binary_operator 
饶先宏's avatar
饶先宏 已提交
183 184 185 186
             signed_option
             unary_module_path_operator 
             binary_module_path_operator
             net_type net_type_option output_variable_type
饶先宏's avatar
饶先宏 已提交
187
             vectored_or_scalared_option vectored_option scalared_option
饶先宏's avatar
饶先宏 已提交
188 189 190
             case_type

%type <ival> event_expression event_control delay_or_event_control procedural_timing_control
饶先宏's avatar
饶先宏 已提交
191

饶先宏's avatar
饶先宏 已提交
192 193
%type <mul_obj> range range_option constant_range_expression dimension  
                mintypmax_expression mintypmax_expression_option var
饶先宏's avatar
饶先宏 已提交
194
%type <str_bind_obj> port_ident param_assignment net_decl_assignment
饶先宏's avatar
饶先宏 已提交
195
                   
196

197
%type <treenode>  attr_spec 
饶先宏's avatar
饶先宏 已提交
198
%type <treenode>  constant_mintypmax_expression 
饶先宏's avatar
饶先宏 已提交
199 200 201 202 203 204 205
                  port parameter_declaration
                  port_declaration inout_declaration input_declaration output_declaration
                  port_reference
                  constant_base_expression
                  width_constant_expression
                  msb_constant_expression 
                  lsb_constant_expression
饶先宏's avatar
饶先宏 已提交
206
                  dimension_constant_expression
饶先宏's avatar
饶先宏 已提交
207
                  concatenation multiple_concatenation
饶先宏's avatar
饶先宏 已提交
208 209 210 211
                  primary unary_expression pow_expression multiplicative_expression
                  additive_expression shift_expression relational_expression equality_expression
                  and_expression exclusive_or_expression inclusive_or_expression
                  logical_and_expression logical_or_expression conditional_expression 
饶先宏's avatar
饶先宏 已提交
212
                  expression expression_option
饶先宏's avatar
饶先宏 已提交
213 214
                  constant_concatenation constant_multiple_concatenation
                  constant_primary unary_constant_expression pow_constant_expression multiplicative_constant_expression
215 216 217 218
                  additive_constant_expression shift_constant_expression relational_constant_expression equality_constant_expression
                  and_constant_expression exclusive_or_constant_expression inclusive_or_constant_expression
                  logical_and_constant_expression logical_or_constant_expression conditional_constant_expression 
                  constant_expression
饶先宏's avatar
饶先宏 已提交
219
                  base_expression
饶先宏's avatar
饶先宏 已提交
220 221 222
                  module_instance
                  ordered_parameter_assignment named_parameter_assignment
                  named_port_connection ordered_port_connection
饶先宏's avatar
饶先宏 已提交
223
                  net_assignment
饶先宏's avatar
饶先宏 已提交
224
                  hierarchical_identifier_part
饶先宏's avatar
饶先宏 已提交
225 226
                  statement statement_or_null blocking_assignment nonblocking_assignment
                  par_block seq_block case_statement conditional_statement case_item 
227

饶先宏's avatar
饶先宏 已提交
228 229
%type <list> attribute_instance_list attribute_instance attribute_instance_spec_list
             hierarchical_identifier 
饶先宏's avatar
饶先宏 已提交
230 231 232 233
%type <list> list_of_net list_of_net_identifiers list_of_net_decl_assignments

%type <list> dimension_list

饶先宏's avatar
饶先宏 已提交
234
%type <list> module_parameter_port_list module_param_list  
饶先宏's avatar
饶先宏 已提交
235
             list_of_param_assignments port_declaration_list
饶先宏's avatar
饶先宏 已提交
236 237 238 239 240
             list_of_port_connections_option

%type <list> module_instance_list parameter_value_assignment_option parameter_value_assignment
             list_of_parameter_assignments ordered_parameter_assignment_list named_parameter_assignment_list
             list_of_port_connections ordered_port_connection_list named_port_connection_list
241 242 243

%type <list> list_of_port_declarations
             list_of_ports module_item_list non_port_module_item_list 
饶先宏's avatar
饶先宏 已提交
244
             ports port_declarations port_expression
245

饶先宏's avatar
饶先宏 已提交
246 247
%type <list> list_of_net_assignments

饶先宏's avatar
饶先宏 已提交
248 249
%type <list> expression_list constant_expression_list

饶先宏's avatar
饶先宏 已提交
250
%type <list> statement_list case_item_list
饶先宏's avatar
饶先宏 已提交
251

饶先宏's avatar
饶先宏 已提交
252 253
%%

254
/* Start variables */
饶先宏's avatar
饶先宏 已提交
255
grammar_begin : 
256 257
  library_text {}
| source_text {}
258 259
| %empty {
}
饶先宏's avatar
饶先宏 已提交
260 261 262 263 264
;

/* A.1.1 Library Source Text */

library_text : 
265 266
  library_descriptions {}
| library_text library_descriptions{}
饶先宏's avatar
饶先宏 已提交
267 268 269
;

library_descriptions : 
270 271 272
  library_declaration{}
| include_statement{}
| config_declaration{}
饶先宏's avatar
饶先宏 已提交
273 274 275
;

library_declaration : 
276 277
  KW_LIBRARY library_identifier file_path_specs ';'{}
| KW_LIBRARY library_identifier file_path_specs KW_INCDIR file_path_specs ';'{}
饶先宏's avatar
饶先宏 已提交
278 279 280
;

file_path_specs : 
281 282
  file_path_spec{}
| file_path_specs ',' file_path_spec{}
饶先宏's avatar
饶先宏 已提交
283 284
;

285
file_path_spec : file_path{}
饶先宏's avatar
饶先宏 已提交
286 287
;

288
file_path : string {}
饶先宏's avatar
饶先宏 已提交
289 290
;

291
include_statement : KW_INCLUDE file_path_spec ';'{}
饶先宏's avatar
饶先宏 已提交
292
;
293 294
   
/* A.1.2  Verilog source text. */
饶先宏's avatar
饶先宏 已提交
295 296 297

source_text : 
  description {
298
  }
饶先宏's avatar
饶先宏 已提交
299 300 301 302 303 304
| source_text description{
}
;

description : 
  module_declaration {
305 306
  }
| udp_declaration {
饶先宏's avatar
饶先宏 已提交
307
}
308
| config_declaration {
饶先宏's avatar
饶先宏 已提交
309 310 311
}
;

饶先宏's avatar
饶先宏 已提交
312
module_item_list :
313
    %empty {
饶先宏's avatar
饶先宏 已提交
314 315 316 317 318 319 320 321
    }
|   module_item {
    }
|   module_item_list module_item {
    }
  ;

non_port_module_item_list :
322
    %empty {
饶先宏's avatar
饶先宏 已提交
323 324 325 326 327 328 329
    }
|   non_port_module_item {
    }
|   non_port_module_item_list non_port_module_item {
    }
  ;

饶先宏's avatar
饶先宏 已提交
330
module_declaration : 
331
  attribute_instance_list
饶先宏's avatar
饶先宏 已提交
332 333 334
  module_keyword
  module_identifier
  module_parameter_port_list
335 336
  list_of_ports
  ';'
饶先宏's avatar
饶先宏 已提交
337 338 339
  {
    IVerilogRoot ** ppRoot = getVerilogRoot();
	(*ppRoot)->add_module(ppRoot, $3, currentmodule = verilogparseCreateModuleDeclaration($1,$3,$4,$5));
饶先宏's avatar
饶先宏 已提交
340
    objectRelease($3);
饶先宏's avatar
饶先宏 已提交
341 342 343
    lastport = NULL;
    lastparameter = NULL;
  }
344
  module_item_list
饶先宏's avatar
饶先宏 已提交
345
  KW_ENDMODULE
346
{
饶先宏's avatar
饶先宏 已提交
347
/*
饶先宏's avatar
饶先宏 已提交
348
	IVerilogRoot ** ppRoot = getVerilogRoot();
饶先宏's avatar
饶先宏 已提交
349
	(*ppRoot)->add_module(ppRoot, $3, verilogparseCreateModuleDeclaration($1,$3,$4,$5));
饶先宏's avatar
饶先宏 已提交
350
    objectRelease($3);
饶先宏's avatar
饶先宏 已提交
351 352
    lastport = NULL;
    lastparameter = NULL;
饶先宏's avatar
饶先宏 已提交
353 354
*/
    currentmodule = NULL;
355 356 357
}  

| attribute_instance_list
饶先宏's avatar
饶先宏 已提交
358 359 360
  module_keyword
  module_identifier
  module_parameter_port_list
361 362
  list_of_port_declarations
  ';'
饶先宏's avatar
饶先宏 已提交
363 364 365
  {
	IVerilogRoot ** ppRoot = getVerilogRoot();
	(*ppRoot)->add_module(ppRoot, $3, currentmodule = verilogparseCreateModuleDeclaration($1,$3,$4,$5));
饶先宏's avatar
饶先宏 已提交
366
    objectRelease($3);
饶先宏's avatar
饶先宏 已提交
367 368 369 370
    lastport = NULL;
    lastparameter = NULL;

  }
371 372 373
  non_port_module_item_list
  KW_ENDMODULE
  {
饶先宏's avatar
饶先宏 已提交
374
/*
饶先宏's avatar
饶先宏 已提交
375
	IVerilogRoot ** ppRoot = getVerilogRoot();
饶先宏's avatar
饶先宏 已提交
376
	(*ppRoot)->add_module(ppRoot, $3, verilogparseCreateModuleDeclaration($1,$3,$4,$5));
饶先宏's avatar
饶先宏 已提交
377
    objectRelease($3);
饶先宏's avatar
饶先宏 已提交
378 379
    lastport = NULL;
    lastparameter = NULL;
饶先宏's avatar
饶先宏 已提交
380 381
    */
    currentmodule = NULL;
饶先宏's avatar
饶先宏 已提交
382
  }
饶先宏's avatar
饶先宏 已提交
383 384
;

385 386 387 388 389 390 391
module_keyword :
  KW_MODULE {
  }
| KW_MACROMODULE {
  }
  ;

饶先宏's avatar
饶先宏 已提交
392

393 394 395
/*
A.1.3 Module parameters and ports
*/
饶先宏's avatar
饶先宏 已提交
396

397
module_parameter_port_list  : 
398
   %empty {
饶先宏's avatar
饶先宏 已提交
399
    $$ = dlistCreate();
饶先宏's avatar
饶先宏 已提交
400
    lastparameter = NULL;
401 402
    }
|   '#' '(' module_param_list ')'{
饶先宏's avatar
饶先宏 已提交
403
    $$ = $3;
饶先宏's avatar
饶先宏 已提交
404
    lastparameter = NULL;
饶先宏's avatar
饶先宏 已提交
405 406 407
}
;

408 409
module_param_list : 
  parameter_declaration {
饶先宏's avatar
饶先宏 已提交
410 411
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
饶先宏's avatar
饶先宏 已提交
412
  }
413 414
| module_param_list ',' parameter_declaration{
	$$ = $1;
饶先宏's avatar
饶先宏 已提交
415
	dlistAppendItem($$, $3);
饶先宏's avatar
饶先宏 已提交
416 417 418
}
;

419 420
list_of_ports :
    %empty {
饶先宏's avatar
饶先宏 已提交
421
    $$ = dlistCreate();
饶先宏's avatar
饶先宏 已提交
422
}
423
| '(' ports ')' {
饶先宏's avatar
饶先宏 已提交
424 425 426 427
    $$ = $2;
}
;

饶先宏's avatar
饶先宏 已提交
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
/*
我们不支持复杂端口定义 
*/
ports : 
    %empty {
	$$ = dlistCreate();
}
| ports ',' port_identifier{
    $$ = $1;
    dlistAppendItem($$,
        verilogparseCreatePort(
            NULL, /* IDListVarPtr attributes, */
            PORT_DIRECT_UNKNOW, /* int port_direct, */
            0, /* int port_type, */
            0, /* int port_issigned, */
            RANGE_TYPE_NONE, /*int range_type*/
            NULL, /* HOBJECT param_range_msb,  expression */
            NULL, /* HOBJECT param_range_lsb,  expression */
            $3, /* const char * name, */
            NULL /* HOBJECT expr */
        )
    );
}
| port_identifier {
    $$ = dlistCreate();
    dlistAppendItem($$,
        verilogparseCreatePort(
            NULL, /* IDListVarPtr attributes, */
            PORT_DIRECT_UNKNOW, /* int port_direct, */
饶先宏's avatar
饶先宏 已提交
457
            VAR_TYPE_NONE, /* int port_type, */
饶先宏's avatar
饶先宏 已提交
458 459 460 461 462 463 464 465 466 467 468 469
            0, /* int port_issigned, */
            RANGE_TYPE_NONE, /*int range_type*/
            NULL, /* HOBJECT param_range_msb,  expression */
            NULL, /* HOBJECT param_range_lsb,  expression */
            $1, /* const char * name, */
            NULL /* HOBJECT expr */
        )
    );
}
;

/*
470 471
ports : 
    %empty {
饶先宏's avatar
饶先宏 已提交
472
	$$ = dlistCreate();
饶先宏's avatar
饶先宏 已提交
473
}
474
| ports ',' port{
饶先宏's avatar
饶先宏 已提交
475
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
476
    dlistAppendItem($$,$3);
饶先宏's avatar
饶先宏 已提交
477
}
478
| port {
饶先宏's avatar
饶先宏 已提交
479 480
    $$ = dlistCreate();
	dlistAppendItem($$,$1);
饶先宏's avatar
饶先宏 已提交
481 482
}
;
饶先宏's avatar
饶先宏 已提交
483
*/
饶先宏's avatar
饶先宏 已提交
484

485
list_of_port_declarations   : 
486
 '(' port_declarations ')'{
487
    $$ = $2;
饶先宏's avatar
饶先宏 已提交
488 489 490
}
;

491
port_declarations : 
492
  %empty { 
饶先宏's avatar
饶先宏 已提交
493
    $$ = dlistCreate();
494 495
  }
| port_declarations ',' port_declaration {
饶先宏's avatar
饶先宏 已提交
496
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
497
    dlistAppendItem($$,$3);
498 499
  }
| port_declaration {
饶先宏's avatar
饶先宏 已提交
500 501
    $$ = dlistCreate();
	dlistAppendItem($$,$1);
502 503
  }
  ;
饶先宏's avatar
饶先宏 已提交
504 505 506

port            : 
  port_expression{
507
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
508
  }
509
| '.' port_identifier '(' port_expression ')'{
饶先宏's avatar
饶先宏 已提交
510
   // $$ = verilogparserCreatePort($2, $4);
饶先宏's avatar
饶先宏 已提交
511 512 513 514
}
;

port_expression : 
515 516
   %empty {
	$$ = dlistCreate();
517 518
	}
| port_reference {
饶先宏's avatar
饶先宏 已提交
519 520
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
饶先宏's avatar
饶先宏 已提交
521
  }
522
| port_expression ',' port_reference{
饶先宏's avatar
饶先宏 已提交
523
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
524
    dlistAppendItem($$,$3);
饶先宏's avatar
饶先宏 已提交
525 526 527 528 529
}
;

port_reference  : 
  port_identifier{
饶先宏's avatar
饶先宏 已提交
530
  $$ = NULL;
饶先宏's avatar
饶先宏 已提交
531
}
532
| port_identifier '[' ']' {
饶先宏's avatar
饶先宏 已提交
533
  $$ = NULL;
饶先宏's avatar
饶先宏 已提交
534
}
535
| port_identifier '[' constant_range_expression ']' {
饶先宏's avatar
饶先宏 已提交
536
  $$ = NULL;
饶先宏's avatar
饶先宏 已提交
537 538 539
}
;

540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
/*
port_declaration : 
    attribute_instance_list inout_declaration {
    }
|   attribute_instance_list input_declaration {
    }
|   attribute_instance_list output_declaration {
    }
  ;
*/
/*
  IEEE. 1364-2005的这种格式端口定义不满足LALR(1),
  module test (
    input [7:0] a,
    input signed [7:0] b, c, d, 
    output [7:0] e, 
    output reg signed [7:0] f, g,
    output signed [7:0] h) ;
  endmodule
  原来的语法是分组描述的,然而注意每一组定义后面用逗号,
  与组内的标识符后的逗号冲突了,这样不满足LALR(1)的要求,
  现在改为为每个端口都是单独声明的,声明可以带属性也可以
  不带属性,不带属性的声明使用前面最近一个带属性的声明的
  属性。导致的问题有二:1.第一个端口必须是带属性的,这个
  应该由动作函数来做检查,2.output端口类型可以设置REG等属
  性并设置初始值,这是其他端口不能有的,这个也由动作函数
  来做检查吧。
  注意后面的input_declaration,input_declaration和
  output_declaration也做了相应的调整,每个后面不是跟一系列
  标识符,而是只跟一个port_ident了,这样就消除了冲突,满足
  LALR(1)的要求。
*/
572
port_declaration : 
饶先宏's avatar
饶先宏 已提交
573 574
    inout_declaration {
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
575
    lastport = $1;
576
    }
饶先宏's avatar
饶先宏 已提交
577 578
|   input_declaration {
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
579
    lastport = $1;
580
    }
饶先宏's avatar
饶先宏 已提交
581 582
|   output_declaration {
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
583
    lastport = $1;
584 585
    }
|   port_ident {
饶先宏's avatar
饶先宏 已提交
586 587 588
       $$ = verilogparseCreatePort(
            NULL, /* IDListVarPtr attributes, */
            PORT_DIRECT_ASPRE, /* int port_direct, */
饶先宏's avatar
饶先宏 已提交
589
            VAR_TYPE_NONE, /* int port_type, */
饶先宏's avatar
饶先宏 已提交
590 591 592 593 594 595 596
            0, /* int port_issigned, */
            RANGE_TYPE_NONE, /*int range_type*/
            lastport, /* HOBJECT param_range_msb,  expression */
            NULL, /* HOBJECT param_range_lsb,  expression */
            $1.key, /* const char * name, */
            $1.obj /* HOBJECT expr */
        );
597
    }
饶先宏's avatar
饶先宏 已提交
598 599
;

600 601 602 603
/*
下面修改过的语法从A.2.1.2过来的
*/
inout_declaration :
饶先宏's avatar
饶先宏 已提交
604
    attribute_instance_list KW_INOUT net_type_option signed_option range_option 
605
    port_ident {
饶先宏's avatar
饶先宏 已提交
606 607 608 609 610 611 612 613 614 615 616
    $$ = verilogparseCreatePort(
            $1, /* IDListVarPtr attributes, */
            PORT_DIRECT_INOUT, /* int port_direct, */
            $3, /* int port_type, */
            $4, /* int port_issigned, */
            $5.type, /*int range_type*/
            $5.obj[0], /* HOBJECT param_range_msb,  expression */
            $5.obj[1], /* HOBJECT param_range_lsb,  expression */
            $6.key, /* const char * name, */
            $6.obj /* HOBJECT expr */
        );
617 618 619 620
    }
  ;

input_declaration :
饶先宏's avatar
饶先宏 已提交
621
    attribute_instance_list KW_INPUT net_type_option signed_option range_option 
622
    port_ident {
饶先宏's avatar
饶先宏 已提交
623 624 625 626 627 628 629 630 631 632 633
    $$ = verilogparseCreatePort(
            $1, /* IDListVarPtr attributes, */
            PORT_DIRECT_INPUT, /* int port_direct, */
            $3, /* int port_type, */
            $4, /* int port_issigned, */
            $5.type, /*int range_type*/
            $5.obj[0], /* HOBJECT param_range_msb,  expression */
            $5.obj[1], /* HOBJECT param_range_lsb,  expression */
            $6.key, /* const char * name, */
            $6.obj /* HOBJECT expr */
        );
634 635 636 637
    }
  ;

output_declaration :
饶先宏's avatar
饶先宏 已提交
638
    attribute_instance_list KW_OUTPUT net_type_option signed_option range_option 
639
    port_ident {
饶先宏's avatar
饶先宏 已提交
640 641 642 643 644 645 646 647 648 649 650 651
    $$ = verilogparseCreatePort(
            $1, /* IDListVarPtr attributes, */
            PORT_DIRECT_OUTPUT, /* int port_direct, */
            $3, /* int port_type, */
            $4, /* int port_issigned, */
            $5.type, /*int range_type*/
            $5.obj[0], /* HOBJECT param_range_msb,  expression */
            $5.obj[1], /* HOBJECT param_range_lsb,  expression */
            $6.key, /* const char * name, */
            $6.obj /* HOBJECT expr */
        );

652
    }
饶先宏's avatar
饶先宏 已提交
653
|   attribute_instance_list KW_OUTPUT KW_REG signed_option range_option
654
    port_ident {
饶先宏's avatar
饶先宏 已提交
655 656
    $$ = verilogparseCreatePort(
            $1, /* IDListVarPtr attributes, */
饶先宏's avatar
饶先宏 已提交
657
            PORT_DIRECT_OUTPUT, /* int port_direct, */
饶先宏's avatar
饶先宏 已提交
658
            VAR_TYPE_REG, /* int port_type, */
饶先宏's avatar
饶先宏 已提交
659 660 661 662 663 664 665 666
            $4, /* int port_issigned, */
            $5.type, /*int range_type*/
            $5.obj[0], /* HOBJECT param_range_msb,  expression */
            $5.obj[1], /* HOBJECT param_range_lsb,  expression */
            $6.key, /* const char * name, */
            $6.obj /* HOBJECT expr */
        );

667
    }
饶先宏's avatar
饶先宏 已提交
668
|   attribute_instance_list KW_OUTPUT output_variable_type 
669
    port_ident {
饶先宏's avatar
饶先宏 已提交
670 671
    $$ = verilogparseCreatePort(
            $1, /* IDListVarPtr attributes, */
饶先宏's avatar
饶先宏 已提交
672
            PORT_DIRECT_OUTPUT, /* int port_direct, */
饶先宏's avatar
饶先宏 已提交
673 674 675 676 677 678 679 680
            $3, /* int port_type, */
            0, /* int port_issigned, */
            RANGE_TYPE_NONE, /*int range_type*/
            NULL, /* HOBJECT param_range_msb,  expression */
            NULL, /* HOBJECT param_range_lsb,  expression */
            $4.key, /* const char * name, */
            $4.obj /* HOBJECT expr */
        );
681 682 683 684
    }
  ;


685 686 687
/* 
A.1.4 Module Items 
*/
饶先宏's avatar
饶先宏 已提交
688

饶先宏's avatar
饶先宏 已提交
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
port_declaration_list :
    inout_declaration {
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
    lastport = $1;
    }
|   input_declaration {
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
    lastport = $1;
    }
|   output_declaration {
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
    lastport = $1;
    }
|   port_declaration_list ',' port_ident {
    $$ = $1;
707 708 709
    dlistAppendItem($$, verilogparseCreatePort(
            NULL, /* IDListVarPtr attributes, */
            PORT_DIRECT_ASPRE, /* int port_direct, */
饶先宏's avatar
饶先宏 已提交
710
            VAR_TYPE_NONE, /* int port_type, */
711 712 713 714 715 716 717
            0, /* int port_issigned, */
            RANGE_TYPE_NONE, /*int range_type*/
            lastport, /* HOBJECT param_range_msb,  expression */
            NULL, /* HOBJECT param_range_lsb,  expression */
            $3.key, /* const char * name, */
            $3.obj /* HOBJECT expr */
        ));
饶先宏's avatar
饶先宏 已提交
718 719
    }

720
module_item :
饶先宏's avatar
饶先宏 已提交
721
    port_declaration_list {
722 723 724
    }
|   non_port_module_item {
    }
饶先宏's avatar
饶先宏 已提交
725 726
 ;

727
module_or_generate_item :
饶先宏's avatar
饶先宏 已提交
728
  module_or_generate_item_declaration {
饶先宏's avatar
饶先宏 已提交
729
  }
730
| attribute_instance_list local_parameter_declaration ';' {
饶先宏's avatar
饶先宏 已提交
731
  }
732
| attribute_instance_list parameter_override {
饶先宏's avatar
饶先宏 已提交
733
  }
饶先宏's avatar
饶先宏 已提交
734
| continuous_assign {
饶先宏's avatar
饶先宏 已提交
735
  }
736
| attribute_instance_list gate_instantiation {
饶先宏's avatar
饶先宏 已提交
737
  }
738
| attribute_instance_list udp_instantiation {
饶先宏's avatar
饶先宏 已提交
739
  }
饶先宏's avatar
饶先宏 已提交
740
| module_instantiation {
饶先宏's avatar
饶先宏 已提交
741
  }
742
| attribute_instance_list initial_construct {
饶先宏's avatar
饶先宏 已提交
743
  }
饶先宏's avatar
饶先宏 已提交
744
| always_construct {
745 746 747 748 749 750
  }
| attribute_instance_list loop_generate_construct {
  }
| attribute_instance_list conditional_generate_construct {
  }
  ;
饶先宏's avatar
饶先宏 已提交
751

752
module_or_generate_item_declaration :
饶先宏's avatar
饶先宏 已提交
753
  net_declaration {
754
    }
饶先宏's avatar
饶先宏 已提交
755
|  attribute_instance_list reg_declaration {
756
    }
饶先宏's avatar
饶先宏 已提交
757
|  attribute_instance_list integer_declaration {
758
    }
饶先宏's avatar
饶先宏 已提交
759
| attribute_instance_list real_declaration {
760
    }
饶先宏's avatar
饶先宏 已提交
761
| attribute_instance_list time_declaration {
762
    }
饶先宏's avatar
饶先宏 已提交
763
| attribute_instance_list realtime_declaration {
764
    }
饶先宏's avatar
饶先宏 已提交
765
| attribute_instance_list event_declaration {
766
    }
饶先宏's avatar
饶先宏 已提交
767
| attribute_instance_list genvar_declaration {
768
    }
饶先宏's avatar
饶先宏 已提交
769
| attribute_instance_list task_declaration {
770
    }
饶先宏's avatar
饶先宏 已提交
771
| attribute_instance_list function_declaration {
772
    }
饶先宏's avatar
饶先宏 已提交
773 774
 ;

775 776 777 778 779
non_port_module_item :
    module_or_generate_item {
    }
|   generate_region {
    }
饶先宏's avatar
饶先宏 已提交
780
|   specify_block {
781 782 783 784 785 786
    }
|   attribute_instance_list parameter_declaration ';' {
    }
|   attribute_instance_list specparam_declaration {
    }
   ;
饶先宏's avatar
饶先宏 已提交
787

788
parameter_override :
饶先宏's avatar
饶先宏 已提交
789
    KW_DEFPARAM list_of_defparam_assignments ';' {
790 791
    }
    ;
饶先宏's avatar
饶先宏 已提交
792

793 794 795 796
/*
A.1.5 Configuration source text
*/
config_declaration :
饶先宏's avatar
饶先宏 已提交
797 798
    KW_CONFIG config_identifier ';' 
    design_statement KW_ENDCONFIG {
799
    }
饶先宏's avatar
饶先宏 已提交
800 801
|   KW_CONFIG config_identifier ';' 
    design_statement config_rule_statement KW_ENDCONFIG {
802 803
    }
 ;
饶先宏's avatar
饶先宏 已提交
804

805 806 807
design_statement : 
    KW_DESIGN design_cell_list ';' {
    }
808
;
饶先宏's avatar
饶先宏 已提交
809

810
design_cell_list :
811
   %empty   {
饶先宏's avatar
饶先宏 已提交
812
  }
813 814 815 816 817 818 819 820
|  design_cell_list design_cell {
  } 
|  design_cell {
 }
 ;
 
design_cell :
  cell_identifier {
饶先宏's avatar
饶先宏 已提交
821
  }
822
| library_identifier '.' cell_identifier {
饶先宏's avatar
饶先宏 已提交
823
  }
824
  ;
饶先宏's avatar
饶先宏 已提交
825

826 827 828 829 830 831 832 833 834 835 836 837 838 839
config_rule_statement :
    default_clause liblist_clause ';' {
    }
|   inst_clause liblist_clause ';' {
    }
|   inst_clause use_clause ';' {
    }
|   cell_clause liblist_clause ';' {
    }
|   cell_clause use_clause ';' {
    }
 ;

default_clause :
饶先宏's avatar
饶先宏 已提交
840
  KW_DEFAULT {
饶先宏's avatar
饶先宏 已提交
841
  }
842 843 844
  ;

inst_clause :
饶先宏's avatar
饶先宏 已提交
845
    KW_INSTANCE inst_name {
846 847 848 849
    }
  ;

inst_name :
饶先宏's avatar
饶先宏 已提交
850 851 852 853
    topmodule_identifier {
    }
|   inst_name '.' instance_identifier {
    }
854
  ;
饶先宏's avatar
饶先宏 已提交
855

856
cell_clause : 
饶先宏's avatar
饶先宏 已提交
857
    KW_CELL cell_identifier {
858
    }
饶先宏's avatar
饶先宏 已提交
859
|   KW_CELL library_identifier '.' cell_identifier {
860 861
    }
 ;
饶先宏's avatar
饶先宏 已提交
862

863
liblist_clause :
饶先宏's avatar
饶先宏 已提交
864
    KW_LIBLIST {
865
    }
饶先宏's avatar
饶先宏 已提交
866
|   KW_LIBLIST library_identifier {
867 868
    }
 ;
饶先宏's avatar
饶先宏 已提交
869

870
use_clause :
饶先宏's avatar
饶先宏 已提交
871
    KW_USE cell_identifier {
872
    }
饶先宏's avatar
饶先宏 已提交
873
|   KW_USE cell_identifier ':' KW_CONFIG {
874
    }
饶先宏's avatar
饶先宏 已提交
875
|   KW_USE library_identifier '.' cell_identifier {
876
    }
饶先宏's avatar
饶先宏 已提交
877
|   KW_USE library_identifier '.' cell_identifier ':' KW_CONFIG {
878 879
    }
  ;
饶先宏's avatar
饶先宏 已提交
880

881 882 883 884 885
/*
A.2 Declarations
A.2.1 Declaration types
A.2.1.1 Module parameter declarations
*/
饶先宏's avatar
饶先宏 已提交
886

887
signed_option: 
888
   %empty  {
饶先宏's avatar
饶先宏 已提交
889
   $$ = 0;
890 891
 }
| KW_SIGNED {
饶先宏's avatar
饶先宏 已提交
892
   $$ = 1;
893
}
饶先宏's avatar
饶先宏 已提交
894 895
;

896
range_option: 
897
   %empty  {
饶先宏's avatar
饶先宏 已提交
898
  $$.type = RANGE_TYPE_NONE;
饶先宏's avatar
饶先宏 已提交
899 900
  $$.obj[0] = NULL;
  $$.obj[1] = NULL;
901 902
 }
| range {
饶先宏's avatar
饶先宏 已提交
903
 $$ = $1;
904
}
饶先宏's avatar
饶先宏 已提交
905 906
;

907
local_parameter_declaration :
饶先宏's avatar
饶先宏 已提交
908
    KW_LOCALPARAM signed_option range_option list_of_param_assignments {
909
    }
饶先宏's avatar
饶先宏 已提交
910
|   KW_LOCALPARAM parameter_type list_of_param_assignments{
911 912
    }
 ;
饶先宏's avatar
饶先宏 已提交
913

饶先宏's avatar
饶先宏 已提交
914 915
/*
  因不满足LALR(1)而修改。
916
parameter_declaration :
饶先宏's avatar
饶先宏 已提交
917
    KW_PARAMETER signed_option range_option list_of_param_assignments {
918
    }
饶先宏's avatar
饶先宏 已提交
919
|   KW_PARAMETER parameter_type list_of_param_assignments {
饶先宏's avatar
饶先宏 已提交
920 921 922 923 924 925 926
    }
;
*/

parameter_declaration :
    KW_PARAMETER signed_option range_option param_assignment {
        $$ = verilogparseCreateParameter(PARAM_TYPE_PARAM, PARAM_DATA_TYPE_INTEGER, 
饶先宏's avatar
饶先宏 已提交
927 928
                $2, 
                $3.type, $3.obj[0], $3.obj[1], 
饶先宏's avatar
饶先宏 已提交
929
                $4.key, $4.obj);
饶先宏's avatar
饶先宏 已提交
930
        lastparameter = $$;
饶先宏's avatar
饶先宏 已提交
931 932 933
    }
|   KW_PARAMETER parameter_type param_assignment {
        $$ = verilogparseCreateParameter(PARAM_TYPE_PARAM, $2, 
饶先宏's avatar
饶先宏 已提交
934 935
                0, 
                RANGE_TYPE_NONE, NULL, NULL, 
饶先宏's avatar
饶先宏 已提交
936
                $3.key, $3.obj);
饶先宏's avatar
饶先宏 已提交
937
        lastparameter = $$;
饶先宏's avatar
饶先宏 已提交
938 939 940
    }
|   param_assignment {
        $$ = verilogparseCreateParameter(PARAM_TYPE_ASPRE, 0, 
饶先宏's avatar
饶先宏 已提交
941
                0, 
饶先宏's avatar
饶先宏 已提交
942
                RANGE_TYPE_NONE, lastparameter, NULL, 
饶先宏's avatar
饶先宏 已提交
943
                $1.key, $1.obj);
944
    }
饶先宏's avatar
饶先宏 已提交
945 946
;

饶先宏's avatar
饶先宏 已提交
947

948
specparam_declaration : 
饶先宏's avatar
饶先宏 已提交
949
    KW_SPECPARAM range_option list_of_specparam_assignments ';' {
950 951
    }
   ;
饶先宏's avatar
饶先宏 已提交
952

953
parameter_type :
饶先宏's avatar
饶先宏 已提交
954
    KW_INTEGER {
饶先宏's avatar
饶先宏 已提交
955
    $$ = PARAM_DATA_TYPE_INTEGER;
956
    }
饶先宏's avatar
饶先宏 已提交
957
|   KW_REAL {
饶先宏's avatar
饶先宏 已提交
958
    $$ = PARAM_DATA_TYPE_REAL;
959
    } 
饶先宏's avatar
饶先宏 已提交
960
|   KW_REALTIME {
饶先宏's avatar
饶先宏 已提交
961
    $$ = PARAM_DATA_TYPE_REALTIME;
962
    }
饶先宏's avatar
饶先宏 已提交
963
|   KW_TIME {
饶先宏's avatar
饶先宏 已提交
964
    $$ = PARAM_DATA_TYPE_TIME;
965 966
    }
 ;
饶先宏's avatar
饶先宏 已提交
967

968 969 970
/*
A.2.1.2 Port declarations
*/
饶先宏's avatar
饶先宏 已提交
971

972
net_type_option :
973
   %empty   {
饶先宏's avatar
饶先宏 已提交
974
   $$ = VAR_TYPE_NONE;
饶先宏's avatar
饶先宏 已提交
975
  }
976
| net_type {
饶先宏's avatar
饶先宏 已提交
977
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
978 979 980
  }
;

981
/*
982
inout_declaration :
饶先宏's avatar
饶先宏 已提交
983
    KW_INOUT net_type_option signed_option range_option 
984 985 986
    list_of_port_identifiers {
    }
  ;
饶先宏's avatar
饶先宏 已提交
987

988
input_declaration :
饶先宏's avatar
饶先宏 已提交
989
    KW_INPUT net_type_option signed_option range_option 
990 991 992
    list_of_port_identifiers {
    }
  ;
饶先宏's avatar
饶先宏 已提交
993

994
output_declaration :
饶先宏's avatar
饶先宏 已提交
995
    KW_OUTPUT net_type_option signed_option range_option 
996 997
    list_of_port_identifiers {
    }
饶先宏's avatar
饶先宏 已提交
998
|   KW_OUTPUT KW_REG signed_option range_option
999 1000
    list_of_variable_port_identifiers {
    }
饶先宏's avatar
饶先宏 已提交
1001
|   KW_OUTPUT output_variable_type 
1002 1003 1004
    list_of_variable_port_identifiers {
    }
  ;
1005 1006
*/

饶先宏's avatar
饶先宏 已提交
1007

1008 1009 1010 1011
/*
A.2.1.3 Type declarations
*/
event_declaration :
饶先宏's avatar
饶先宏 已提交
1012
    KW_EVENT list_of_event_identifiers ';' {
1013 1014
    }
 ;
饶先宏's avatar
饶先宏 已提交
1015

饶先宏's avatar
饶先宏 已提交
1016
integer_declaration : KW_INTEGER list_of_variable_identifiers ';' {
1017 1018 1019
    }
  ;
delay3_option: 
1020
    %empty {
1021 1022
    }
|   delay3 {
饶先宏's avatar
饶先宏 已提交
1023

1024 1025
    }
  ;
饶先宏's avatar
饶先宏 已提交
1026

1027
drive_strength_option :
1028
    %empty    {
1029 1030 1031 1032
    }
|   drive_strength {
    }
  ;
饶先宏's avatar
饶先宏 已提交
1033

1034
vectored_option :
1035
    %empty    {
饶先宏's avatar
饶先宏 已提交
1036
    $$ = VS_NONE;
1037
    }
饶先宏's avatar
饶先宏 已提交
1038
|   KW_VECTORED {
饶先宏's avatar
饶先宏 已提交
1039
    $$ = VS_VECTORED;
1040 1041
    }
  ;
饶先宏's avatar
饶先宏 已提交
1042

1043
scalared_option :
1044
   %empty     {
饶先宏's avatar
饶先宏 已提交
1045
   $$ = VS_NONE;
1046
    }
饶先宏's avatar
饶先宏 已提交
1047
|   KW_SCALARED {
饶先宏's avatar
饶先宏 已提交
1048
    $$ = VS_SCALARED;
1049 1050
    }
 ;
饶先宏's avatar
饶先宏 已提交
1051

1052
charge_strength_option :
1053
    %empty    {
1054 1055 1056
    }
|   charge_strength {
    }
饶先宏's avatar
饶先宏 已提交
1057 1058
 ;

1059
vectored_or_scalared_option : 
1060
    %empty    {
饶先宏's avatar
饶先宏 已提交
1061
    $$ = VS_NONE;
1062
    } 
饶先宏's avatar
饶先宏 已提交
1063
|   KW_VECTORED {
饶先宏's avatar
饶先宏 已提交
1064
    $$ = VS_VECTORED;
1065
    }
饶先宏's avatar
饶先宏 已提交
1066
|   KW_SCALARED {
饶先宏's avatar
饶先宏 已提交
1067
    $$ = VS_SCALARED;
1068 1069
    }
 ;
饶先宏's avatar
饶先宏 已提交
1070

饶先宏's avatar
饶先宏 已提交
1071 1072 1073 1074 1075 1076 1077 1078 1079
list_of_net :
    list_of_net_identifiers {
        $$ = $1;
    }
|   list_of_net_decl_assignments {
        $$ = $1;
    }
  ;

1080
net_declaration :
饶先宏's avatar
饶先宏 已提交
1081
/*    attribute_instance_list net_type signed_option
1082 1083
    delay3_option list_of_net_identifiers ';' {
    }
饶先宏's avatar
饶先宏 已提交
1084
|   attribute_instance_list net_type drive_strength_option signed_option
1085 1086
    delay3_option list_of_net_decl_assignments ';' {
    }
饶先宏's avatar
饶先宏 已提交
1087 1088
|*/
    attribute_instance_list net_type drive_strength_option vectored_or_scalared_option signed_option
饶先宏's avatar
饶先宏 已提交
1089
    range_option delay3_option list_of_net ';' {
饶先宏's avatar
饶先宏 已提交
1090 1091 1092 1093
        if (currentmodule == NULL) {
            yyerror("no current module");
        } else {
            IDListVar* list;
饶先宏's avatar
饶先宏 已提交
1094
            IDListVarPtr pitem, pitemtemp;
饶先宏's avatar
饶先宏 已提交
1095
            list = dlistCreate();
饶先宏's avatar
饶先宏 已提交
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
	        pitem = $8->__dlist_pNext; 
	        while (!IsDListHeader(pitem)) {
		        pitemtemp = pitem->__dlist_pNext;
                dlistDetach(pitem);               
                verilogparseVarDeclSetOptions(pitem, 
                    $2,  //int type,
                    $1,  //IDListVar* attributes,
                    $4,  //int vectored_or_scalared,
                    $5, //int issigned,
                    $6.type, //int range_type,
                    $6.obj[0], //HOBJECT range_msb,
饶先宏's avatar
饶先宏 已提交
1107
                    $6.obj[1] //HOBJECT range_lsb
饶先宏's avatar
饶先宏 已提交
1108 1109 1110 1111 1112
                    );
                dlistAppendItem(list, pitem);
		        pitem = pitemtemp;
	        }
            objectRelease($8);
饶先宏's avatar
饶先宏 已提交
1113 1114
            verilogparseAddModuleItems(currentmodule, list, MODULE_ITEM_TYPE_NET_DECLARATION);
        }
1115
    }
饶先宏's avatar
饶先宏 已提交
1116 1117
/*
|   attribute_instance_list net_type scalared_option signed_option
1118 1119
    range delay3_option list_of_net_identifiers ';' {
    }
饶先宏's avatar
饶先宏 已提交
1120 1121

|   attribute_instance_list net_type drive_strength_option vectored_option 
1122 1123 1124
    scalared_option signed_option
    range delay3_option list_of_net_decl_assignments ';' {
    }
饶先宏's avatar
饶先宏 已提交
1125 1126
*/
|   attribute_instance_list KW_TRIREG charge_strength_option signed_option
1127
    delay3_option list_of_net_identifiers ';'
饶先宏's avatar
饶先宏 已提交
1128
|   attribute_instance_list KW_TRIREG drive_strength_option signed_option
1129 1130
    delay3_option list_of_net_decl_assignments ';' {
    }
饶先宏's avatar
饶先宏 已提交
1131
|   attribute_instance_list KW_TRIREG charge_strength_option vectored_or_scalared_option signed_option
1132 1133
    range delay3_option list_of_net_identifiers ';' {
    }
饶先宏's avatar
饶先宏 已提交
1134
|   attribute_instance_list KW_TRIREG drive_strength_option vectored_or_scalared_option signed_option
1135 1136 1137
    range delay3_option list_of_net_decl_assignments ';' {
    }
 ;
饶先宏's avatar
饶先宏 已提交
1138

1139
real_declaration :
饶先宏's avatar
饶先宏 已提交
1140
    KW_REAL list_of_real_identifiers ';' {
1141 1142
    }
  ;
饶先宏's avatar
饶先宏 已提交
1143

1144
realtime_declaration : 
饶先宏's avatar
饶先宏 已提交
1145
    KW_REALTIME list_of_real_identifiers ';' {
1146 1147
    }
  ;
饶先宏's avatar
饶先宏 已提交
1148

1149
reg_declaration :
饶先宏's avatar
饶先宏 已提交
1150
    KW_REG signed_option range_option
1151 1152 1153
    list_of_variable_identifiers ';' {
    }
  ;
饶先宏's avatar
饶先宏 已提交
1154

1155
time_declaration : 
饶先宏's avatar
饶先宏 已提交
1156
    KW_TIME list_of_variable_identifiers ';' {
1157 1158
    }
  ;
饶先宏's avatar
饶先宏 已提交
1159

1160 1161 1162 1163 1164
/*
A.2.2 Declaration data types
A.2.2.1 Net and variable types
*/
net_type :
饶先宏's avatar
饶先宏 已提交
1165
    KW_SUPPLY0 {
饶先宏's avatar
饶先宏 已提交
1166
    $$ = VAR_TYPE_SUPPLY0;
1167
    }
饶先宏's avatar
饶先宏 已提交
1168
|   KW_SUPPLY1 {
饶先宏's avatar
饶先宏 已提交
1169
    $$ = VAR_TYPE_SUPPLY1;
1170
    }
饶先宏's avatar
饶先宏 已提交
1171
|   KW_TRI {
饶先宏's avatar
饶先宏 已提交
1172
    $$ = VAR_TYPE_TRI;
1173
    } 
饶先宏's avatar
饶先宏 已提交
1174
|   KW_TRIAND  {
饶先宏's avatar
饶先宏 已提交
1175
    $$ = VAR_TYPE_TRIAND;
1176
    }
饶先宏's avatar
饶先宏 已提交
1177
|   KW_TRIOR  {
饶先宏's avatar
饶先宏 已提交
1178
    $$ = VAR_TYPE_TRIOR;
1179
    }
饶先宏's avatar
饶先宏 已提交
1180
|   KW_TRI0  {
饶先宏's avatar
饶先宏 已提交
1181
    $$ = VAR_TYPE_TRI0;
1182
    }
饶先宏's avatar
饶先宏 已提交
1183
|   KW_TRI1 {
饶先宏's avatar
饶先宏 已提交
1184
    $$ = VAR_TYPE_TRI1;
1185
    }
饶先宏's avatar
饶先宏 已提交
1186
|   KW_UWIRE  {
饶先宏's avatar
饶先宏 已提交
1187
    $$ = VAR_TYPE_UWIRE;
1188
    }
饶先宏's avatar
饶先宏 已提交
1189
|   KW_WIRE  {
饶先宏's avatar
饶先宏 已提交
1190
    $$ = VAR_TYPE_WIRE;
1191
    }
饶先宏's avatar
饶先宏 已提交
1192
|   KW_WAND  {
饶先宏's avatar
饶先宏 已提交
1193
    $$ = VAR_TYPE_WAND;
1194
    }
饶先宏's avatar
饶先宏 已提交
1195
|   KW_WOR {
饶先宏's avatar
饶先宏 已提交
1196
    $$ = VAR_TYPE_WOR;
1197 1198
    }
  ;
饶先宏's avatar
饶先宏 已提交
1199

1200
output_variable_type : 
饶先宏's avatar
饶先宏 已提交
1201
    KW_INTEGER  {
饶先宏's avatar
饶先宏 已提交
1202
    $$ = VAR_TYPE_INTEGER;
1203
    }
饶先宏's avatar
饶先宏 已提交
1204
|   KW_TIME {
饶先宏's avatar
饶先宏 已提交
1205
    $$ = VAR_TYPE_TIME;
1206 1207
    }
 ;
饶先宏's avatar
饶先宏 已提交
1208

1209
dimension_list :
1210
     %empty   {
饶先宏's avatar
饶先宏 已提交
1211
     $$ = dlistCreate();
1212 1213
    }
| dimension_list dimension {
饶先宏's avatar
饶先宏 已提交
1214 1215 1216
     $$ = $1;
     dlistAppendItem($$, $2.obj[0]);
     dlistAppendItem($$, $2.obj[1]);
1217 1218
    }
| dimension {
饶先宏's avatar
饶先宏 已提交
1219 1220 1221
     $$ = dlistCreate();
     dlistAppendItem($$, $1.obj[0]);
     dlistAppendItem($$, $1.obj[1]);
饶先宏's avatar
饶先宏 已提交
1222 1223 1224
}
;

1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
real_type :
    real_identifier dimension_list {
    }
|   real_identifier '=' constant_expression {
    }
 ;
variable_type :
    variable_identifier dimension_list {
    }
|   variable_identifier '=' constant_expression {
    }
 ;
 
/*
A.2.2.2 Strengths 
*/
饶先宏's avatar
饶先宏 已提交
1241

1242 1243 1244 1245 1246
drive_strength :
    '(' strength0 ',' strength1 ')' {
    }
|   '(' strength1 ',' strength0 ')' {
    }
饶先宏's avatar
饶先宏 已提交
1247
|   '(' strength0 ',' KW_HIGHZ1 ')' {
1248
    }
饶先宏's avatar
饶先宏 已提交
1249
|   '(' strength1 ',' KW_HIGHZ0 ')' {
1250
    }
饶先宏's avatar
饶先宏 已提交
1251
|   '(' KW_HIGHZ0 ',' strength1 ')' {
1252
    }
饶先宏's avatar
饶先宏 已提交
1253
|   '(' KW_HIGHZ1 ',' strength0 ')' {
1254 1255 1256
    }
  ;
strength0 : 
饶先宏's avatar
饶先宏 已提交
1257
    KW_SUPPLY0  {
1258
    }
饶先宏's avatar
饶先宏 已提交
1259
|   KW_STRONG0  {
1260
    }
饶先宏's avatar
饶先宏 已提交
1261
|   KW_PULL0  {
1262
    }
饶先宏's avatar
饶先宏 已提交
1263
|   KW_WEAK0 {
1264 1265
    }
 ;
饶先宏's avatar
饶先宏 已提交
1266

1267
strength1 : 
饶先宏's avatar
饶先宏 已提交
1268
    KW_SUPPLY1  {
1269
    }
饶先宏's avatar
饶先宏 已提交
1270
|   KW_STRONG1  {
1271
    }
饶先宏's avatar
饶先宏 已提交
1272
|   KW_PULL1  {
1273
    }
饶先宏's avatar
饶先宏 已提交
1274
|   KW_WEAK1 {
1275 1276
    }
  ;
饶先宏's avatar
饶先宏 已提交
1277

1278
charge_strength : 
饶先宏's avatar
饶先宏 已提交
1279
    '(' KW_SMALL ')' {
1280
    } 
饶先宏's avatar
饶先宏 已提交
1281
|   '(' KW_MEDIUM ')'  {
1282
    }
饶先宏's avatar
饶先宏 已提交
1283
|   '(' KW_LARGE ')' {
1284 1285
    }
 ;
饶先宏's avatar
饶先宏 已提交
1286

1287 1288 1289
/*
A.2.2.3 Delays
*/
饶先宏's avatar
饶先宏 已提交
1290

1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
delay3 :
    '#' delay_value {
    }
|   '#' '(' mintypmax_expression ')' {
    }
|   '#' '(' mintypmax_expression ',' mintypmax_expression ')' {
    }
|   '#' '(' mintypmax_expression ',' mintypmax_expression ',' mintypmax_expression ')' {
    }
 ;
饶先宏's avatar
饶先宏 已提交
1301

1302
delay2 :
饶先宏's avatar
饶先宏 已提交
1303 1304
    '#' delay_value {
    }
1305 1306 1307 1308 1309
|   '#' '(' mintypmax_expression ')' {
    }
|   '#' '(' mintypmax_expression ',' mintypmax_expression ')' {
    }
 ;
饶先宏's avatar
饶先宏 已提交
1310

1311 1312 1313
delay_value :
    unsigned_number {
    }
饶先宏's avatar
饶先宏 已提交
1314
|   NUM_REAL {
1315 1316 1317
    }
|   identifier {
    }
饶先宏's avatar
饶先宏 已提交
1318 1319
 ;

1320 1321 1322 1323 1324 1325 1326 1327 1328
/*
A.2.3 Declaration lists
*/
list_of_defparam_assignments :
    defparam_assignment {
    }
|   list_of_defparam_assignments  ',' defparam_assignment {
    }
 ;
饶先宏's avatar
饶先宏 已提交
1329

1330 1331 1332 1333 1334 1335
list_of_dimensions:
    dimension {
    }
|   list_of_dimensions  ',' dimension {
    }
 ;
饶先宏's avatar
饶先宏 已提交
1336

1337 1338 1339 1340 1341 1342
list_of_event_identifiers : 
    event_identifier list_of_dimensions {
    }
|   list_of_event_identifiers ',' event_identifier list_of_dimensions {
    }
  ;
饶先宏's avatar
饶先宏 已提交
1343

1344 1345
list_of_net_decl_assignments :
    net_decl_assignment {
饶先宏's avatar
饶先宏 已提交
1346 1347
    HOBJECT vardecl;
    vardecl = verilogparseCreateVarDecl($1.key);
饶先宏's avatar
饶先宏 已提交
1348
    objectRelease($1.key);
饶先宏's avatar
饶先宏 已提交
1349 1350 1351 1352
    verilogparseVarDeclSetAssignExpr(vardecl, $1.obj);
    objectRelease($1.obj);
    $$ = dlistCreate();
    dlistAppendItem($$, vardecl);
1353 1354
    }
|   list_of_net_decl_assignments  ',' net_decl_assignment {
饶先宏's avatar
饶先宏 已提交
1355 1356
    HOBJECT vardecl;
    vardecl = verilogparseCreateVarDecl($3.key);
饶先宏's avatar
饶先宏 已提交
1357
    objectRelease($3.key);
饶先宏's avatar
饶先宏 已提交
1358 1359 1360 1361
    verilogparseVarDeclSetAssignExpr(vardecl, $3.obj);
    objectRelease($3.obj);
    $$ = $1;
    dlistAppendItem($$, vardecl);
1362
    }
饶先宏's avatar
饶先宏 已提交
1363
 ;
饶先宏's avatar
饶先宏 已提交
1364 1365 1366

list_of_net_identifiers : 
    net_identifier dimension_list {
饶先宏's avatar
饶先宏 已提交
1367 1368 1369 1370
    HOBJECT vardecl;
    $$ = dlistCreate();
    dlistAppendItem($$, vardecl = verilogparseCreateVarDecl($1));
    verilogparseVarDeclSetDimensions(vardecl, $2);
饶先宏's avatar
饶先宏 已提交
1371
    objectRelease($1);
饶先宏's avatar
饶先宏 已提交
1372 1373
    }
|   list_of_net_identifiers  ',' net_identifier dimension_list {
饶先宏's avatar
饶先宏 已提交
1374 1375 1376 1377 1378
    HOBJECT vardecl;
    $$ = $1;
    dlistAppendItem($$, vardecl = verilogparseCreateVarDecl($3));
    verilogparseVarDeclSetDimensions(vardecl, $4);
    objectRelease($4);
饶先宏's avatar
饶先宏 已提交
1379
    objectRelease($3);
饶先宏's avatar
饶先宏 已提交
1380 1381 1382
    }
  ;

1383 1384 1385 1386 1387 1388
list_of_event_identifiers : 
    net_identifier list_of_dimensions {
    }
|   list_of_event_identifiers ',' net_identifier list_of_dimensions {
    }
  ;
饶先宏's avatar
饶先宏 已提交
1389

1390 1391
list_of_param_assignments :
    param_assignment {
饶先宏's avatar
饶先宏 已提交
1392
    $$ = NULL;
1393 1394
    }
|   list_of_param_assignments  ',' param_assignment {
饶先宏's avatar
饶先宏 已提交
1395
    $$ = NULL;
1396 1397 1398
    }
 ;
 
1399
 
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
list_of_port_identifiers :
    port_identifier {
    }
|   list_of_port_identifiers  ',' port_identifier {
    }
 ;
 
list_of_real_identifiers :
    real_type {
    }
|   list_of_real_identifiers  ',' real_type {
    }
 ;
 
饶先宏's avatar
饶先宏 已提交
1414

1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430
list_of_specparam_assignments :
    specparam_assignment {
    }
|   list_of_specparam_assignments  ',' specparam_assignment {
    }
 ;
 
list_of_variable_identifiers :
    variable_type {
    }
|   list_of_variable_identifiers  ',' variable_type {
    }
 ;
 
port_ident :
    port_identifier {
饶先宏's avatar
饶先宏 已提交
1431 1432
    $$.key = $1;
    $$.obj = NULL;
1433 1434
    }
|   port_identifier '=' constant_expression {
饶先宏's avatar
饶先宏 已提交
1435 1436
    $$.key = $1;
    $$.obj = $3;
1437 1438
    }
 ;
饶先宏's avatar
饶先宏 已提交
1439

1440 1441 1442 1443 1444 1445
list_of_variable_port_identifiers :
    port_ident {
    }
|   list_of_variable_port_identifiers  ',' port_ident {
    }
 ;
饶先宏's avatar
饶先宏 已提交
1446

1447 1448 1449
/*
A.2.4 Declaration assignments
*/
饶先宏's avatar
饶先宏 已提交
1450

1451 1452 1453 1454
defparam_assignment : 
    hierarchical_parameter_identifier '=' constant_mintypmax_expression {
    }
  ;
饶先宏's avatar
饶先宏 已提交
1455

1456 1457
net_decl_assignment : 
    net_identifier '=' expression {
饶先宏's avatar
饶先宏 已提交
1458 1459
    $$.key = $1;
    $$.obj = $3;
1460
    }
饶先宏's avatar
饶先宏 已提交
1461
|   net_identifier {
饶先宏's avatar
饶先宏 已提交
1462 1463
    $$.key = $1;
    $$.obj = NULL;
饶先宏's avatar
饶先宏 已提交
1464
    }
1465
  ;
饶先宏's avatar
饶先宏 已提交
1466

1467 1468
param_assignment : 
    parameter_identifier '=' constant_mintypmax_expression {
饶先宏's avatar
饶先宏 已提交
1469 1470
    $$.key = $1;
    $$.obj = $3;
1471 1472
    }
  ;
饶先宏's avatar
饶先宏 已提交
1473

1474 1475 1476 1477 1478
specparam_assignment :
    specparam_identifier '=' constant_mintypmax_expression {
    }
|    pulse_control_specparam {
    }
饶先宏's avatar
饶先宏 已提交
1479 1480
 ;

饶先宏's avatar
饶先宏 已提交
1481 1482 1483 1484 1485 1486 1487 1488
/* 
    PATHPULSE$specify_input_terminal_descriptor$specify_output_terminal_descriptor 
    must be:
    1.PATHPULSE$identinput$identoutput
    1.PATHPULSE$identinput$identoutput '[' constant_range_expression ']'
    1.PATHPULSE$identinput '[' constant_range_expression ']' $identoutput
    1.PATHPULSE$identinput '[' constant_range_expression ']' $identoutput '[' constant_range_expression ']'
*/
饶先宏's avatar
饶先宏 已提交
1489

饶先宏's avatar
饶先宏 已提交
1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508
pulse_control_specparam_lvalue :
    SIMPLE_ID /* PATHPULSE$identinput$identoutput */ {
    }
|   SIMPLE_ID /* PATHPULSE$identinput$identoutput  '[' constant_range_expression ']' */
    '[' constant_range_expression ']'  {
    }
|   SIMPLE_ID /* PATHPULSE$identinput '[' constant_range_expression ']' $identoutput*/
    '[' constant_range_expression ']' 
    SYSTEM_ID {
    }
|   SIMPLE_ID /* PATHPULSE$identinput '[' constant_range_expression ']'  $identoutput '[' constant_range_expression ']'*/
    '[' constant_range_expression ']' 
    SYSTEM_ID
    '[' constant_range_expression ']' {
    }
  ;
    
pulse_control_specparam : 
    KW_PATHPULSE '=' '(' reject_limit_value ')' {
1509
    }
饶先宏's avatar
饶先宏 已提交
1510
|   KW_PATHPULSE '=' '(' reject_limit_value ',' error_limit_value ')' {
1511
    }
饶先宏's avatar
饶先宏 已提交
1512
|   pulse_control_specparam_lvalue
1513 1514
    '=' '(' reject_limit_value ')' {
    }
饶先宏's avatar
饶先宏 已提交
1515 1516
|   pulse_control_specparam_lvalue
     '=' '(' reject_limit_value ',' error_limit_value ')' {
1517
    }
饶先宏's avatar
饶先宏 已提交
1518 1519
  ;

饶先宏's avatar
饶先宏 已提交
1520

1521 1522 1523 1524
error_limit_value : 
    limit_value {
    }
  ;
饶先宏's avatar
饶先宏 已提交
1525

1526 1527 1528 1529
reject_limit_value : 
    limit_value {
    }
  ;
饶先宏's avatar
饶先宏 已提交
1530

1531 1532 1533 1534
limit_value : 
    constant_mintypmax_expression {
    }
 ;
饶先宏's avatar
饶先宏 已提交
1535

1536 1537 1538 1539 1540
/*
A.2.5 Declaration ranges
*/
dimension : 
    '[' dimension_constant_expression ':' dimension_constant_expression ']' {
饶先宏's avatar
饶先宏 已提交
1541 1542
        $$.obj[0] = $2;
        $$.obj[1] = $4;
1543 1544
    }
 ;
饶先宏's avatar
饶先宏 已提交
1545

1546
range : '[' msb_constant_expression ':' lsb_constant_expression ']' {
饶先宏's avatar
饶先宏 已提交
1547
      $$.type = RANGE_TYPE_PARTSELECT;
1548 1549
      $$.obj[0] = $2;
      $$.obj[1] = $4;
1550 1551
    }
  ;
饶先宏's avatar
饶先宏 已提交
1552

1553 1554 1555 1556
/*
A.2.6 Function declarations
*/
automatic_option :
1557
     %empty   {
1558
    }
饶先宏's avatar
饶先宏 已提交
1559
|   KW_AUTOMATIC { 
1560 1561
    }
  ;
饶先宏's avatar
饶先宏 已提交
1562

1563
function_range_or_type_option:
1564
     %empty   {
1565 1566 1567 1568
    }
|   function_range_or_type {
    }
  ;
饶先宏's avatar
饶先宏 已提交
1569

1570 1571 1572 1573 1574 1575
function_item_declaration_list:
    function_item_declaration {
    }
|   function_item_declaration_list function_item_declaration {
    }
 ;
饶先宏's avatar
饶先宏 已提交
1576

1577
block_item_declaration_list:
1578
    %empty    {
1579 1580 1581 1582 1583 1584
    }
|   block_item_declaration {
    }
|   block_item_declaration_list block_item_declaration {
    }
 ;
饶先宏's avatar
饶先宏 已提交
1585

饶先宏's avatar
饶先宏 已提交
1586
function_range_or_type_option :
1587
     %empty   {
饶先宏's avatar
饶先宏 已提交
1588 1589 1590 1591 1592
    }
|   function_range_or_type {
    }
  ;

1593
function_declaration :
饶先宏's avatar
饶先宏 已提交
1594
    KW_FUNCTION automatic_option function_range_or_type_option function_identifier ';'
1595 1596
    function_item_declaration_list
    function_statement
饶先宏's avatar
饶先宏 已提交
1597
    KW_ENDFUNCTION {
1598
    }
饶先宏's avatar
饶先宏 已提交
1599
|   KW_FUNCTION automatic_option function_range_or_type_option function_identifier '(' function_port_list ')' ';'
1600 1601
    block_item_declaration_list   
    function_statement
饶先宏's avatar
饶先宏 已提交
1602
    KW_ENDFUNCTION {
1603 1604
    }
 ;
饶先宏's avatar
饶先宏 已提交
1605

1606 1607
function_item_declaration :
    block_item_declaration
饶先宏's avatar
饶先宏 已提交
1608
|   attribute_instance_list tf_input_declaration ';' {
1609 1610
    }
 ;
饶先宏's avatar
饶先宏 已提交
1611

1612 1613 1614 1615 1616 1617
function_port_list :
    attribute_instance_list tf_input_declaration {
    }
|   function_port_list attribute_instance_list tf_input_declaration {
    }
  ;
饶先宏's avatar
饶先宏 已提交
1618

1619 1620 1621
function_range_or_type :
    signed_option range_option {
    }
饶先宏's avatar
饶先宏 已提交
1622
|   KW_INTEGER {
1623
    }
饶先宏's avatar
饶先宏 已提交
1624
|   KW_REAL {
1625
    }
饶先宏's avatar
饶先宏 已提交
1626
|   KW_REALTIME {
1627
    }
饶先宏's avatar
饶先宏 已提交
1628
| KW_TIME {
1629 1630
    }
  ;
饶先宏's avatar
饶先宏 已提交
1631

1632 1633 1634 1635
/*
A.2.7 Task declarations
*/
task_item_declaration_list :
1636
     %empty   {
1637 1638 1639 1640 1641 1642
    }
|   task_item_declaration_list task_item_declaration {
    }
|   task_item_declaration {
    }
 ;
饶先宏's avatar
饶先宏 已提交
1643

1644
task_port_list_option:
1645
     %empty   {
1646 1647 1648 1649
    }
|   task_port_list {
    }
  ;
饶先宏's avatar
饶先宏 已提交
1650

1651
task_declaration :
饶先宏's avatar
饶先宏 已提交
1652
    KW_TASK automatic_option task_identifier ';'
1653 1654
    task_item_declaration_list
    statement_or_null
饶先宏's avatar
饶先宏 已提交
1655
    KW_ENDTASK {
1656
    }
饶先宏's avatar
饶先宏 已提交
1657
|   KW_TASK automatic_option task_identifier '(' task_port_list_option ')' ';'
1658 1659
    block_item_declaration_list
    statement_or_null
饶先宏's avatar
饶先宏 已提交
1660
    KW_ENDTASK {
1661 1662
    }
 ;
饶先宏's avatar
饶先宏 已提交
1663

1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
task_item_declaration :
    block_item_declaration {
    }
|   attribute_instance_list tf_input_declaration ';' {
    }
|   attribute_instance_list tf_output_declaration ';' {
    }
|   attribute_instance_list tf_inout_declaration ';' {
    }
  ;
饶先宏's avatar
饶先宏 已提交
1674

1675 1676 1677 1678 1679 1680
task_port_list :
    task_port_item {
    }
|   task_port_list ',' task_port_item {
    }
 ;
饶先宏's avatar
饶先宏 已提交
1681

1682 1683 1684 1685 1686 1687 1688 1689
task_port_item :
    attribute_instance_list tf_input_declaration {
    }
|   attribute_instance_list tf_output_declaration {
    }
|   attribute_instance_list tf_inout_declaration {
    }
  ;
饶先宏's avatar
饶先宏 已提交
1690

饶先宏's avatar
饶先宏 已提交
1691
reg_option :
1692
    %empty    {
饶先宏's avatar
饶先宏 已提交
1693 1694 1695 1696 1697
    }
|   KW_REG {
    }
  ;   

1698
tf_input_declaration :
饶先宏's avatar
饶先宏 已提交
1699
    KW_INPUT reg_option signed_option range_option list_of_port_identifiers {
1700
    }
饶先宏's avatar
饶先宏 已提交
1701
|   KW_INPUT task_port_type list_of_port_identifiers {
1702 1703
    }
  ;
饶先宏's avatar
饶先宏 已提交
1704

1705
tf_output_declaration :
饶先宏's avatar
饶先宏 已提交
1706
    KW_OUTPUT reg_option signed_option range_option list_of_port_identifiers {
饶先宏's avatar
饶先宏 已提交
1707
    }
饶先宏's avatar
饶先宏 已提交
1708
|   KW_OUTPUT task_port_type list_of_port_identifiers {
1709 1710
    }
  ;
饶先宏's avatar
饶先宏 已提交
1711

1712
tf_inout_declaration :
饶先宏's avatar
饶先宏 已提交
1713
    KW_INOUT reg_option signed_option range_option list_of_port_identifiers {
1714
    }
饶先宏's avatar
饶先宏 已提交
1715
|   KW_INOUT task_port_type list_of_port_identifiers {
1716 1717
    }
  ;
饶先宏's avatar
饶先宏 已提交
1718

1719
task_port_type :
饶先宏's avatar
饶先宏 已提交
1720
    KW_INTEGER  {
1721
    }
饶先宏's avatar
饶先宏 已提交
1722
|   KW_REAL {
1723
    }
饶先宏's avatar
饶先宏 已提交
1724
|   KW_REALTIME {
1725
    }
饶先宏's avatar
饶先宏 已提交
1726
|   KW_TIME{
1727 1728
    }
  ;
饶先宏's avatar
饶先宏 已提交
1729

1730 1731 1732
/*
A.2.8 Block item declarations
*/
饶先宏's avatar
饶先宏 已提交
1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775
block_item_declaration :
    attribute_instance_list  KW_REG signed_option range_option list_of_block_variable_identifiers ';' {
    }
|   attribute_instance_list  KW_INTEGER list_of_block_variable_identifiers ';' {
    }
|   attribute_instance_list  KW_TIME list_of_block_variable_identifiers ';' {
    }
|   attribute_instance_list  KW_REAL list_of_block_real_identifiers ';' {
    }
|   attribute_instance_list  KW_REALTIME list_of_block_real_identifiers ';' {
    }
|   attribute_instance_list  event_declaration {
    }
|   attribute_instance_list  local_parameter_declaration ';' {
    }
|   attribute_instance_list  parameter_declaration ';' {
    }
  ;

list_of_block_variable_identifiers :
    block_variable_type {
    }
|   list_of_block_variable_identifiers  ',' block_variable_type {
    }
  ;

list_of_block_real_identifiers : 
    block_real_type {
    } 
|   list_of_block_real_identifiers ',' block_real_type {
    }
  ;

block_variable_type : 
    variable_identifier dimension_list {
    }
 ;

block_real_type : 
    real_identifier dimension_list {
    }
  ;

1776 1777 1778 1779
/*
A.3 Primitive instances
A.3.1 Primitive instantiation and instances
*/
饶先宏's avatar
饶先宏 已提交
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830

cmos_switch_instance_list:
    cmos_switch_instance {
    }
|   cmos_switch_instance_list ',' cmos_switch_instance {
    }
  ;

enable_gate_instance_list:
    enable_gate_instance {
    }
|   enable_gate_instance_list ',' enable_gate_instance {
    }
  ;

mos_switch_instance_list:
    mos_switch_instance {
    }
|   mos_switch_instance_list ',' mos_switch_instance {
    }
  ;

n_input_gate_instance_list:
    n_input_gate_instance {
    }
|   n_input_gate_instance_list ',' n_input_gate_instance {
    }
  ;

n_output_gate_instance_list:
    n_output_gate_instance {
    }
|   n_output_gate_instance_list ',' n_output_gate_instance {
    }
  ;

pass_enable_switch_instance_list:
    pass_enable_switch_instance {
    }
|   pass_enable_switch_instance_list ',' pass_enable_switch_instance {
    }
  ;

pass_switch_instance_list:
    pass_switch_instance {
    }
|   pass_switch_instance_list ',' pass_switch_instance {
    }
  ;

pulldown_strength_option :
1831
     %empty   {
饶先宏's avatar
饶先宏 已提交
1832 1833 1834 1835 1836 1837
    }
|   pulldown_strength {
    }
  ;

pullup_strength_option :
1838
     %empty   {
饶先宏's avatar
饶先宏 已提交
1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851
    }
|   pullup_strength {
    }
  ;

pull_gate_instance_list:
    pull_gate_instance {
    }
|   pull_gate_instance_list ',' pull_gate_instance {
    }
  ;

delay2_option :
1852
     %empty   {
饶先宏's avatar
饶先宏 已提交
1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879
    }
|   delay2 {
    }
  ;

gate_instantiation :
    cmos_switchtype delay3_option cmos_switch_instance_list ';' {
    }
|   enable_gatetype drive_strength_option delay3_option enable_gate_instance_list ';' {
    }
|   mos_switchtype delay3_option mos_switch_instance_list ';' {
    }
|   n_input_gatetype drive_strength_option delay2_option n_input_gate_instance_list ';' {
    }
|   n_output_gatetype drive_strength_option delay2_option n_output_gate_instance_list ';' { 
    }
|   pass_en_switchtype delay2_option pass_enable_switch_instance_list ';' {
    }
|   pass_switchtype pass_switch_instance_list ';' {
    }
|   KW_PULLDOWN pulldown_strength_option pull_gate_instance_list ';' {
    }
|   KW_PULLUP pullup_strength_option pull_gate_instance_list ';' {
    }
 ;

name_of_gate_instance_option :
1880
    %empty    {
饶先宏's avatar
饶先宏 已提交
1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945
    }
|   name_of_gate_instance {
    }
  ;


input_terminal_list:
    input_terminal {
    }
|   input_terminal_list ',' input_terminal {
    }
  ;

output_terminal_list:
    output_terminal {
    }
|   output_terminal_list ',' output_terminal {
    }
  ;

cmos_switch_instance : 
    name_of_gate_instance_option '(' output_terminal ',' input_terminal ',' ncontrol_terminal ',' pcontrol_terminal ')' {
    }
 ;

enable_gate_instance : 
    name_of_gate_instance_option '(' output_terminal ',' input_terminal ',' enable_terminal ')' {
    }
  ;

mos_switch_instance : 
    name_of_gate_instance_option '(' output_terminal ',' input_terminal ',' enable_terminal ')' {
    }
  ;

n_input_gate_instance : 
    name_of_gate_instance_option '(' output_terminal ',' input_terminal_list ')' {
    }
  ;

n_output_gate_instance : 
    name_of_gate_instance_option '(' output_terminal_list ',' input_terminal ')' {
    }
  ;

pass_switch_instance : 
    name_of_gate_instance_option '(' inout_terminal ',' inout_terminal ')' {
    }
  ;

pass_enable_switch_instance : 
    name_of_gate_instance_option '(' inout_terminal ',' inout_terminal ',' enable_terminal ')' {
    }
  ;

pull_gate_instance : 
    name_of_gate_instance_option '(' output_terminal ')' {
    }
  ;

name_of_gate_instance : 
    gate_instance_identifier range_option {
    }
  ;

1946 1947 1948
/*
A.3.2 Primitive strengths
*/
饶先宏's avatar
饶先宏 已提交
1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967

pulldown_strength :
    '(' strength0 ',' strength1 ')' {
    }
|   '(' strength1 ',' strength0 ')' {
    }
|   '(' strength0 ')' {
    }
  ;

pullup_strength :
    '(' strength0 ',' strength1 ')' {
    }
|   '(' strength1 ',' strength0 ')' {
    }
|   '(' strength1 ')' {
    }
  ;

1968 1969 1970
/*
A.3.3 Primitive terminals
*/
饶先宏's avatar
饶先宏 已提交
1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000
enable_terminal : 
    expression {
    }
  ;

inout_terminal : 
    net_lvalue {
    }
  ;

input_terminal : 
    expression {
    }
  ;

ncontrol_terminal : 
    expression {
    }
  ;

output_terminal : 
    net_lvalue {
    }
  ;

pcontrol_terminal : 
    expression {
    }
  ;

2001 2002 2003
/*
A.3.4 Primitive gate and switch types
*/
饶先宏's avatar
饶先宏 已提交
2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071
cmos_switchtype : 
    KW_CMOS  {
    }
|   KW_RCMOS {
    }
  ;
enable_gatetype : 
    KW_BUFIF0  {
    }
|   KW_BUFIF1 {
    }
|   KW_NOTIF0  {
    }
|   KW_NOTIF1 {
    }
  ;

mos_switchtype : 
    KW_NMOS  {
    }
|   KW_PMOS  {
    }
|   KW_RNMOS  {
    }
|   KW_RPMOS {
    }
  ;

n_input_gatetype : 
    KW_AND  {
    }
|   KW_NAND  {
    }
|   KW_OR  {
    }
|   KW_NOR  {
    }
|   KW_XOR  {
    }
|   KW_XNOR {
    }
  ;

n_output_gatetype : 
    KW_BUF {
    } 
|   KW_NOT {
    }
  ;

pass_en_switchtype : 
    KW_TRANIF0 {
    }
|   KW_TRANIF1 {
    }
|   KW_RTRANIF1 {
    }
|   KW_RTRANIF0 {
    }
  ;

pass_switchtype : 
    KW_TRAN  {
    }
|   KW_RTRAN {
    }
  ;

2072 2073 2074 2075
/*
A.4 Module instantiation and generate construct
A.4.1 Module instantiation
*/
饶先宏's avatar
饶先宏 已提交
2076
parameter_value_assignment_option :
2077
     %empty   {
饶先宏's avatar
饶先宏 已提交
2078
     $$ = dlistCreate();
饶先宏's avatar
饶先宏 已提交
2079 2080
    }
| parameter_value_assignment {
饶先宏's avatar
饶先宏 已提交
2081
     $$ = $1;
饶先宏's avatar
饶先宏 已提交
2082 2083 2084 2085 2086
    }
 ;

module_instance_list:
    module_instance {
饶先宏's avatar
饶先宏 已提交
2087 2088
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
饶先宏's avatar
饶先宏 已提交
2089 2090
    }
|   module_instance_list ',' module_instance {
饶先宏's avatar
饶先宏 已提交
2091 2092
    $$ = $1;
    dlistAppendItem($$, $3);
饶先宏's avatar
饶先宏 已提交
2093 2094 2095 2096
    }
  ;

module_instantiation :
饶先宏's avatar
饶先宏 已提交
2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112
    attribute_instance_list module_identifier parameter_value_assignment_option module_instance_list ';' {
    	IDListVarPtr pitem, pitemtemp;
	    if (dlistItemCount($4) > 0) {
	        pitem = $4->__dlist_pNext; 
	        while (pitem != $4) {
		        pitemtemp = pitem->__dlist_pNext;
                verilogparseSetModuleInstanceOption(
                    pitem, //HOBJECT inst,
                    $1, //IDListVarPtr attributes,
                    $2, //const char * modulename,
                    $3  //IDListVarPtr parameter_value_assignment
                );
		        pitem = pitemtemp;
	        }
            verilogparseAddModuleItems(currentmodule, $4, MODULE_ITEM_TYPE_MODULE_INSTANCE);
        }
饶先宏's avatar
饶先宏 已提交
2113 2114 2115 2116 2117
    }
 ;

parameter_value_assignment : 
    '#' '(' list_of_parameter_assignments ')' {
饶先宏's avatar
饶先宏 已提交
2118
    $$ = $3;
饶先宏's avatar
饶先宏 已提交
2119 2120 2121 2122 2123
    }
  ;

ordered_parameter_assignment_list:
    ordered_parameter_assignment {
饶先宏's avatar
饶先宏 已提交
2124 2125
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
饶先宏's avatar
饶先宏 已提交
2126 2127
    }
|   ordered_parameter_assignment_list ',' ordered_parameter_assignment {
饶先宏's avatar
饶先宏 已提交
2128 2129
    $$ = $1;
    dlistAppendItem($$, $3);
饶先宏's avatar
饶先宏 已提交
2130 2131 2132 2133 2134
    }
  ;

named_parameter_assignment_list:
    named_parameter_assignment {
饶先宏's avatar
饶先宏 已提交
2135 2136
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
饶先宏's avatar
饶先宏 已提交
2137 2138
    }
|   named_parameter_assignment_list ',' named_parameter_assignment {
饶先宏's avatar
饶先宏 已提交
2139 2140
    $$ = $1;
    dlistAppendItem($$, $3);
饶先宏's avatar
饶先宏 已提交
2141 2142 2143 2144 2145
    }
  ;

list_of_parameter_assignments :
    ordered_parameter_assignment_list {
饶先宏's avatar
饶先宏 已提交
2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158
        int index; 
        IDListVarPtr pitem, pitemtemp;
        $$ = $1;
        index = 0;
	    if ($$ != NULL) {
	        pitem = $$->__dlist_pNext; 
	        while (pitem != $$) {
		        pitemtemp = pitem->__dlist_pNext;
                verilogparseSetParamInstanceIndex(pitem, index);
                index++;
		        pitem = pitemtemp;
	        }
        }
饶先宏's avatar
饶先宏 已提交
2159 2160
    }
|   named_parameter_assignment_list {
饶先宏's avatar
饶先宏 已提交
2161
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
2162 2163 2164 2165 2166
    }
  ;

ordered_parameter_assignment : 
    expression {
饶先宏's avatar
饶先宏 已提交
2167 2168 2169 2170 2171 2172 2173 2174
        $$ = verilogparseCreateParamInstance(
            NULL, //const char* name,
            1, //int exprcount,
            $1, //HOBJECT expr0,
            NULL, //HOBJECT expr1,
            NULL, //HOBJECT expr2,
            NULL //IDListVarPtr attributes
            );
饶先宏's avatar
饶先宏 已提交
2175 2176 2177 2178
    }
  ;

mintypmax_expression_option:
2179
      %empty  {
饶先宏's avatar
饶先宏 已提交
2180
      $$.objcount = 0;
饶先宏's avatar
饶先宏 已提交
2181 2182
    }
|   mintypmax_expression {
饶先宏's avatar
饶先宏 已提交
2183
      $$ = $1;
饶先宏's avatar
饶先宏 已提交
2184 2185 2186 2187 2188
    }
  ;

named_parameter_assignment : 
    '.' parameter_identifier '(' mintypmax_expression_option ')' {
饶先宏's avatar
饶先宏 已提交
2189 2190 2191
        $$ = verilogparseCreateParamInstance(
            $2, //const char* name,
            $4.objcount, //int exprcount,
饶先宏's avatar
饶先宏 已提交
2192
            $4.obj[0], //HOBJECT expr0, /*用mintymax方式传参数,估计只有用在delay中才用得上了*/
饶先宏's avatar
饶先宏 已提交
2193 2194 2195 2196
            $4.obj[1], //HOBJECT expr1,
            $4.obj[2], //HOBJECT expr2,
            NULL //IDListVarPtr attributes
            );
饶先宏's avatar
饶先宏 已提交
2197 2198 2199 2200
    }
  ;

list_of_port_connections_option:
饶先宏's avatar
饶先宏 已提交
2201 2202
    %empty  {
    $$ = dlistCreate();
饶先宏's avatar
饶先宏 已提交
2203 2204
    }
|   list_of_port_connections {
饶先宏's avatar
饶先宏 已提交
2205
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
2206 2207 2208
    }
  ;

饶先宏's avatar
饶先宏 已提交
2209
/*
饶先宏's avatar
饶先宏 已提交
2210 2211 2212 2213
module_instance : 
    name_of_module_instance '(' list_of_port_connections_option ')' {
    }
  ;
饶先宏's avatar
饶先宏 已提交
2214 2215 2216 2217 2218 2219
*/
module_instance : 
    module_instance_identifier range_option '(' list_of_port_connections_option ')' {
    $$ = verilogparseCreateModuleInstance(
            $1, //const char * instname,
            $2.type, // int range_type,
饶先宏's avatar
饶先宏 已提交
2220
            $2.obj[0], //HOBJECT range_msb,这个range很奇怪,不知道如何使用
饶先宏's avatar
饶先宏 已提交
2221 2222 2223 2224 2225
            $2.obj[1], //HOBJECT range_lsb,
            $4 //IDListVarPtr port_connections
        );
    }
  ;
饶先宏's avatar
饶先宏 已提交
2226

饶先宏's avatar
饶先宏 已提交
2227
/*
饶先宏's avatar
饶先宏 已提交
2228 2229 2230 2231
name_of_module_instance : 
    module_instance_identifier range_option {
    }
  ;
饶先宏's avatar
饶先宏 已提交
2232
*/
饶先宏's avatar
饶先宏 已提交
2233 2234 2235

ordered_port_connection_list:
    ordered_port_connection {
饶先宏's avatar
饶先宏 已提交
2236 2237
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
饶先宏's avatar
饶先宏 已提交
2238 2239
    }
|   ordered_port_connection_list ',' ordered_port_connection {
饶先宏's avatar
饶先宏 已提交
2240 2241
    $$ = $1;
    dlistAppendItem($$, $3);
饶先宏's avatar
饶先宏 已提交
2242 2243 2244 2245 2246
    }
  ;

named_port_connection_list:
    named_port_connection {
饶先宏's avatar
饶先宏 已提交
2247 2248
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
饶先宏's avatar
饶先宏 已提交
2249 2250
    }
|   named_port_connection_list ',' named_port_connection {
饶先宏's avatar
饶先宏 已提交
2251 2252
    $$ = $1;
    dlistAppendItem($$, $3);
饶先宏's avatar
饶先宏 已提交
2253 2254 2255 2256 2257 2258
    }
  ;


list_of_port_connections :
    ordered_port_connection_list {
饶先宏's avatar
饶先宏 已提交
2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271
        int index; 
        IDListVarPtr pitem, pitemtemp;
        $$ = $1;
        index = 0;
	    if ($$ != NULL) {
	        pitem = $$->__dlist_pNext; 
	        while (pitem != $$) {
		        pitemtemp = pitem->__dlist_pNext;
                verilogparseSetParamInstanceIndex(pitem, index);
                index++;
		        pitem = pitemtemp;
	        }
        }
饶先宏's avatar
饶先宏 已提交
2272 2273
    }
|   named_port_connection_list {
饶先宏's avatar
饶先宏 已提交
2274
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
2275 2276 2277 2278
    }
  ;

expression_option:
2279
    %empty    {
饶先宏's avatar
饶先宏 已提交
2280
    $$ = NULL;
饶先宏's avatar
饶先宏 已提交
2281 2282
    }
|   expression {
饶先宏's avatar
饶先宏 已提交
2283
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
2284 2285 2286 2287 2288
    }
  ;

ordered_port_connection : 
    attribute_instance_list expression_option {
饶先宏's avatar
饶先宏 已提交
2289 2290 2291 2292 2293 2294 2295 2296
    $$ = verilogparseCreateParamInstance(
            NULL, //const char* name,
            1, //int exprcount,
            $2, //HOBJECT expr0,
            NULL, //HOBJECT expr1,
            NULL, //HOBJECT expr2,
            $1 //IDListVarPtr attributes
            );
饶先宏's avatar
饶先宏 已提交
2297 2298 2299 2300 2301
    }
  ;

named_port_connection : 
    attribute_instance_list '.' port_identifier '(' expression_option ')' {
饶先宏's avatar
饶先宏 已提交
2302 2303 2304 2305 2306 2307 2308 2309 2310
    $$ = verilogparseCreateParamInstance(
            $3, //const char* name,
            1, //int exprcount,
            $5, //HOBJECT expr0,
            NULL, //HOBJECT expr1,
            NULL, //HOBJECT expr2,
            $1 //IDListVarPtr attributes
            );

饶先宏's avatar
饶先宏 已提交
2311 2312 2313 2314 2315
    }
  ;

/*
A.4.2 Generate construct
2316
*/
饶先宏's avatar
饶先宏 已提交
2317 2318

module_or_generate_item_list:
2319
     %empty   {
饶先宏's avatar
饶先宏 已提交
2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415
    }
|   module_or_generate_item {
    }
|   module_or_generate_item_list  module_or_generate_item {
    }
  ;


generate_region :
    KW_GENERATE module_or_generate_item_list KW_ENDGENERATE {
    }
  ;

genvar_declaration : 
    KW_GENVAR list_of_genvar_identifiers ';' {
    }
  ;

list_of_genvar_identifiers :
    genvar_identifier  {
    }
|   list_of_genvar_identifiers ',' genvar_identifier {
    }
  ;

loop_generate_construct :
    KW_FOR '(' genvar_initialization ';' genvar_expression ';' genvar_iteration ')'
    generate_block {
    }
  ;

genvar_initialization :
    genvar_identifier '=' constant_expression {
    }
  ;

genvar_expression :
    genvar_primary {
    }
|   unary_operator attribute_instance_list genvar_primary {
    }
|   genvar_expression binary_operator attribute_instance_list genvar_expression {
    }
|   genvar_expression '?' attribute_instance_list genvar_expression ':' genvar_expression {
    }
  ;

genvar_iteration :
    genvar_identifier '=' genvar_expression {
    }
  ;

genvar_primary :
    constant_primary {
    }
|   genvar_identifier {
    }
  ;

conditional_generate_construct :
    if_generate_construct {
    }
|   case_generate_construct {
    }
  ;

if_generate_construct :
    KW_IF '(' constant_expression ')' generate_block_or_null {
    }
|   KW_IF '(' constant_expression ')' generate_block_or_null KW_ELSE generate_block_or_null {
    }
  ;


case_generate_item_list:
    case_generate_item {
    }
|   case_generate_item_list  case_generate_item {
    }
  ;

case_generate_construct :
    KW_CASE '(' constant_expression ')' case_generate_item_list KW_ENDCASE {
    }
  ;

case_generate_item :
    constant_expression_list ':' generate_block_or_null {
    }
|   KW_DEFAULT generate_block_or_null {
    }
|   KW_DEFAULT ':' generate_block_or_null {
    }
  ;

module_or_generate_item_list :
2416
     %empty   {
饶先宏's avatar
饶先宏 已提交
2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439
    }
|   module_or_generate_item_list module_or_generate_item {
    }
|   module_or_generate_item {   
    }
  ;

generate_block :
    module_or_generate_item {
    }
|   KW_BEGIN  ':' generate_block_identifier module_or_generate_item_list KW_END {
    }
|   KW_BEGIN module_or_generate_item_list KW_END {
    }
  ;

generate_block_or_null :
    generate_block {
    }
|   ';' {
    }
  ;

2440 2441 2442 2443
/*
A.5 UDP declaration and instantiation
A.5.1 UDP declaration
*/
饶先宏's avatar
饶先宏 已提交
2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463

udp_port_declaration_list :
    udp_port_declaration_list udp_port_declaration {
    }
|   udp_port_declaration {   
    }
  ;

udp_declaration :
    attribute_instance_list KW_PRIMITIVE udp_identifier '(' udp_port_list ')' ';'
    udp_port_declaration_list 
    udp_body
    KW_ENDPRIMITIVE {
    }
|   attribute_instance_list KW_PRIMITIVE udp_identifier '(' udp_declaration_port_list ')' ';'
    udp_body
    KW_ENDPRIMITIVE {
    }
  ;

2464 2465 2466
/*
A.5.2 UDP ports
*/
饶先宏's avatar
饶先宏 已提交
2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509

udp_port_list : 
    output_port_identifier ',' input_port_identifier {
    }
|   udp_port_list ',' input_port_identifier {
    }
  ;

udp_declaration_port_list :
    udp_output_declaration ',' udp_input_declaration{
    } 
|   udp_declaration_port_list ',' udp_input_declaration {
    }
  ;

udp_port_declaration :
    udp_output_declaration ';' {
    }
|   udp_input_declaration ';' {
    }
|   udp_reg_declaration ';' {
    }
  ;

udp_output_declaration :
    attribute_instance_list KW_OUTPUT port_identifier {
    }
|   attribute_instance_list KW_OUTPUT KW_REG port_identifier {
    }
|   attribute_instance_list KW_OUTPUT KW_REG port_identifier '=' constant_expression {
    }
  ;

udp_input_declaration : 
    attribute_instance_list KW_INPUT list_of_port_identifiers {
    }
  ;

udp_reg_declaration : 
    attribute_instance_list KW_REG variable_identifier {
    }
  ;

2510 2511 2512
/*
A.5.3 UDP body
*/
饶先宏's avatar
饶先宏 已提交
2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581

udp_body :
    combinational_body  {
    }
|   sequential_body {
    }
  ;

combinational_entry_list :
    combinational_entry {
    } 
|   combinational_entry_list  combinational_entry {
    }
  ;

combinational_body : 
    KW_TABLE combinational_entry_list KW_ENDTABLE {
    }
  ;

combinational_entry : 
    level_input_list ':' output_symbol ';' {
    }
  ;

sequential_entry_list :
    sequential_entry {
    } 
|   sequential_entry_list  sequential_entry {
    }
  ;

sequential_body : 
    KW_TABLE sequential_entry_list KW_ENDTABLE {
    }
|   udp_initial_statement KW_TABLE sequential_entry_list KW_ENDTABLE {
    }
  ;

udp_initial_statement : 
    KW_INITIAL output_port_identifier '=' init_val ';' {
    }
  ;

init_val : 
    number {
    }
  ;
  /* 1'b0 | 1'b1 | 1'bx | 1'bX | 1'B0 | 1'B1 | 1'Bx | 1'BX | 1 | 0 */

sequential_entry : 
    seq_input_list ':' current_state ':' next_state ';' {
    }
  ;
seq_input_list : 
    level_input_list {
    }
|   edge_input_list {
    }
  ;

level_input_list : 
    level_symbol {
    }
| level_input_list level_symbol {
    }
  ;

level_symbol_list :
2582
    %empty    {
饶先宏's avatar
饶先宏 已提交
2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641
    }
|   level_symbol {
    }
|   level_symbol_list level_symbol {
    }
  ;

edge_input_list : 
    level_symbol_list edge_indicator level_symbol_list {
    }
  ;

edge_indicator : 
    '(' level_symbol level_symbol ')'  {
    }
| edge_symbol {
    }
  ;

current_state : 
    level_symbol {
    }
  ;

next_state : 
    output_symbol  {
    }
|   '-' {
    }
  ;


output_symbol : 
    unsigned_number {
    }
|   '?'   {
    }
|   SIMPLE_ID {
    }
  ;

level_symbol :
    unsigned_number {
    }
|   '?' {
    }
|   SIMPLE_ID {
    }
 ;

edge_symbol : /* can be r,f,p,n or star in any case. */
    SIMPLE_ID {
    }
|   '*' {
    }
  ;

/*
fixed me!
2642 2643 2644
output_symbol ::= 0 | 1 | x | X
level_symbol ::= 0 | 1 | x | X | ? | b | B
edge_symbol ::= r | R | f | F | p | P | n | N | *
饶先宏's avatar
饶先宏 已提交
2645 2646
*/

2647 2648 2649
/*
A.5.4 UDP instantiation
*/
饶先宏's avatar
饶先宏 已提交
2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684

udp_instance_list :
    udp_instance {
    }
|   udp_instance_list ',' udp_instance {
    }
  ;


udp_instantiation : 
    udp_identifier drive_strength_option delay2_option
    udp_instance_list ';' {
    }
  ;

input_terminal_list :
    input_terminal {
    }
|   input_terminal_list ',' input_terminal {
    }
  ;


udp_instance : 
    name_of_udp_instance '(' output_terminal ',' input_terminal_list ')' {
    }
|   '(' output_terminal ',' input_terminal_list ')' {
    }
  ;

name_of_udp_instance : 
    udp_instance_identifier range_option {
    }
  ;

2685 2686 2687 2688
/*
A.6 Behavioral statements
A.6.1 Continuous assignment statements
*/
饶先宏's avatar
饶先宏 已提交
2689
continuous_assign : 
饶先宏's avatar
饶先宏 已提交
2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701
    attribute_instance_list KW_ASSIGN drive_strength_option delay3_option list_of_net_assignments ';' {
        if (currentmodule == NULL) {
            yyerror("no current module");
        } else {
            IDListVarPtr pitem, pitemtemp;
	        pitem = $5->__dlist_pNext; 
	        while (!IsDListHeader(pitem)) {
		        pitemtemp = pitem->__dlist_pNext;
                verilog_Assignment* assignment = verilogAssignmentGetData(pitem);
                assignment->attributes = $1;
		        pitem = pitemtemp;
	        }
饶先宏's avatar
饶先宏 已提交
2702
            verilogparseAddModuleItems(currentmodule, $5, MODULE_ITEM_TYPE_CONTINUOUS_ASSIGNMENT);
饶先宏's avatar
饶先宏 已提交
2703
        }
饶先宏's avatar
饶先宏 已提交
2704 2705 2706 2707 2708
    }
  ;

list_of_net_assignments : 
    net_assignment {
饶先宏's avatar
饶先宏 已提交
2709 2710
        $$ = dlistCreate();
        dlistAppendItem($$, $1);
饶先宏's avatar
饶先宏 已提交
2711 2712
    }
|   list_of_net_assignments ',' net_assignment {
饶先宏's avatar
饶先宏 已提交
2713 2714
        $$ = $1;
        dlistAppendItem($$, $3);
饶先宏's avatar
饶先宏 已提交
2715 2716 2717
    }
  ;

饶先宏's avatar
饶先宏 已提交
2718
/*
饶先宏's avatar
饶先宏 已提交
2719 2720 2721 2722
net_assignment : 
    net_lvalue '=' expression {
    }
  ;
饶先宏's avatar
饶先宏 已提交
2723 2724 2725 2726 2727
*/

net_assignment : 
    var '=' expression {
        $$ = verilogparseCreateAssignment(
饶先宏's avatar
饶先宏 已提交
2728
            0,
饶先宏's avatar
饶先宏 已提交
2729 2730 2731
	        $1.obj[0], /* IDListVarPtr hierarchical_identifier */
	        $1.obj[1], /* IDListVarPtr element_select */
            $1.type, //int range_type,
饶先宏's avatar
饶先宏 已提交
2732 2733 2734 2735 2736 2737 2738
	        1, /* int constelementsel */
	        $3, /* HOBJECT expr */
	        NULL /* IDListVarPtr attributes */
        );
    }
  ;

饶先宏's avatar
饶先宏 已提交
2739

2740 2741 2742
/*
A.6.2 Procedural blocks and assignments
*/
饶先宏's avatar
饶先宏 已提交
2743 2744 2745 2746 2747 2748
initial_construct :
    KW_INITIAL statement {
    }
  ;

always_construct : 
饶先宏's avatar
饶先宏 已提交
2749
    attribute_instance_list KW_ALWAYS statement {
饶先宏's avatar
饶先宏 已提交
2750 2751 2752 2753
    IDListVarPtr list = dlistCreate();
    dlistAppendItem(list, $3);
    verilogparseAddModuleItems(currentmodule, list, MODULE_ITEM_TYPE_ALWAYS_CONSTRUCT);
    objectRelease(list);
饶先宏's avatar
饶先宏 已提交
2754 2755 2756 2757
    }
  ;

delay_or_event_control_option :
2758
     %empty   {
饶先宏's avatar
饶先宏 已提交
2759 2760 2761 2762 2763 2764
    }
|   delay_or_event_control {
    }
  ;

blocking_assignment : 
饶先宏's avatar
饶先宏 已提交
2765 2766 2767 2768
    attribute_instance_list var '=' delay_or_event_control_option expression {
        $$ = verilogparseCreateAssignmentStatement(
            STATEMENT_BLOCKING_ASSIGNMENT,
            verilogparseCreateAssignment(
饶先宏's avatar
饶先宏 已提交
2769
                1,
饶先宏's avatar
饶先宏 已提交
2770 2771 2772 2773 2774 2775 2776 2777
	            $2.obj[0], /* IDListVarPtr hierarchical_identifier */
	            $2.obj[1], /* IDListVarPtr element_select */
                $2.type, //int range_type,
	            1, /* int constelementsel */
	            $5, /* HOBJECT expr */
	            $1 /* IDListVarPtr attributes */
            )
        );
饶先宏's avatar
饶先宏 已提交
2778
    }
饶先宏's avatar
饶先宏 已提交
2779 2780
/* 
    variable_lvalue '=' expression
饶先宏's avatar
饶先宏 已提交
2781 2782
|   variable_lvalue '=' delay_or_event_control_option  expression {
    }
饶先宏's avatar
饶先宏 已提交
2783
*/
饶先宏's avatar
饶先宏 已提交
2784 2785 2786
  ;

nonblocking_assignment : 
饶先宏's avatar
饶先宏 已提交
2787 2788 2789 2790
    attribute_instance_list var LTE delay_or_event_control_option expression {
        $$ = verilogparseCreateAssignmentStatement(
            STATEMENT_NONBLOCKING_ASSIGNMENT,
            verilogparseCreateAssignment (
饶先宏's avatar
饶先宏 已提交
2791
                2,
饶先宏's avatar
饶先宏 已提交
2792 2793 2794 2795 2796 2797 2798 2799 2800 2801
	            $2.obj[0], /* IDListVarPtr hierarchical_identifier */
	            $2.obj[1], /* IDListVarPtr element_select */
                $2.type, //int range_type,
	            1, /* int constelementsel */
	            $5, /* HOBJECT expr */
	            $1 /* IDListVarPtr attributes */
            )
        );
    }
/*
饶先宏's avatar
饶先宏 已提交
2802 2803
    variable_lvalue LTE delay_or_event_control_option expression {
    }
饶先宏's avatar
饶先宏 已提交
2804
*/
饶先宏's avatar
饶先宏 已提交
2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825
  ;
procedural_continuous_assignments :
    KW_ASSIGN variable_assignment {
    }
|   KW_DEASSIGN variable_lvalue {
    }
|   KW_FORCE variable_assignment {
    }
|   KW_FORCE net_assignment {
    }
|   KW_RELEASE variable_lvalue {
    }
|   KW_RELEASE net_lvalue {
    }
  ;

variable_assignment : 
    variable_lvalue '=' expression {
    }
  ;

2826 2827 2828
/*
A.6.3 Parallel and sequential blocks
*/
饶先宏's avatar
饶先宏 已提交
2829
block_item_declaration_list:
2830
    %empty    {
饶先宏's avatar
饶先宏 已提交
2831 2832 2833 2834 2835 2836 2837 2838
    }
|   block_item_declaration {
    }
|   block_item_declaration_list block_item_declaration {
    }
  ;

statement_list:
2839
    %empty    {
饶先宏's avatar
饶先宏 已提交
2840
    $$ = dlistCreate();
饶先宏's avatar
饶先宏 已提交
2841 2842
    }
|   statement {
饶先宏's avatar
饶先宏 已提交
2843 2844
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
饶先宏's avatar
饶先宏 已提交
2845 2846
    }
|   statement_list statement {
饶先宏's avatar
饶先宏 已提交
2847 2848
    $$ = $1;
    dlistAppendItem($$, $2);
饶先宏's avatar
饶先宏 已提交
2849 2850 2851 2852 2853
    }
  ;

par_block : 
    KW_FORK statement_list KW_JOIN {
饶先宏's avatar
饶先宏 已提交
2854 2855 2856 2857
    $$ = verilogparseCreateListStatement(
        STATEMENT_PAR, //int statementtype,
        $2 //IDListVarPtr statement_list
        );
饶先宏's avatar
饶先宏 已提交
2858 2859
    }
|   KW_FORK ':' block_identifier block_item_declaration_list statement_list KW_JOIN {
饶先宏's avatar
饶先宏 已提交
2860
    yyerror("No support to named par block");
饶先宏's avatar
饶先宏 已提交
2861 2862 2863 2864 2865
    }
  ;

seq_block : 
    KW_BEGIN statement_list KW_END {
饶先宏's avatar
饶先宏 已提交
2866 2867 2868 2869
    $$ = verilogparseCreateListStatement(
        STATEMENT_SEQ, //int statementtype,
        $2 //IDListVarPtr statement_list
        );
饶先宏's avatar
饶先宏 已提交
2870 2871
    }
|   KW_BEGIN  ':' block_identifier block_item_declaration_list statement_list KW_END {
饶先宏's avatar
饶先宏 已提交
2872
    yyerror("No support to named par block");
饶先宏's avatar
饶先宏 已提交
2873 2874 2875
    }
  ;

2876 2877 2878
/*
A.6.4 Statements
*/
饶先宏's avatar
饶先宏 已提交
2879
statement :
饶先宏's avatar
饶先宏 已提交
2880
    blocking_assignment ';' {
饶先宏's avatar
饶先宏 已提交
2881
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
2882 2883
    }
|   attribute_instance_list case_statement {
饶先宏's avatar
饶先宏 已提交
2884
    $$ = $2;
饶先宏's avatar
饶先宏 已提交
2885
    }
饶先宏's avatar
饶先宏 已提交
2886
|   conditional_statement {
饶先宏's avatar
饶先宏 已提交
2887
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
2888 2889
    }
|   attribute_instance_list disable_statement {
饶先宏's avatar
饶先宏 已提交
2890 2891
    yyerror("No support to disable statement");
    $$ = NULL;
饶先宏's avatar
饶先宏 已提交
2892 2893
    }
|   attribute_instance_list event_trigger {
饶先宏's avatar
饶先宏 已提交
2894 2895
    yyerror("No support to event_trigger statement");
    $$ = NULL;
饶先宏's avatar
饶先宏 已提交
2896 2897
    }
|   attribute_instance_list loop_statement {
饶先宏's avatar
饶先宏 已提交
2898 2899
    yyerror("No support to loop statement");
    $$ = NULL;
饶先宏's avatar
饶先宏 已提交
2900
    }
饶先宏's avatar
饶先宏 已提交
2901
|   nonblocking_assignment ';' {
饶先宏's avatar
饶先宏 已提交
2902
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
2903 2904
    }
|   attribute_instance_list par_block {
饶先宏's avatar
饶先宏 已提交
2905
    $$ = $2;
饶先宏's avatar
饶先宏 已提交
2906 2907
    }
|   attribute_instance_list procedural_continuous_assignments ';' {
饶先宏's avatar
饶先宏 已提交
2908 2909
    yyerror("No support to procedural_continuous_assignments");
    $$ = NULL;
饶先宏's avatar
饶先宏 已提交
2910
    }
饶先宏's avatar
饶先宏 已提交
2911 2912 2913 2914 2915
|   attribute_instance_list procedural_timing_control statement_or_null {
    verilog_Statement * statinfo;
    $$ = $3;
    statinfo = verilogStatementGetData($$);
    statinfo->timecontrol = $2;
饶先宏's avatar
饶先宏 已提交
2916 2917
    }
|   attribute_instance_list seq_block {
饶先宏's avatar
饶先宏 已提交
2918
    $$ = $2;
饶先宏's avatar
饶先宏 已提交
2919 2920
    }
|   attribute_instance_list system_task_enable {
饶先宏's avatar
饶先宏 已提交
2921 2922
    $$ = NULL;
    yyerror("No support to system_task_enable");
饶先宏's avatar
饶先宏 已提交
2923 2924
    }
|   attribute_instance_list task_enable {
饶先宏's avatar
饶先宏 已提交
2925 2926
    $$ = NULL;
    yyerror("No support to task_enable");
饶先宏's avatar
饶先宏 已提交
2927 2928
    }
|   attribute_instance_list wait_statement {
饶先宏's avatar
饶先宏 已提交
2929 2930 2931
    $$ = NULL;
    yyerror("No support to wait_statement");
   }
饶先宏's avatar
饶先宏 已提交
2932 2933 2934 2935
  ;

statement_or_null :
    statement {
饶先宏's avatar
饶先宏 已提交
2936
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
2937 2938
    }
|   attribute_instance_list ';' {
饶先宏's avatar
饶先宏 已提交
2939
    $$ = verilogparseCreateNullStatement();
饶先宏's avatar
饶先宏 已提交
2940 2941 2942 2943 2944 2945 2946 2947
    }
  ;

function_statement : 
    statement {
    }
  ;

2948 2949 2950
/*
A.6.5 Timing control statements
*/
饶先宏's avatar
饶先宏 已提交
2951 2952 2953 2954 2955 2956 2957 2958 2959
delay_control :
    '#' delay_value {
    }
|   '#' '(' mintypmax_expression ')' {
    }
  ;

delay_or_event_control :
    delay_control {
饶先宏's avatar
饶先宏 已提交
2960
    $$ = TIMECONTROL_DELAY;
饶先宏's avatar
饶先宏 已提交
2961 2962
    }
|   event_control {
饶先宏's avatar
饶先宏 已提交
2963
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
2964 2965
    }
|   KW_REPEAT '(' expression ')' event_control {
饶先宏's avatar
饶先宏 已提交
2966
    yyerror("no support repeat <> event_control");
饶先宏's avatar
饶先宏 已提交
2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978
    }
  ;

disable_statement :
    KW_DISABLE hierarchical_task_identifier ';' {
    }
|   KW_DISABLE hierarchical_block_identifier ';' {
    }
  ;

event_control :
    '@' hierarchical_event_identifier {
饶先宏's avatar
饶先宏 已提交
2979
    $$ = TIMECONTROL_SINGALCHANGE;
饶先宏's avatar
饶先宏 已提交
2980 2981
    }
|   '@' '(' event_expression ')' {
饶先宏's avatar
饶先宏 已提交
2982
    $$ = $3;
饶先宏's avatar
饶先宏 已提交
2983
    }
饶先宏's avatar
饶先宏 已提交
2984
|   '@' '*' {
饶先宏's avatar
饶先宏 已提交
2985
    $$ = TIMECONTROL_SINGALCHANGE;
饶先宏's avatar
饶先宏 已提交
2986 2987
    }
|   '@' '(' '*' ')' {
饶先宏's avatar
饶先宏 已提交
2988
    $$ = TIMECONTROL_SINGALCHANGE;
饶先宏's avatar
饶先宏 已提交
2989 2990 2991 2992
    }
  ;

script_list :
2993
     %empty   {
饶先宏's avatar
饶先宏 已提交
2994 2995 2996 2997 2998 2999 3000 3001
    }
| '['expression ']' {
    }
|script_list '['expression ']' {
    }
  ;

event_trigger :
饶先宏's avatar
饶先宏 已提交
3002
    MINUSGT hierarchical_event_identifier script_list ';' {
饶先宏's avatar
饶先宏 已提交
3003 3004 3005 3006 3007
    }
  ;

event_expression :
    expression {
饶先宏's avatar
饶先宏 已提交
3008
    $$ = TIMECONTROL_SINGALCHANGE;
饶先宏's avatar
饶先宏 已提交
3009 3010
    }
|   KW_POSEDGE expression {
饶先宏's avatar
饶先宏 已提交
3011
    $$ = TIMECONTROL_ATPOSEDGE;    
饶先宏's avatar
饶先宏 已提交
3012 3013
    }
|   KW_NEGEDGE expression {
饶先宏's avatar
饶先宏 已提交
3014
    $$ = TIMECONTROL_ATNEGEDGE;    
饶先宏's avatar
饶先宏 已提交
3015 3016
    }
|   event_expression KW_OR event_expression {
饶先宏's avatar
饶先宏 已提交
3017
    $$ = TIMECONTROL_SINGALCHANGE;
饶先宏's avatar
饶先宏 已提交
3018 3019
    }
|   event_expression ',' event_expression {
饶先宏's avatar
饶先宏 已提交
3020
    $$ = TIMECONTROL_SINGALCHANGE;
饶先宏's avatar
饶先宏 已提交
3021 3022 3023 3024 3025
    }
  ;

procedural_timing_control :
    delay_control {
饶先宏's avatar
饶先宏 已提交
3026
        $$ = TIMECONTROL_DELAY;
饶先宏's avatar
饶先宏 已提交
3027 3028
    }
|   event_control {
饶先宏's avatar
饶先宏 已提交
3029
        $$ = $1;
饶先宏's avatar
饶先宏 已提交
3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042
    }
  ;

procedural_timing_control_statement :
    procedural_timing_control statement_or_null {
    }
  ;

wait_statement :
    KW_WAIT '(' expression ')' statement_or_null {
    }
  ;

3043 3044 3045
/*
A.6.6 Conditional statements
*/
饶先宏's avatar
饶先宏 已提交
3046 3047 3048
conditional_statement :
    KW_IF '(' expression ')'
    statement_or_null KW_ELSE statement_or_null {
饶先宏's avatar
饶先宏 已提交
3049 3050 3051 3052 3053
        $$ = verilogparseCreateConditionalStatement(
            $3, //HOBJECT expression,
            $5, //HOBJECT trueblock,
            $7  //HOBJECT falseblock
        );
饶先宏's avatar
饶先宏 已提交
3054 3055 3056
    }
|   KW_IF '(' expression ')'
    statement_or_null {
饶先宏's avatar
饶先宏 已提交
3057 3058 3059 3060 3061
        $$ = verilogparseCreateConditionalStatement(
            $3, //HOBJECT expression,
            $5, //HOBJECT trueblock,
            NULL  //HOBJECT falseblock
        );
饶先宏's avatar
饶先宏 已提交
3062
    }
饶先宏's avatar
饶先宏 已提交
3063 3064
/*|   if_else_if_statement {
    } 这个与前面冲突了,也没有必要啊 */
饶先宏's avatar
饶先宏 已提交
3065
  ;
饶先宏's avatar
饶先宏 已提交
3066
/*
饶先宏's avatar
饶先宏 已提交
3067
else_if_list:
3068
     %empty   {
饶先宏's avatar
饶先宏 已提交
3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084
    } 
|   KW_ELSE KW_IF '(' expression ')' statement_or_null {
    }
|   else_if_list KW_ELSE KW_IF '(' expression ')' statement_or_null {
    }
  ;

if_else_if_statement :
    KW_IF '(' expression ')' statement_or_null
    else_if_list
    KW_ELSE statement_or_null {
    }
|   KW_IF '(' expression ')' statement_or_null
    else_if_list {
    }
  ;
饶先宏's avatar
饶先宏 已提交
3085
*/
饶先宏's avatar
饶先宏 已提交
3086

3087 3088 3089
/*
A.6.7 Case statements
*/
饶先宏's avatar
饶先宏 已提交
3090 3091
case_item_list :
    case_item {
饶先宏's avatar
饶先宏 已提交
3092 3093
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
饶先宏's avatar
饶先宏 已提交
3094 3095
    }
|   case_item_list case_item {
饶先宏's avatar
饶先宏 已提交
3096 3097
    $$ = $1;
    dlistAppendItem($$, $2);
饶先宏's avatar
饶先宏 已提交
3098 3099 3100 3101 3102
    }
  ;

case_type:
    KW_CASE {
饶先宏's avatar
饶先宏 已提交
3103
    $$ = CASETYPE_CASE;
饶先宏's avatar
饶先宏 已提交
3104 3105
    }
|   KW_CASEZ {
饶先宏's avatar
饶先宏 已提交
3106
    $$ = CASETYPE_CASEZ;
饶先宏's avatar
饶先宏 已提交
3107 3108
    }
|   KW_CASEX {
饶先宏's avatar
饶先宏 已提交
3109
    $$ = CASETYPE_CASEX;
饶先宏's avatar
饶先宏 已提交
3110 3111 3112 3113 3114
    }
  ;

case_statement :
    case_type '(' expression ')' case_item_list KW_ENDCASE {
饶先宏's avatar
饶先宏 已提交
3115 3116 3117 3118 3119
    $$ = verilogparseCreateCaseStatement(
	    $1, //int case_type
	    $3, //HOBJECT case_expression,
	    $5  //IDListVarPtr case_item_list
        );
饶先宏's avatar
饶先宏 已提交
3120 3121 3122 3123 3124
    }
  ;

expression_list :
    expression {
饶先宏's avatar
饶先宏 已提交
3125 3126
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
饶先宏's avatar
饶先宏 已提交
3127 3128
    }
|   expression_list ',' expression {
饶先宏's avatar
饶先宏 已提交
3129 3130
    $$ = $1;
    dlistAppendItem($$, $3);
饶先宏's avatar
饶先宏 已提交
3131 3132 3133 3134 3135
    }
  ;

case_item :
    expression_list ':' statement_or_null {
饶先宏's avatar
饶先宏 已提交
3136 3137 3138 3139
      $$ = verilogparseCreateCaseItem(
            $1, //IDListVarPtr expression_list,
            $3 //HOBJECT statement
        );
饶先宏's avatar
饶先宏 已提交
3140 3141
    }
|   KW_DEFAULT ':' statement_or_null {
饶先宏's avatar
饶先宏 已提交
3142 3143 3144 3145
      $$ = verilogparseCreateCaseItem(
            dlistCreate(), //IDListVarPtr expression_list,
            $3 //HOBJECT statement
        );
饶先宏's avatar
饶先宏 已提交
3146 3147
    }
|   KW_DEFAULT statement_or_null {
饶先宏's avatar
饶先宏 已提交
3148 3149 3150 3151
      $$ = verilogparseCreateCaseItem(
            dlistCreate(), //IDListVarPtr expression_list,
            $2 //HOBJECT statement
        );
饶先宏's avatar
饶先宏 已提交
3152 3153 3154
    }
  ;

3155 3156 3157
/*
A.6.8 Looping statements
*/
饶先宏's avatar
饶先宏 已提交
3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168
loop_statement :
    KW_FOREVER statement {
    }
|   KW_REPEAT '(' expression ')' statement {
    }
|   KW_WHILE '(' expression ')' statement {    
    }
|   KW_FOR '(' variable_assignment ';' expression ';' variable_assignment ')' statement {
    }
  ;

3169 3170 3171
/*
A.6.9 Task enable statements
*/
饶先宏's avatar
饶先宏 已提交
3172
expression_or_null_list :
3173
     %empty   {
饶先宏's avatar
饶先宏 已提交
3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196
    }
|   expression {
    }
|   expression_or_null_list ',' {
    }
|   expression_or_null_list ',' expression {
    }
  ;

system_task_enable : 
    SYSTEM_ID ';' {
    }
|   SYSTEM_ID '(' expression_or_null_list ')' ';' {
    }
  ;

task_enable : 
    hierarchical_task_identifier ';' {
    }
|   hierarchical_task_identifier '(' expression_list ')' ';' {
    }
  ;

3197 3198 3199 3200
/*
A.7 Specify section
A.7.1 Specify block declaration
*/
饶先宏's avatar
饶先宏 已提交
3201
specify_item_list :
3202
     %empty   {
饶先宏's avatar
饶先宏 已提交
3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241
    }
|   specify_item {
    }
|   specify_item_list specify_item {
    }
  ;

specify_block : 
    KW_SPECIFY specify_item_list KW_ENDSPECIFY {
    }
  ;

specify_item :
    specparam_declaration {
    }
|   pulsestyle_declaration {
    }
|   showcancelled_declaration {
    }
|   path_declaration {
    }
|   system_timing_check {
    }
  ;

pulsestyle_declaration :
    KW_PULSESTYLE_ONEVENT list_of_path_outputs ';' {
    }
|   KW_PULSESTYLE_ONDETECT list_of_path_outputs ';' {
    }
  ;

showcancelled_declaration :
    KW_SHOWCANCELLED list_of_path_outputs ';' {
    }
|   KW_NOSHOWCANCELLED list_of_path_outputs ';' {
    }
  ;

3242 3243 3244
/*
A.7.2 Specify path declarations
*/
饶先宏's avatar
饶先宏 已提交
3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261
path_declaration :
    simple_path_declaration ';' {
    }
|   edge_sensitive_path_declaration ';' {
    }
|   state_dependent_path_declaration ';' {
    }
  ;

simple_path_declaration : 
    parallel_path_description '=' path_delay_value {
    }
|   full_path_description '=' path_delay_value {
    }
  ;

polarity_operator_option:
3262
     %empty   {
饶先宏's avatar
饶先宏 已提交
3263 3264 3265 3266 3267 3268
    }
|   polarity_operator {
    }
  ;

parallel_path_description :
饶先宏's avatar
饶先宏 已提交
3269
    '(' specify_input_terminal_descriptor polarity_operator_option EQGT specify_output_terminal_descriptor ')' {
饶先宏's avatar
饶先宏 已提交
3270 3271 3272 3273
    }
  ;

full_path_description :
饶先宏's avatar
饶先宏 已提交
3274
    '(' list_of_path_inputs polarity_operator_option STARGT list_of_path_outputs ')' {
饶先宏's avatar
饶先宏 已提交
3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291
    }
  ;

list_of_path_inputs :
    specify_input_terminal_descriptor {
    } 
|   list_of_path_inputs ',' specify_input_terminal_descriptor {
    }
  ;

list_of_path_outputs :
    specify_output_terminal_descriptor {
    }
|   list_of_path_outputs ',' specify_output_terminal_descriptor {
    }
  ;

3292 3293 3294
/*
A.7.3 Specify block terminals
*/
饶先宏's avatar
饶先宏 已提交
3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322
specify_input_terminal_descriptor :
    input_identifier {
    }
|   input_identifier '[' constant_range_expression ']' {
    }
  ;

specify_output_terminal_descriptor :
    output_identifier {
    }
|   output_identifier '[' constant_range_expression ']' {
    }
  ;

input_identifier : 
    input_port_identifier  {
    }
|   inout_port_identifier {
    }
  ;

output_identifier : 
    output_port_identifier  {
    }
|   inout_port_identifier {
    }
  ;

3323 3324 3325
/*
A.7.4 Specify path delays
*/
饶先宏's avatar
饶先宏 已提交
3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440
path_delay_value :
    list_of_path_delay_expressions {
    }
|   '(' list_of_path_delay_expressions ')' {
    }
  ;

list_of_path_delay_expressions :
    t_path_delay_expression {
    }
|   trise_path_delay_expression ',' tfall_path_delay_expression {
    }
|   trise_path_delay_expression ',' tfall_path_delay_expression ',' tz_path_delay_expression {
    }
|   t01_path_delay_expression ',' t10_path_delay_expression ',' t0z_path_delay_expression ','
    tz1_path_delay_expression ',' t1z_path_delay_expression ',' tz0_path_delay_expression {
    }
|   t01_path_delay_expression ',' t10_path_delay_expression ',' t0z_path_delay_expression ','
    tz1_path_delay_expression ',' t1z_path_delay_expression ',' tz0_path_delay_expression ','
    t0x_path_delay_expression ',' tx1_path_delay_expression ',' t1x_path_delay_expression ','
    tx0_path_delay_expression ',' txz_path_delay_expression ',' tzx_path_delay_expression {
    }
  ;

t_path_delay_expression : 
    path_delay_expression {
    }
  ;

trise_path_delay_expression : 
	path_delay_expression {
	}
  ;

tfall_path_delay_expression : 
	path_delay_expression {
	}
  ;

tz_path_delay_expression : 
	path_delay_expression {
	}
  ;

t01_path_delay_expression : 
	path_delay_expression {
	}
  ;

t10_path_delay_expression : 
	path_delay_expression {
	}
  ;

t0z_path_delay_expression : 
	path_delay_expression {
	}
  ;

tz1_path_delay_expression : 
	path_delay_expression {
	}
  ;

t1z_path_delay_expression : 
	path_delay_expression {
	}
  ;

tz0_path_delay_expression : 
	path_delay_expression {
	}
  ;
t0x_path_delay_expression : 
	path_delay_expression {
	}
  ;

tx1_path_delay_expression : 
	path_delay_expression {
	}
  ;

t1x_path_delay_expression : 
	path_delay_expression {
	}
  ;
tx0_path_delay_expression : 
	path_delay_expression {
	}
  ;

txz_path_delay_expression : 
	path_delay_expression {
	}
  ;

tzx_path_delay_expression : 
	path_delay_expression {
	}
  ;

path_delay_expression : 
    constant_mintypmax_expression {
    }
  ;

edge_sensitive_path_declaration :
    parallel_edge_sensitive_path_description '=' path_delay_value {
    }
|   full_edge_sensitive_path_description '=' path_delay_value {
    }
  ;

edge_identifier_option :
3441
     %empty   {
饶先宏's avatar
饶先宏 已提交
3442 3443 3444 3445 3446 3447
    }
|   edge_identifier {
    }
  ;

polarity_operator_option :
3448
     %empty   {
饶先宏's avatar
饶先宏 已提交
3449 3450 3451 3452 3453
    }
|   polarity_operator {
    }
  ;
parallel_edge_sensitive_path_description :
饶先宏's avatar
饶先宏 已提交
3454
    '(' edge_identifier_option specify_input_terminal_descriptor EQGT 
饶先宏's avatar
饶先宏 已提交
3455 3456 3457 3458 3459
    '(' specify_output_terminal_descriptor polarity_operator_option ':' data_source_expression ')' ')' {
    }
  ;

full_edge_sensitive_path_description :
饶先宏's avatar
饶先宏 已提交
3460
    '(' edge_identifier_option list_of_path_inputs STARGT
饶先宏's avatar
饶先宏 已提交
3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492
    '(' list_of_path_outputs polarity_operator_option ':' data_source_expression ')' ')' {
    }
  ;

data_source_expression : 
    expression {
    }
  ;

edge_identifier : 
    KW_POSEDGE {
    }
|   KW_NEGEDGE {
    }
  ;

state_dependent_path_declaration :
    KW_IF '(' module_path_expression ')' simple_path_declaration {
    }
|   KW_IF '(' module_path_expression ')' edge_sensitive_path_declaration {
    }
|   KW_IFNONE simple_path_declaration {
    }
  ;

polarity_operator : 
    '+'  {
    }
|   '-' {
    }
  ;

3493 3494 3495 3496
/*
A.7.5 System timing checks
A.7.5.1 System timing check commands
*/
饶先宏's avatar
饶先宏 已提交
3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525

system_timing_check :
    setup_timing_check {
    }
|   hold_timing_check{
    }
|   setuphold_timing_check {
    }
|   recovery_timing_check {
    }
|   removal_timing_check {
    }
|   recrem_timing_check {
    }
|   skew_timing_check {
    }
|   timeskew_timing_check {
    }
|   fullskew_timing_check {
    }
|   period_timing_check {
    }
|   width_timing_check {
    }
|   nochange_timing_check {
    }
  ;

notifier_or_null :
3526
    %empty    {
饶先宏's avatar
饶先宏 已提交
3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544
    }
|   ',' {
    }
|   ',' notifier {
    }
  ;

setup_timing_check :
    KW_SYS_SETUP '(' data_event ',' reference_event ',' timing_check_limit notifier_or_null ')' ';' {
    }
  ;

hold_timing_check :
    KW_SYS_HOLD '(' reference_event ',' data_event ',' timing_check_limit notifier_or_null ')' ';' {
    }
  ;

notifier_option :
3545
     %empty  {
饶先宏's avatar
饶先宏 已提交
3546 3547 3548 3549 3550 3551
    }
|   notifier {
    }
  ;

stamptime_condition_option :
3552
     %empty   {
饶先宏's avatar
饶先宏 已提交
3553 3554 3555 3556 3557 3558
    }
|   stamptime_condition {
    }
  ;

checktime_condition_option :
3559
    %empty    {
饶先宏's avatar
饶先宏 已提交
3560 3561 3562 3563 3564 3565
    }
|   checktime_condition {
    }
  ;

delayed_reference_option :
3566
     %empty   {
饶先宏's avatar
饶先宏 已提交
3567 3568 3569 3570 3571 3572
    }
|   delayed_reference {
    }
  ;

delayed_data_option :
3573
    %empty    {
饶先宏's avatar
饶先宏 已提交
3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687
    }
|   delayed_data {
    }
  ;

setuphold_timing_check :
    KW_SYS_SETUPHOLD '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ')' ';' {
    }
|   KW_SYS_SETUPHOLD '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option 
    ')' ';' {
    }
|   KW_SYS_SETUPHOLD '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option 
    ',' stamptime_condition_option 
    ')' ';' {
    }
|   KW_SYS_SETUPHOLD '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option 
    ',' stamptime_condition_option 
    ',' checktime_condition_option
     ')' ';' {
    }
|   KW_SYS_SETUPHOLD '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option 
    ',' stamptime_condition_option 
    ',' checktime_condition_option
    ',' delayed_reference_option 
    ')' ';' {
    }
|   KW_SYS_SETUPHOLD '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option 
    ',' stamptime_condition_option 
    ',' checktime_condition_option
    ',' delayed_reference_option 
    ',' delayed_data_option
    ')' ';' {
    }
  ;

recovery_timing_check :
    KW_SYS_RECOVERY '(' reference_event ',' data_event ',' timing_check_limit notifier_or_null ')' ';' {
    }
  ;

removal_timing_check :
    KW_SYS_REMOVAL '(' reference_event ',' data_event ',' timing_check_limit notifier_or_null ')' ';' {
    }
  ;

recrem_timing_check :
    KW_SYS_RECREM '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ')' ';' {
    }
|   KW_SYS_RECREM '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option
    ')' ';' {
    }
|   KW_SYS_RECREM '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option 
    ',' stamptime_condition_option
    ')' ';' {
    }
|   KW_SYS_RECREM '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option 
    ',' stamptime_condition_option 
    ',' checktime_condition_option
    ')' ';' {
    }
|   KW_SYS_RECREM '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option 
    ',' stamptime_condition_option 
    ',' checktime_condition_option
    ',' delayed_reference_option
    ')' ';' {
    }
|   KW_SYS_RECREM '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option 
    ',' stamptime_condition_option 
    ',' checktime_condition_option
    ',' delayed_reference_option  
    ',' delayed_data_option
    ')' ';' {
    }
  ;

skew_timing_check :
    KW_SYS_SKEW '(' reference_event ',' data_event ',' timing_check_limit notifier_or_null ')' ';' {
    }
  ;

timeskew_timing_check :
    KW_SYS_TIMESKEW '(' reference_event ',' data_event ',' timing_check_limit
    ')' ';' {
    }
|   KW_SYS_TIMESKEW '(' reference_event ',' data_event ',' timing_check_limit
    ',' notifier_option 
    ')' ';' {
    }
|   KW_SYS_TIMESKEW '(' reference_event ',' data_event ',' timing_check_limit
    ',' notifier_option 
    ',' event_based_flag_option
    ')' ';' {
    }
|   KW_SYS_TIMESKEW '(' reference_event ',' data_event ',' timing_check_limit
    ',' notifier_option 
    ',' event_based_flag_option
    ',' remain_active_flag_option
    ')' ';' {
    }
  ;

event_based_flag_option :
3688
     %empty   {
饶先宏's avatar
饶先宏 已提交
3689 3690 3691 3692 3693 3694
    }
|   event_based_flag {
    }
  ;

remain_active_flag_option :
3695
     %empty   {
饶先宏's avatar
饶先宏 已提交
3696 3697 3698 3699 3700 3701
    }
|   remain_active_flag {
    }
  ;

threshold_option :
3702
     %empty   {
饶先宏's avatar
饶先宏 已提交
3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756
    }
|   threshold {
    }
  ;

fullskew_timing_check :
    KW_SYS_FULLSKEW '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ')' ';' {
    }
|   KW_SYS_FULLSKEW '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option
    ')' ';' {
    }

|   KW_SYS_FULLSKEW '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option
    ',' event_based_flag_option
    ')' ';' {
    }
|   KW_SYS_FULLSKEW '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit
    ',' notifier_option
    ',' event_based_flag_option
    ',' remain_active_flag_option 
    ')' ';' {
    }
  ;

period_timing_check :
    KW_SYS_PERIOD '(' controlled_reference_event ',' timing_check_limit notifier_or_null ')' ';' {
    }
  ;


width_timing_check :
    KW_SYS_WIDTH '(' controlled_reference_event ',' timing_check_limit
    ')' ';' {
    }
|   KW_SYS_WIDTH '(' controlled_reference_event ',' timing_check_limit
    ',' threshold_option 
    ')' ';' {
    }
|   KW_SYS_WIDTH '(' controlled_reference_event ',' timing_check_limit
    ',' threshold_option 
    ',' notifier_option 
    ')' ';' {
    }
  ;

nochange_timing_check :
    KW_SYS_NOCHANGE '(' reference_event ',' data_event ',' start_edge_offset ','
    end_edge_offset notifier_or_null ')' ';' {
    }
  ;

3757 3758 3759
/*
A.7.5.2 System timing check command arguments
*/
饶先宏's avatar
饶先宏 已提交
3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836

checktime_condition : 
    mintypmax_expression {
    }
  ;

controlled_reference_event : 
    controlled_timing_check_event {
    }
  ;

data_event : 
    timing_check_event {
    }
  ;

delayed_data :
    terminal_identifier {
    }
|   terminal_identifier '[' constant_mintypmax_expression ']' {
    }
  ;

delayed_reference :
    terminal_identifier {
    }
|   terminal_identifier '[' constant_mintypmax_expression ']' {
    }
  ;

end_edge_offset :
    mintypmax_expression {
    }
 ;

event_based_flag : 
    constant_expression {
    }
  ;

notifier : 
    variable_identifier {
    }
  ;

reference_event : 
    timing_check_event {
    }
  ;

remain_active_flag : 
    constant_expression {
    }
  ;

stamptime_condition : 
    mintypmax_expression {
    }
  ;

start_edge_offset : 
    mintypmax_expression {
    }
  ;

threshold : 
    constant_expression {
    }
  ;

timing_check_limit : 
    expression {
    }
  ;



3837 3838 3839
/*
A.7.5.3 System timing check event definitions
*/
饶先宏's avatar
饶先宏 已提交
3840 3841

timing_check_event_control_option :
3842
     %empty   {
饶先宏's avatar
饶先宏 已提交
3843 3844 3845 3846 3847 3848 3849 3850
    }
|   timing_check_event_control {
    }
  ;

timing_check_event :
    timing_check_event_control_option specify_terminal_descriptor {
    }
饶先宏's avatar
饶先宏 已提交
3851
|   timing_check_event_control_option specify_terminal_descriptor T_AND timing_check_condition {
饶先宏's avatar
饶先宏 已提交
3852 3853 3854 3855 3856 3857
    }
  ;

controlled_timing_check_event :
    timing_check_event_control specify_terminal_descriptor {
    }
饶先宏's avatar
饶先宏 已提交
3858
|   timing_check_event_control specify_terminal_descriptor T_AND timing_check_condition {
饶先宏's avatar
饶先宏 已提交
3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878
    }
  ;

timing_check_event_control :
    KW_POSEDGE {
    }
|   KW_NEGEDGE {
    }
|   edge_control_specifier {
    }
  ;

specify_terminal_descriptor :
    specify_input_terminal_descriptor {
    }
|   specify_output_terminal_descriptor {
    }
  ;

edge_descriptor_list:
3879
      %empty  {
饶先宏's avatar
饶先宏 已提交
3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910
    }
| edge_descriptor {
    }
| edge_descriptor_list ',' edge_descriptor {
    }
  ;

edge_control_specifier : 
    KW_EDGE edge_descriptor_list {
    }
  ;

edge_descriptor :
    number {
    }
  ;

/*
fixed me
edge_descriptor :
    01 {
    }
|   10 {
    }
|   z_or_x zero_or_one {
    }
|   zero_or_one z_or_x {
    }
  ;

zero_or_one : 0 | 1
3911
z_or_x ::= x | X | z | Z
饶先宏's avatar
饶先宏 已提交
3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941
*/

timing_check_condition :
    scalar_timing_check_condition {
    }
|   '(' scalar_timing_check_condition ')' {
    }
  ;

scalar_timing_check_condition :
    expression {
    }
|   '~' expression {
    }
|   expression L_EQ scalar_constant {
    }
|   expression C_EQ scalar_constant {
    }
|   expression L_NEQ scalar_constant {
    }
|   expression C_NEQ scalar_constant {
    }
  ;

scalar_constant :
    number {
    }
  ;
/*
fixedme
3942
1'b0 | 1'b1 | 1'B0 | 1'B1 | 'b0 | 'b1 | 'B0 | 'B1 | 1 | 0
饶先宏's avatar
饶先宏 已提交
3943 3944
*/

3945 3946 3947 3948
/*
A.8 Expressions
A.8.1 Concatenations
*/
饶先宏's avatar
饶先宏 已提交
3949 3950
concatenation : 
    '{' expression_list '}' {
饶先宏's avatar
饶先宏 已提交
3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963
        $$ = verilogparseCreateConcatExpr(
        verilogparseCreateIntExpr(1),//HOBJECT multicount,
        $2 //IDListVarPtr expr_list
        );
    }
  ;

multiple_concatenation : 
    '{' constant_expression '{' expression_list '}' '}' {
        $$ = verilogparseCreateConcatExpr(
        $2,//HOBJECT multicount,
        $4 //IDListVarPtr expr_list
        );
饶先宏's avatar
饶先宏 已提交
3964 3965 3966 3967 3968
    }
  ;

constant_expression_list :
    constant_expression {
饶先宏's avatar
饶先宏 已提交
3969 3970
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
饶先宏's avatar
饶先宏 已提交
3971 3972
    }
|   constant_expression_list ',' constant_expression {
饶先宏's avatar
饶先宏 已提交
3973 3974
    $$ = $1;
    dlistAppendItem($$, $3);
饶先宏's avatar
饶先宏 已提交
3975 3976 3977 3978 3979
    }
  ;

constant_concatenation : 
    '{' constant_expression_list '}' {
饶先宏's avatar
饶先宏 已提交
3980 3981 3982 3983
        $$ = verilogparseCreateConcatConstantExpr(
        verilogparseCreateIntExpr(1),//HOBJECT multicount,
        $2 //IDListVarPtr expr_list
        );
饶先宏's avatar
饶先宏 已提交
3984 3985 3986 3987
    }
  ;

constant_multiple_concatenation : 
饶先宏's avatar
饶先宏 已提交
3988 3989 3990 3991 3992
    '{' constant_expression '{' constant_expression_list'}'  '}' {
        $$ = verilogparseCreateConcatConstantExpr(
        $2,//HOBJECT multicount,
        $4 //IDListVarPtr expr_list
        );
饶先宏's avatar
饶先宏 已提交
3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013
    }
  ;

module_path_expression_list :
    module_path_expression {
    }
|   module_path_expression_list ',' module_path_expression {
    }
  ;


module_path_concatenation : 
    '{' module_path_expression_list '}' {
    }
  ;

module_path_multiple_concatenation : 
    '{' constant_expression module_path_concatenation '}' {
    }
  ;

4014 4015 4016
/*
A.8.2 Function calls
*/
饶先宏's avatar
饶先宏 已提交
4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033
constant_function_call : 
    function_identifier attribute_instance_list
    '(' constant_expression_list ')' {
    }
  ;

system_function_identifier :
    SYSTEM_ID {
    }
  ;

constant_system_function_call : 
    system_function_identifier
    '(' constant_expression_list ')' {
    }
  ;

4034
/*
饶先宏's avatar
饶先宏 已提交
4035 4036 4037 4038 4039
function_call : 
    hierarchical_function_identifier attribute_instance_list
    '(' expression_list ')' {
    }
  ;
4040 4041
*/
function_call : 
饶先宏's avatar
饶先宏 已提交
4042
    hierarchical_identifier attribute_instance_list
4043 4044 4045 4046
    '(' expression_list ')' {
    }
  ;

饶先宏's avatar
饶先宏 已提交
4047 4048 4049 4050 4051 4052 4053 4054 4055

system_function_call : 
    system_function_identifier {
    }
|   system_function_identifier
    '(' expression_list ')' {
    }
  ;

4056 4057 4058
/*
A.8.3 Expressions
*/
饶先宏's avatar
饶先宏 已提交
4059 4060
base_expression : 
    expression {
饶先宏's avatar
饶先宏 已提交
4061
        $$ = $1;
饶先宏's avatar
饶先宏 已提交
4062 4063 4064 4065 4066
    }
  ;

conditional_expression : 
    expression '?' attribute_instance_list expression ':' expression {
饶先宏's avatar
饶先宏 已提交
4067 4068 4069 4070 4071
        $$ = verilogparseCreateIfopExpr(
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $6, //HOBJECT expr2,
        $3 //IDListVarPtr attributes
饶先宏's avatar
饶先宏 已提交
4072
        );
饶先宏's avatar
饶先宏 已提交
4073 4074 4075 4076 4077
    }
  ;

constant_base_expression : 
    constant_expression {
饶先宏's avatar
饶先宏 已提交
4078
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
4079 4080 4081
    }
  ;

4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388
unary_constant_expression :
    constant_primary {
        $$ = $1;
    }
|   unary_operator attribute_instance_list unary_constant_expression { 
    /*规范中是unary_operator attribute_instance_list primary, 似乎有点不大对啊 */
    $$ = verilogparseCreateUnopConstantExpr(
         $1,//int op,
         $3,//HOBJECT expr,
         $2 //IDListVarPtr attributes
        );
    }
 ;

pow_constant_expression :
    unary_constant_expression {
        $$ = $1;
    }
|  pow_constant_expression POW attribute_instance_list unary_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_POW, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
 ;

multiplicative_constant_expression :
    pow_constant_expression {
        $$ = $1;
    }
|  multiplicative_constant_expression '*' attribute_instance_list pow_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_MUL, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  multiplicative_constant_expression '/' attribute_instance_list pow_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_DIV, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  multiplicative_constant_expression '%' attribute_instance_list pow_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_MOD, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
    ;


additive_constant_expression :
    multiplicative_constant_expression {
        $$ = $1;
    }
|  additive_constant_expression '+' attribute_instance_list multiplicative_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_PLUS, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  additive_constant_expression '-' attribute_instance_list multiplicative_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_MINUS, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
    ;

shift_constant_expression :
    additive_constant_expression {
        $$ = $1;
    }
|  shift_constant_expression LSL attribute_instance_list additive_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_LSL, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  shift_constant_expression LSR attribute_instance_list additive_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_LSR, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  shift_constant_expression ASL attribute_instance_list additive_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_ASL, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  shift_constant_expression ASR attribute_instance_list additive_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_ASR, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;

relational_constant_expression :
    shift_constant_expression {
        $$ = $1;
    }
|  relational_constant_expression '>' attribute_instance_list shift_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_GT, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  relational_constant_expression '<' attribute_instance_list shift_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_LT, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  relational_constant_expression GTE attribute_instance_list shift_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_GTE, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  relational_constant_expression LTE attribute_instance_list shift_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_LTE, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;

equality_constant_expression :
    relational_constant_expression {
        $$ = $1;
    }
|  equality_constant_expression L_EQ attribute_instance_list relational_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_L_EQ, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  equality_constant_expression C_EQ attribute_instance_list relational_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_C_EQ, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  equality_constant_expression L_NEQ attribute_instance_list relational_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_L_NEQ, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  equality_constant_expression C_NEQ attribute_instance_list relational_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_C_NEQ, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;

and_constant_expression :
    equality_constant_expression {
        $$ = $1;
    }
|  and_constant_expression '&' attribute_instance_list equality_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_B_AND, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  and_constant_expression B_NAND attribute_instance_list equality_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_B_NAND, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;


exclusive_or_constant_expression :
    and_constant_expression {
        $$ = $1;
    }
|  exclusive_or_constant_expression '^' attribute_instance_list and_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_B_XOR, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  exclusive_or_constant_expression B_EQU attribute_instance_list and_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_B_EQU, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;


inclusive_or_constant_expression :
    exclusive_or_constant_expression {
        $$ = $1;
    }
|  inclusive_or_constant_expression '|' attribute_instance_list exclusive_or_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_B_OR, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  inclusive_or_constant_expression B_NOR attribute_instance_list exclusive_or_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_B_NOR, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;

logical_and_constant_expression :
    inclusive_or_constant_expression {
        $$ = $1;
    }
|  logical_and_constant_expression L_AND attribute_instance_list inclusive_or_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_L_AND, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;

logical_or_constant_expression :
    logical_and_constant_expression {
        $$ = $1;
    }
|   logical_or_constant_expression L_OR attribute_instance_list logical_and_constant_expression {
    $$ = verilogparseCreateBinopConstantExpr(
        OP_L_OR, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
    ;

constant_expression : 
    logical_or_constant_expression {
        $$ = $1;
    }
| constant_expression '?' attribute_instance_list constant_expression ':' constant_expression {
    $$ = verilogparseCreateIfopConstantExpr(
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $6, //HOBJECT expr2,
        $3 //IDListVarPtr attributes
        );
    }

   ;

/*
饶先宏's avatar
饶先宏 已提交
4389 4390
constant_expression :
    constant_primary {
4391
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
4392 4393
    }
|   unary_operator attribute_instance_list constant_primary {
饶先宏's avatar
饶先宏 已提交
4394 4395 4396 4397
    $$ = verilogparseCreateUnopExpr(
         $1,//int op,
         $3,//HOBJECT expr,
         $2 //IDListVarPtr attributes
4398
        );
饶先宏's avatar
饶先宏 已提交
4399 4400
    }
|   constant_expression binary_operator attribute_instance_list constant_expression {
饶先宏's avatar
饶先宏 已提交
4401 4402 4403 4404 4405
    $$ = verilogparseCreateBinopExpr(
        $2, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
4406
        );
饶先宏's avatar
饶先宏 已提交
4407 4408
    }
|   constant_expression '?' attribute_instance_list constant_expression ':' constant_expression {
饶先宏's avatar
饶先宏 已提交
4409 4410 4411 4412 4413
    $$ = verilogparseCreateIfopExpr(
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $6, //HOBJECT expr2,
        $3 //IDListVarPtr attributes
4414
        );
饶先宏's avatar
饶先宏 已提交
4415 4416
    }
  ;
4417
*/
饶先宏's avatar
饶先宏 已提交
4418 4419 4420

constant_mintypmax_expression :
    constant_expression {
饶先宏's avatar
饶先宏 已提交
4421
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
4422 4423
    }
|   constant_expression ':' constant_expression ':' constant_expression {
饶先宏's avatar
饶先宏 已提交
4424
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
4425 4426 4427 4428 4429
    }
  ;

constant_range_expression :
    constant_expression {
饶先宏's avatar
饶先宏 已提交
4430
    $$.type = RANGE_TYPE_BITSELECT;
饶先宏's avatar
饶先宏 已提交
4431 4432
    $$.obj[0] = $1;
    $$.obj[1] = NULL;
饶先宏's avatar
饶先宏 已提交
4433 4434
    }
|   msb_constant_expression ':' lsb_constant_expression {
饶先宏's avatar
饶先宏 已提交
4435
    $$.type = RANGE_TYPE_PARTSELECT;
饶先宏's avatar
饶先宏 已提交
4436 4437
    $$.obj[0] = $1;
    $$.obj[1] = $3;
饶先宏's avatar
饶先宏 已提交
4438
    }
饶先宏's avatar
饶先宏 已提交
4439 4440
|   constant_base_expression STARTPLUSWIDTH width_constant_expression {
    $$.type = RANGE_TYPE_STARTPLUSWIDTH;
饶先宏's avatar
饶先宏 已提交
4441
    $$.obj[0] = $1;
饶先宏's avatar
饶先宏 已提交
4442
    $$.obj[1] = $3;
饶先宏's avatar
饶先宏 已提交
4443
    }
饶先宏's avatar
饶先宏 已提交
4444 4445
|   constant_base_expression STARTMINUSWIDTH width_constant_expression {
    $$.type = RANGE_TYPE_STARTMINUSWIDTH;
饶先宏's avatar
饶先宏 已提交
4446
    $$.obj[0] = $1;
饶先宏's avatar
饶先宏 已提交
4447
    $$.obj[1] = $3;
饶先宏's avatar
饶先宏 已提交
4448 4449 4450 4451 4452
    }
  ;

dimension_constant_expression :
    constant_expression {
饶先宏's avatar
饶先宏 已提交
4453
     $$ = $1;
饶先宏's avatar
饶先宏 已提交
4454 4455 4456
    }
  ;

饶先宏's avatar
饶先宏 已提交
4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476
unary_expression :
    primary {
        $$ = $1;
    }
|   unary_operator attribute_instance_list unary_expression { 
    /*规范中是unary_operator attribute_instance_list primary, 似乎有点不大对啊 */
    $$ = verilogparseCreateUnopExpr(
         $1,//int op,
         $3,//HOBJECT expr,
         $2 //IDListVarPtr attributes
        );
    }
 ;

pow_expression :
    unary_expression {
        $$ = $1;
    }
|  pow_expression POW attribute_instance_list unary_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4477
        OP_POW, //int op,
饶先宏's avatar
饶先宏 已提交
4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
 ;

multiplicative_expression :
    pow_expression {
        $$ = $1;
    }
|  multiplicative_expression '*' attribute_instance_list pow_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4491
        OP_MUL, //int op,
饶先宏's avatar
饶先宏 已提交
4492 4493 4494 4495 4496 4497 4498
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  multiplicative_expression '/' attribute_instance_list pow_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4499
        OP_DIV, //int op,
饶先宏's avatar
饶先宏 已提交
4500 4501 4502 4503 4504 4505 4506
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  multiplicative_expression '%' attribute_instance_list pow_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4507
        OP_MOD, //int op,
饶先宏's avatar
饶先宏 已提交
4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
    ;


additive_expression :
    multiplicative_expression {
        $$ = $1;
    }
|  additive_expression '+' attribute_instance_list multiplicative_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4522
        OP_PLUS, //int op,
饶先宏's avatar
饶先宏 已提交
4523 4524 4525 4526 4527 4528 4529
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  additive_expression '-' attribute_instance_list multiplicative_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4530
        OP_MINUS, //int op,
饶先宏's avatar
饶先宏 已提交
4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
    ;

shift_expression :
    additive_expression {
        $$ = $1;
    }
|  shift_expression LSL attribute_instance_list additive_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4544
        OP_LSL, //int op,
饶先宏's avatar
饶先宏 已提交
4545 4546 4547 4548 4549 4550 4551
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  shift_expression LSR attribute_instance_list additive_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4552
        OP_LSR, //int op,
饶先宏's avatar
饶先宏 已提交
4553 4554 4555 4556 4557 4558 4559
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  shift_expression ASL attribute_instance_list additive_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4560
        OP_ASL, //int op,
饶先宏's avatar
饶先宏 已提交
4561 4562 4563 4564 4565 4566 4567
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  shift_expression ASR attribute_instance_list additive_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4568
        OP_ASR, //int op,
饶先宏's avatar
饶先宏 已提交
4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;

relational_expression :
    shift_expression {
        $$ = $1;
    }
|  relational_expression '>' attribute_instance_list shift_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4582
        OP_GT, //int op,
饶先宏's avatar
饶先宏 已提交
4583 4584 4585 4586 4587 4588 4589
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  relational_expression '<' attribute_instance_list shift_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4590
        OP_LT, //int op,
饶先宏's avatar
饶先宏 已提交
4591 4592 4593 4594 4595 4596 4597
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  relational_expression GTE attribute_instance_list shift_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4598
        OP_GTE, //int op,
饶先宏's avatar
饶先宏 已提交
4599 4600 4601 4602 4603 4604 4605
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  relational_expression LTE attribute_instance_list shift_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4606
        OP_LTE, //int op,
饶先宏's avatar
饶先宏 已提交
4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;

equality_expression :
    relational_expression {
        $$ = $1;
    }
|  equality_expression L_EQ attribute_instance_list relational_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4620
        OP_L_EQ, //int op,
饶先宏's avatar
饶先宏 已提交
4621 4622 4623 4624 4625 4626 4627
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  equality_expression C_EQ attribute_instance_list relational_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4628
        OP_C_EQ, //int op,
饶先宏's avatar
饶先宏 已提交
4629 4630 4631 4632 4633 4634 4635
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  equality_expression L_NEQ attribute_instance_list relational_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4636
        OP_L_NEQ, //int op,
饶先宏's avatar
饶先宏 已提交
4637 4638 4639 4640 4641 4642 4643
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  equality_expression C_NEQ attribute_instance_list relational_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4644
        OP_C_NEQ, //int op,
饶先宏's avatar
饶先宏 已提交
4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;

and_expression :
    equality_expression {
        $$ = $1;
    }
|  and_expression '&' attribute_instance_list equality_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4658
        OP_B_AND, //int op,
饶先宏's avatar
饶先宏 已提交
4659 4660 4661 4662 4663 4664 4665
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  and_expression B_NAND attribute_instance_list equality_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4666
        OP_B_NAND, //int op,
饶先宏's avatar
饶先宏 已提交
4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;


exclusive_or_expression :
    and_expression {
        $$ = $1;
    }
|  exclusive_or_expression '^' attribute_instance_list and_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4681
        OP_B_XOR, //int op,
饶先宏's avatar
饶先宏 已提交
4682 4683 4684 4685 4686 4687 4688
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  exclusive_or_expression B_EQU attribute_instance_list and_expression {
    $$ = verilogparseCreateBinopExpr(
饶先宏's avatar
饶先宏 已提交
4689
        OP_B_EQU, //int op,
饶先宏's avatar
饶先宏 已提交
4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;


inclusive_or_expression :
    exclusive_or_expression {
        $$ = $1;
    }
|  inclusive_or_expression '|' attribute_instance_list exclusive_or_expression {
    $$ = verilogparseCreateBinopExpr(
        OP_B_OR, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
|  inclusive_or_expression B_NOR attribute_instance_list exclusive_or_expression {
    $$ = verilogparseCreateBinopExpr(
        OP_B_NOR, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;

logical_and_expression :
    inclusive_or_expression {
        $$ = $1;
    }
|  logical_and_expression L_AND attribute_instance_list inclusive_or_expression {
    $$ = verilogparseCreateBinopExpr(
        OP_L_AND, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
  ;

logical_or_expression :
    logical_and_expression {
        $$ = $1;
    }
|   logical_or_expression L_OR attribute_instance_list logical_and_expression {
    $$ = verilogparseCreateBinopExpr(
        OP_L_OR, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
        );
    }
    ;

expression : 
    logical_or_expression {
        $$ = $1;
    }
饶先宏's avatar
饶先宏 已提交
4752
|   conditional_expression {
饶先宏's avatar
饶先宏 已提交
4753 4754 4755 4756
        $$ = $1;
    }
   ;
/*
饶先宏's avatar
饶先宏 已提交
4757 4758
expression :
    primary {
饶先宏's avatar
饶先宏 已提交
4759
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
4760 4761
    }
|   unary_operator attribute_instance_list primary {
饶先宏's avatar
饶先宏 已提交
4762 4763 4764 4765
    $$ = verilogparseCreateUnopExpr(
         $1,//int op,
         $3,//HOBJECT expr,
         $2 //IDListVarPtr attributes
饶先宏's avatar
饶先宏 已提交
4766
        );
饶先宏's avatar
饶先宏 已提交
4767 4768
    }
|   expression binary_operator attribute_instance_list expression {
饶先宏's avatar
饶先宏 已提交
4769 4770 4771 4772 4773
    $$ = verilogparseCreateBinopExpr(
        $2, //int op,
        $1, //HOBJECT expr0,
        $4, //HOBJECT expr1,
        $3  //IDListVarPtr attributes
饶先宏's avatar
饶先宏 已提交
4774
        );
饶先宏's avatar
饶先宏 已提交
4775 4776
    }
|   conditional_expression {
饶先宏's avatar
饶先宏 已提交
4777
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
4778 4779
    }
  ;
饶先宏's avatar
饶先宏 已提交
4780
*/
饶先宏's avatar
饶先宏 已提交
4781 4782

/*
4783 4784 4785
expression1 ::= expression
expression2 ::= expression
expression3 ::= expression
饶先宏's avatar
饶先宏 已提交
4786 4787 4788 4789
*/

lsb_constant_expression : 
    constant_expression {
4790
      $$ = $1;
饶先宏's avatar
饶先宏 已提交
4791 4792 4793 4794 4795
    }
  ;

mintypmax_expression :
    expression {
饶先宏's avatar
饶先宏 已提交
4796 4797
      $$.objcount = 1;
      $$.obj[0] = $1;
饶先宏's avatar
饶先宏 已提交
4798 4799
    }
|   expression ':' expression ':' expression {
饶先宏's avatar
饶先宏 已提交
4800 4801 4802 4803
      $$.objcount = 3;
      $$.obj[0] = $1;
      $$.obj[1] = $3;
      $$.obj[2] = $5;
饶先宏's avatar
饶先宏 已提交
4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833
    }
  ;

module_path_conditional_expression : 
    module_path_expression '?' attribute_instance_list
    module_path_expression ':' module_path_expression {
    }
  ;

module_path_expression :
    module_path_primary {
    }
|   unary_module_path_operator attribute_instance_list module_path_primary {
    }
|   module_path_expression binary_module_path_operator 
    attribute_instance_list module_path_expression {
    }
|   module_path_conditional_expression {
    }
  ;

module_path_mintypmax_expression :
    module_path_expression {
    }
|   module_path_expression ':' module_path_expression ':' module_path_expression {
    }
  ;

msb_constant_expression : 
    constant_expression {
4834
        $$ = $1;
饶先宏's avatar
饶先宏 已提交
4835 4836 4837 4838 4839 4840
    }
  ;

range_expression :
    expression {
    }
饶先宏's avatar
饶先宏 已提交
4841
|   constant_expression ':' lsb_constant_expression {
饶先宏's avatar
饶先宏 已提交
4842
    }
饶先宏's avatar
饶先宏 已提交
4843
|   expression STARTPLUSWIDTH width_constant_expression {
饶先宏's avatar
饶先宏 已提交
4844
    }
饶先宏's avatar
饶先宏 已提交
4845
|   expression STARTMINUSWIDTH width_constant_expression {
饶先宏's avatar
饶先宏 已提交
4846 4847 4848 4849 4850
    }
  ;

width_constant_expression : 
    constant_expression {
饶先宏's avatar
饶先宏 已提交
4851
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
4852 4853 4854
    }
  ;

4855 4856 4857
/*
A.8.4 Primaries
*/
饶先宏's avatar
饶先宏 已提交
4858 4859
constant_primary :
    number {
饶先宏's avatar
饶先宏 已提交
4860 4861 4862 4863
        $$ = verilogparseCreateValueExpr(
            EXPRTYPE_NUMBER, //int exprtype,
            $1, //IConstStringVar* value,
            NULL //IDListVarPtr attributes
4864
        );
饶先宏's avatar
饶先宏 已提交
4865 4866
    }
|   parameter_identifier {
饶先宏's avatar
饶先宏 已提交
4867 4868 4869 4870 4871 4872 4873
        $$ = verilogparseCreateParamExpr(
            EXPRTYPE_PARAM, //int exprtype,
            $1, //IConstStringVar* name,
            RANGE_TYPE_NONE, //int range_type,
            NULL, //HOBJECT range_msb,
            NULL, //HOBJECT range_lsb,
            NULL //IDListVarPtr attributes
4874
        );
饶先宏's avatar
饶先宏 已提交
4875 4876
    }
|   parameter_identifier '[' constant_range_expression ']' {
饶先宏's avatar
饶先宏 已提交
4877 4878 4879 4880 4881 4882 4883 4884
        $$ = verilogparseCreateParamExpr(
            EXPRTYPE_PARAM, //int exprtype,
            $1, //IConstStringVar* name,
            $3.type, //int range_type,
            $3.obj[0], //HOBJECT range_msb,
            $3.obj[1], //HOBJECT range_lsb,
            NULL //IDListVarPtr attributes
        );
饶先宏's avatar
饶先宏 已提交
4885 4886
    }
|   specparam_identifier  {
饶先宏's avatar
饶先宏 已提交
4887
        $$ = NULL;
饶先宏's avatar
饶先宏 已提交
4888 4889
    }
|   specparam_identifier '[' constant_range_expression ']' {
饶先宏's avatar
饶先宏 已提交
4890
        $$ = NULL;
饶先宏's avatar
饶先宏 已提交
4891 4892
    }
|   constant_concatenation {
饶先宏's avatar
饶先宏 已提交
4893
        $$ = $1;
饶先宏's avatar
饶先宏 已提交
4894 4895
    }
|   constant_multiple_concatenation {
饶先宏's avatar
饶先宏 已提交
4896
        $$ = $1;
饶先宏's avatar
饶先宏 已提交
4897 4898
    }
|   constant_function_call {
饶先宏's avatar
饶先宏 已提交
4899
        $$ = NULL;
饶先宏's avatar
饶先宏 已提交
4900 4901
    }
|   constant_system_function_call {
饶先宏's avatar
饶先宏 已提交
4902
        $$ = NULL;
饶先宏's avatar
饶先宏 已提交
4903 4904
    }
|   '(' constant_mintypmax_expression ')' {
饶先宏's avatar
饶先宏 已提交
4905
        $$ = $2;
饶先宏's avatar
饶先宏 已提交
4906 4907
    }
|   string {
饶先宏's avatar
饶先宏 已提交
4908 4909 4910 4911
        $$ = verilogparseCreateValueExpr(
            EXPRTYPE_STRING, //int exprtype,
            $1, //IConstStringVar* value,
            NULL //IDListVarPtr attributes
4912
        );
饶先宏's avatar
饶先宏 已提交
4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933
    }
  ;

module_path_primary :
    number {
    }
|   identifier {
    }
|   module_path_concatenation {
    }
|   module_path_multiple_concatenation {
    }
|   function_call {
    }
|   system_function_call {
    }
|   '(' module_path_mintypmax_expression ')' {
    }
  ;

array_element_select :
4934
     %empty   {
饶先宏's avatar
饶先宏 已提交
4935 4936 4937 4938 4939 4940 4941 4942
    }
|   '[' expression ']' {
    }
|   array_element_select '[' expression ']' {
    }
  ;

range_expression_option :
4943
      %empty  {
饶先宏's avatar
饶先宏 已提交
4944
    }
饶先宏's avatar
饶先宏 已提交
4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958
| '[' range_expression ']' {
    }
  ;

range_expression_list :
      %empty  {
    }
| '[' range_expression ']' {
    }
| range_expression_list '[' range_expression ']' {
     /*
     此时要判断前面的作为array_element_select只能由一个表达式组成,
     不能是两个表达式表示的段选择
     */
饶先宏's avatar
饶先宏 已提交
4959 4960 4961
    }
  ;

饶先宏's avatar
饶先宏 已提交
4962 4963 4964 4965
/*
  不满足LALR(1)的文法,只能够由后期判断了
|   hierarchical_identifier array_element_select range_expression_option {
    }
饶先宏's avatar
饶先宏 已提交
4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985

    hierachical_header:
    identifier '.' {
    }
|   identifier '[' constant_expression ']' '.' {
    }
|   hierachical_header identifier '.' {
    }
|   hierachical_header identifier '[' constant_expression ']' '.' {
    }
 ;
    
hierarchical_identifier : 
  hierachical_header identifier {
  }
| identifier {
  }
 ;
*/

饶先宏's avatar
饶先宏 已提交
4986
hierarchical_identifier_part :
饶先宏's avatar
饶先宏 已提交
4987
    identifier {
饶先宏's avatar
饶先宏 已提交
4988
    $$ = verilogparseCreateVarSel(
4989 4990 4991 4992 4993
        $1, //const char * name,
        RANGE_TYPE_NONE, //int range_type,
        NULL, //HOBJECT range_msb,
        NULL  //HOBJECT range_lsb
       );
饶先宏's avatar
饶先宏 已提交
4994 4995
    }
|   identifier '[' expression ']' {
饶先宏's avatar
饶先宏 已提交
4996
    $$ = verilogparseCreateVarSel(
4997 4998 4999 5000 5001
        $1, //const char * name,
        RANGE_TYPE_BITSELECT, //int range_type,
        $3,  // HOBJECT range_msb,
        NULL //HOBJECT range_lsb
       );
饶先宏's avatar
饶先宏 已提交
5002 5003
    }
|   identifier '[' expression ':' expression ']' {
饶先宏's avatar
饶先宏 已提交
5004
    $$ = verilogparseCreateVarSel(
5005 5006 5007 5008 5009
        $1, //const char * name,
        RANGE_TYPE_PARTSELECT, //int range_type,
        $3,  // HOBJECT range_msb,
        $5   //HOBJECT range_lsb
       );
饶先宏's avatar
饶先宏 已提交
5010 5011
    }
|   identifier '[' expression STARTPLUSWIDTH expression ']' {
饶先宏's avatar
饶先宏 已提交
5012
    $$ = verilogparseCreateVarSel(
5013 5014 5015 5016 5017
        $1, //const char * name,
        RANGE_TYPE_STARTPLUSWIDTH, //int range_type,
        $3,  // HOBJECT range_msb,
        $5   //HOBJECT range_lsb
       );
饶先宏's avatar
饶先宏 已提交
5018 5019
    }
|   identifier '[' expression STARTMINUSWIDTH expression ']' {
饶先宏's avatar
饶先宏 已提交
5020
    $$ = verilogparseCreateVarSel(
5021 5022 5023 5024 5025
        $1, //const char * name,
        RANGE_TYPE_STARTMINUSWIDTH, //int range_type,
        $3,  // HOBJECT range_msb,
        $5   //HOBJECT range_lsb
       );
饶先宏's avatar
饶先宏 已提交
5026 5027 5028 5029
    }
  ;

var :
饶先宏's avatar
饶先宏 已提交
5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045
  hierarchical_identifier {
    $$.type = RANGE_TYPE_NONE;
    $$.obj[0] = $1;
    $$.obj[1] = dlistCreate();
  }
|  var '[' expression ']' {
    $$ = $1;
    $$.type = RANGE_TYPE_BITSELECT;
    dlistAppendItem($$.obj[1], $3);
    dlistAppendItem($$.obj[1], $3);
  }
|  var '[' expression ':' expression ']' {
    $$ = $1;
    $$.type = RANGE_TYPE_PARTSELECT; /*只记录最后一次的类型,反正这种情况只有最后一次才会出现*/
    dlistAppendItem($$.obj[1], $3);
    dlistAppendItem($$.obj[1], $5);
饶先宏's avatar
饶先宏 已提交
5046
    }
饶先宏's avatar
饶先宏 已提交
5047
|  var '[' expression STARTPLUSWIDTH expression ']' {
饶先宏's avatar
饶先宏 已提交
5048
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068
    $$.type = RANGE_TYPE_STARTPLUSWIDTH;
    dlistAppendItem($$.obj[1], $3);
    dlistAppendItem($$.obj[1], $5);
    }
|  var '[' expression STARTMINUSWIDTH expression ']' {
    $$ = $1;
    $$.type = RANGE_TYPE_STARTMINUSWIDTH;
    dlistAppendItem($$.obj[1], $3);
    dlistAppendItem($$.obj[1], $5);
    }
  ;

hierarchical_identifier :
    hierarchical_identifier_part {
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
    }
|   hierarchical_identifier '.' hierarchical_identifier_part {
    $$ = $1;
    dlistAppendItem($$, $3);
饶先宏's avatar
饶先宏 已提交
5069 5070
    }
  ;
饶先宏's avatar
饶先宏 已提交
5071

饶先宏's avatar
饶先宏 已提交
5072 5073
/*
    hierarchical_identifier array_element_select range_expression_option
饶先宏's avatar
饶先宏 已提交
5074
*/
饶先宏's avatar
饶先宏 已提交
5075

饶先宏's avatar
饶先宏 已提交
5076 5077
primary :
    number {
饶先宏's avatar
饶先宏 已提交
5078 5079 5080 5081
        $$ = verilogparseCreateValueExpr(
            EXPRTYPE_NUMBER, //int exprtype,
            $1, //IConstStringVar* value,
            NULL //IDListVarPtr attributes
饶先宏's avatar
饶先宏 已提交
5082
        );
饶先宏's avatar
饶先宏 已提交
5083
    }
饶先宏's avatar
饶先宏 已提交
5084
|   var {
饶先宏's avatar
饶先宏 已提交
5085 5086 5087 5088 5089 5090 5091 5092
        $$ = verilogparseCreateVariableExpr(
            EXPRTYPE_HIERARCHICAL_IDENT,
            $1.obj[0], //IDListVarPtr hierarchical_identifier,
            $1.obj[1], //IDListVarPtr elementselect,
            $1.type, //int range_type,
            NULL, //HOBJECT range_msb,
            NULL, //HOBJECT range_lsb,
            NULL //IDListVarPtr attributes
饶先宏's avatar
饶先宏 已提交
5093
        );
饶先宏's avatar
饶先宏 已提交
5094 5095
    }
|   concatenation {
饶先宏's avatar
饶先宏 已提交
5096
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
5097 5098
    }
|   multiple_concatenation {
饶先宏's avatar
饶先宏 已提交
5099
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
5100
    }
5101 5102

|   function_call{ 
饶先宏's avatar
饶先宏 已提交
5103 5104
    $$ = NULL;
    yyerror("no support for function_call");
饶先宏's avatar
饶先宏 已提交
5105 5106
    }
|   system_function_call {
饶先宏's avatar
饶先宏 已提交
5107 5108
    $$ = NULL;
    yyerror("no support for system_function_call");
饶先宏's avatar
饶先宏 已提交
5109
    }
5110

饶先宏's avatar
饶先宏 已提交
5111
|   '(' mintypmax_expression ')' {
饶先宏's avatar
饶先宏 已提交
5112 5113 5114 5115
    $$ = $2.obj[0];
    if ($2.objcount > 1) {
        yyerror("no supprot for mintypmax_expression when objcount > 1");
    }
饶先宏's avatar
饶先宏 已提交
5116 5117
    }
|   string {
饶先宏's avatar
饶先宏 已提交
5118 5119 5120 5121
        $$ = verilogparseCreateValueExpr(
            EXPRTYPE_STRING, //int exprtype,
            $1, //IConstStringVar* value,
            NULL //IDListVarPtr attributes
饶先宏's avatar
饶先宏 已提交
5122
        );
饶先宏's avatar
饶先宏 已提交
5123 5124 5125
    }
  ;

5126 5127 5128
/*
A.8.5 Expression left-side values
*/
饶先宏's avatar
饶先宏 已提交
5129
const_array_element_select :
5130
     %empty   {
饶先宏's avatar
饶先宏 已提交
5131 5132 5133 5134 5135 5136 5137 5138
    }
|   '[' constant_expression ']' {
    }
|   const_array_element_select '[' constant_expression ']' {
    }
  ;

constant_range_expression_option :
5139
     %empty   {
饶先宏's avatar
饶先宏 已提交
5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172
    }
| range_expression {
    }
  ;

net_lvalue_list :
    net_lvalue {
    }
|   net_lvalue_list ',' net_lvalue {
    }
  ;

net_lvalue :
    hierarchical_net_identifier const_array_element_select constant_range_expression_option {
    }
|   '{' net_lvalue_list '}' {
    }
  ;

variable_lvalue_list :
    variable_lvalue {
    }
|   variable_lvalue_list ',' variable_lvalue {
    }
  ;

variable_lvalue :
    hierarchical_variable_identifier array_element_select range_expression_option {
    }
|   '{' variable_lvalue_list '}' {
    }
  ;

5173 5174 5175
/*
A.8.6 Operators
*/
饶先宏's avatar
饶先宏 已提交
5176

5177
unary_operator :
饶先宏's avatar
饶先宏 已提交
5178
    '+'  {
饶先宏's avatar
饶先宏 已提交
5179
    $$ = OP_PLUS;
饶先宏's avatar
饶先宏 已提交
5180 5181
    }
|   '-'  {
饶先宏's avatar
饶先宏 已提交
5182
    $$ = OP_MINUS;
饶先宏's avatar
饶先宏 已提交
5183 5184
    }
|   '!'  {
饶先宏's avatar
饶先宏 已提交
5185
    $$ = OP_L_NOT;
饶先宏's avatar
饶先宏 已提交
5186 5187
    }
|   '~'  {
饶先宏's avatar
饶先宏 已提交
5188
    $$ = OP_B_NOT;
饶先宏's avatar
饶先宏 已提交
5189 5190
    }
|   '&'  {
饶先宏's avatar
饶先宏 已提交
5191
    $$ = OP_B_AND;
饶先宏's avatar
饶先宏 已提交
5192 5193
    }
|   B_NAND {
饶先宏's avatar
饶先宏 已提交
5194
    $$ = OP_B_NAND;
饶先宏's avatar
饶先宏 已提交
5195 5196
    } 
|   '|' {
饶先宏's avatar
饶先宏 已提交
5197
    $$ = OP_B_OR;
饶先宏's avatar
饶先宏 已提交
5198 5199
    } 
|   B_NOR {
饶先宏's avatar
饶先宏 已提交
5200
    $$ = OP_B_NOR;
饶先宏's avatar
饶先宏 已提交
5201 5202
    } 
|   '^' {
饶先宏's avatar
饶先宏 已提交
5203
    $$ = OP_B_XOR;
饶先宏's avatar
饶先宏 已提交
5204 5205
    } 
|   B_EQU  {
饶先宏's avatar
饶先宏 已提交
5206
    $$ = OP_B_EQU;
饶先宏's avatar
饶先宏 已提交
5207 5208
    }
  ;
饶先宏's avatar
饶先宏 已提交
5209

5210
binary_operator :
饶先宏's avatar
饶先宏 已提交
5211
    '+' {
饶先宏's avatar
饶先宏 已提交
5212
    $$ = OP_PLUS;
饶先宏's avatar
饶先宏 已提交
5213 5214
    }
|   '-' {
饶先宏's avatar
饶先宏 已提交
5215
    $$ = OP_MINUS;
饶先宏's avatar
饶先宏 已提交
5216 5217
    }
|   '*'  {
饶先宏's avatar
饶先宏 已提交
5218
    $$ = OP_MUL;
饶先宏's avatar
饶先宏 已提交
5219 5220
    }
|   '/' {
饶先宏's avatar
饶先宏 已提交
5221
    $$ = OP_DIV;
饶先宏's avatar
饶先宏 已提交
5222 5223
    } 
|   '%' {
饶先宏's avatar
饶先宏 已提交
5224
    $$ = OP_MOD;
饶先宏's avatar
饶先宏 已提交
5225 5226
    } 
|   L_EQ {
饶先宏's avatar
饶先宏 已提交
5227
    $$ = OP_L_EQ;
饶先宏's avatar
饶先宏 已提交
5228 5229
    }
|   L_NEQ {
饶先宏's avatar
饶先宏 已提交
5230
    $$ = OP_L_NEQ;
饶先宏's avatar
饶先宏 已提交
5231 5232
    }
|   C_EQ {
饶先宏's avatar
饶先宏 已提交
5233
    $$ = OP_C_EQ;
饶先宏's avatar
饶先宏 已提交
5234 5235
    } 
|   C_NEQ {
饶先宏's avatar
饶先宏 已提交
5236
    $$ = OP_C_NEQ;
饶先宏's avatar
饶先宏 已提交
5237 5238
    } 
|   L_AND  {
饶先宏's avatar
饶先宏 已提交
5239
    $$ = OP_L_AND;
饶先宏's avatar
饶先宏 已提交
5240 5241
    }
|   L_OR  {
饶先宏's avatar
饶先宏 已提交
5242
    $$ = OP_L_OR;
饶先宏's avatar
饶先宏 已提交
5243 5244
    }
|   POW {
饶先宏's avatar
饶先宏 已提交
5245
    $$ = OP_POW;
饶先宏's avatar
饶先宏 已提交
5246 5247
    }
|   '<' {
饶先宏's avatar
饶先宏 已提交
5248
    $$ = OP_LT;
饶先宏's avatar
饶先宏 已提交
5249 5250
    } 
|   LTE  {
饶先宏's avatar
饶先宏 已提交
5251
    $$ = OP_LTE;
饶先宏's avatar
饶先宏 已提交
5252 5253
    }
|   '>' {
饶先宏's avatar
饶先宏 已提交
5254
    $$ = OP_GT;
饶先宏's avatar
饶先宏 已提交
5255 5256
    } 
|   GTE  {
饶先宏's avatar
饶先宏 已提交
5257
    $$ = OP_GTE;
饶先宏's avatar
饶先宏 已提交
5258 5259
    }
|   '&' {
饶先宏's avatar
饶先宏 已提交
5260
    $$ = OP_B_AND;
饶先宏's avatar
饶先宏 已提交
5261 5262
    } 
|   '|' {
饶先宏's avatar
饶先宏 已提交
5263
    $$ = OP_B_OR;
饶先宏's avatar
饶先宏 已提交
5264 5265
    } 
|   '^' {
饶先宏's avatar
饶先宏 已提交
5266
    $$ = OP_B_XOR;
饶先宏's avatar
饶先宏 已提交
5267 5268
    } 
|   B_EQU {
饶先宏's avatar
饶先宏 已提交
5269
    $$ = OP_B_EQU;
饶先宏's avatar
饶先宏 已提交
5270 5271
    }
|   LSR  {
饶先宏's avatar
饶先宏 已提交
5272
    $$ = OP_LSR;
饶先宏's avatar
饶先宏 已提交
5273 5274
    }
|   LSL  {
饶先宏's avatar
饶先宏 已提交
5275
    $$ = OP_LSL;
饶先宏's avatar
饶先宏 已提交
5276 5277
    }
|   ASR {
饶先宏's avatar
饶先宏 已提交
5278
    $$ = OP_ASR;
饶先宏's avatar
饶先宏 已提交
5279 5280
    } 
|   ASL {
饶先宏's avatar
饶先宏 已提交
5281
    $$ = OP_ASL;
饶先宏's avatar
饶先宏 已提交
5282
    }
5283
  ;
饶先宏's avatar
饶先宏 已提交
5284

5285
unary_module_path_operator :
饶先宏's avatar
饶先宏 已提交
5286
    '!'  {
饶先宏's avatar
饶先宏 已提交
5287
    $$ = OP_L_NOT;
饶先宏's avatar
饶先宏 已提交
5288 5289
    }
|   '~'  {
饶先宏's avatar
饶先宏 已提交
5290
    $$ = OP_B_NOT;
饶先宏's avatar
饶先宏 已提交
5291 5292
    }
|   '&'  {
饶先宏's avatar
饶先宏 已提交
5293
    $$ = OP_B_AND;
饶先宏's avatar
饶先宏 已提交
5294 5295
    }
|   B_NAND  {
饶先宏's avatar
饶先宏 已提交
5296
    $$ = OP_B_NAND;
饶先宏's avatar
饶先宏 已提交
5297 5298
    }
|   '|'  {
饶先宏's avatar
饶先宏 已提交
5299
    $$ = OP_B_OR;
饶先宏's avatar
饶先宏 已提交
5300 5301
    }
|   B_NOR  {
饶先宏's avatar
饶先宏 已提交
5302
    $$ = OP_B_NOR;
饶先宏's avatar
饶先宏 已提交
5303 5304
    }
|   '^'  {
饶先宏's avatar
饶先宏 已提交
5305
    $$ = OP_B_XOR;
饶先宏's avatar
饶先宏 已提交
5306 5307
    }
|   B_EQU  {
饶先宏's avatar
饶先宏 已提交
5308
    $$ = OP_B_EQU;
饶先宏's avatar
饶先宏 已提交
5309
    }
5310
  ;
饶先宏's avatar
饶先宏 已提交
5311

5312
binary_module_path_operator :
饶先宏's avatar
饶先宏 已提交
5313
    L_EQ  {
饶先宏's avatar
饶先宏 已提交
5314
    $$ = OP_L_EQ;
饶先宏's avatar
饶先宏 已提交
5315 5316
    }
|   L_NEQ {
饶先宏's avatar
饶先宏 已提交
5317
    $$ = OP_L_NEQ;
饶先宏's avatar
饶先宏 已提交
5318 5319
    } 
|   L_AND {
饶先宏's avatar
饶先宏 已提交
5320
    $$ = OP_L_AND;
饶先宏's avatar
饶先宏 已提交
5321 5322
    } 
|   L_OR {
饶先宏's avatar
饶先宏 已提交
5323
    $$ = OP_L_OR;
饶先宏's avatar
饶先宏 已提交
5324 5325
    } 
|   '&' {
饶先宏's avatar
饶先宏 已提交
5326
    $$ = OP_B_AND;
饶先宏's avatar
饶先宏 已提交
5327 5328
    }
|   '|'  {
饶先宏's avatar
饶先宏 已提交
5329
    $$ = OP_B_OR;
饶先宏's avatar
饶先宏 已提交
5330 5331
    }
|   '^'  {
饶先宏's avatar
饶先宏 已提交
5332
    $$ = OP_B_XOR;
饶先宏's avatar
饶先宏 已提交
5333 5334
    }
|   B_EQU  {
饶先宏's avatar
饶先宏 已提交
5335
    $$ = OP_B_EQU;
饶先宏's avatar
饶先宏 已提交
5336
    }
5337
 ;
饶先宏's avatar
饶先宏 已提交
5338

5339 5340 5341
/*
A.8.7 Numbers
*/
饶先宏's avatar
饶先宏 已提交
5342
/*
5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380
number ::=
decimal_number
| octal_number
| binary_number
| hex_number
| real_number
real_number ::=
unsigned_number . unsigned_number
| unsigned_number [ . unsigned_number ] exp [ sign ] unsigned_number
exp ::= e | E
decimal_number ::=
unsigned_number
| [ size ] decimal_base unsigned_number
| [ size ] decimal_base x_digit { _ }
| [ size ] decimal_base z_digit { _ }
binary_number ::= [ size ] binary_base binary_value
octal_number ::= [ size ] octal_base octal_value
hex_number ::= [ size ] hex_base hex_value
sign ::= + | -
size ::= non_zero_unsigned_number
non_zero_unsigned_number2 ::= non_zero_decimal_digit { _ | decimal_digit}
unsigned_number2 ::= decimal_digit { _ | decimal_digit }
binary_value2 ::= binary_digit { _ | binary_digit }
octal_value2 ::= octal_digit { _ | octal_digit }
hex_value2 ::= hex_digit { _ | hex_digit }
decimal_base2 ::= '[s|S]d | '[s|S]D
binary_base2 ::= '[s|S]b | '[s|S]B
octal_base2 ::= '[s|S]o | '[s|S]O
hex_base2 ::= '[s|S]h | '[s|S]H
non_zero_decimal_digit ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
decimal_digit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
binary_digit ::= x_digit | z_digit | 0 | 1
octal_digit ::= x_digit | z_digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
hex_digit ::=
x_digit | z_digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
| a | b | c | d | e | f | A | B | C | D | E | F
x_digit ::= x | X
z_digit ::= z | Z | ?
饶先宏's avatar
饶先宏 已提交
5381 5382 5383 5384
*/

unsigned_number :
  UNSIGNED_NUMBER {
5385
  $$ = $1;
饶先宏's avatar
饶先宏 已提交
5386 5387 5388 5389 5390
  }
;

number :
    NUM_REAL{
5391
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
5392
    }
5393 5394 5395
|   unsigned_number {
    $$ = $1;
    }
饶先宏's avatar
饶先宏 已提交
5396
|   BIN_BASE BIN_VALUE {
饶先宏's avatar
饶先宏 已提交
5397 5398 5399
        $$ = $1;
        hdl4seConstStringAppend($$, conststringFromVar($2));
        objectRelease($2);
饶先宏's avatar
饶先宏 已提交
5400 5401
    }
|   HEX_BASE HEX_VALUE {
饶先宏's avatar
饶先宏 已提交
5402 5403 5404
        $$ = $1;
        hdl4seConstStringAppend($$, conststringFromVar($2));
        objectRelease($2);
饶先宏's avatar
饶先宏 已提交
5405 5406
    }
|   OCT_BASE OCT_VALUE {
饶先宏's avatar
饶先宏 已提交
5407 5408 5409
        $$ = $1;
        hdl4seConstStringAppend($$, conststringFromVar($2));
        objectRelease($2);
饶先宏's avatar
饶先宏 已提交
5410
    }
饶先宏's avatar
饶先宏 已提交
5411
|   DEC_BASE DEC_VALUE {
饶先宏's avatar
饶先宏 已提交
5412 5413 5414
        $$ = $1;
        hdl4seConstStringAppend($$, conststringFromVar($2));
        objectRelease($2);
饶先宏's avatar
饶先宏 已提交
5415 5416
    }
|   UNSIGNED_NUMBER BIN_BASE BIN_VALUE {
饶先宏's avatar
饶先宏 已提交
5417 5418 5419 5420 5421
        $$ = $1;
        hdl4seConstStringAppend($$, conststringFromVar($2));
        hdl4seConstStringAppend($$, conststringFromVar($3));
        objectRelease($2);
        objectRelease($3);
饶先宏's avatar
饶先宏 已提交
5422 5423
    }
|   UNSIGNED_NUMBER HEX_BASE HEX_VALUE {
饶先宏's avatar
饶先宏 已提交
5424 5425 5426 5427 5428
        $$ = $1;
        hdl4seConstStringAppend($$, conststringFromVar($2));
        hdl4seConstStringAppend($$, conststringFromVar($3));
        objectRelease($2);
        objectRelease($3);
饶先宏's avatar
饶先宏 已提交
5429 5430
    }
|   UNSIGNED_NUMBER OCT_BASE OCT_VALUE {
饶先宏's avatar
饶先宏 已提交
5431 5432 5433 5434 5435
        $$ = $1;
        hdl4seConstStringAppend($$, conststringFromVar($2));
        hdl4seConstStringAppend($$, conststringFromVar($3));
        objectRelease($2);
        objectRelease($3);
饶先宏's avatar
饶先宏 已提交
5436
    }
饶先宏's avatar
饶先宏 已提交
5437
|   UNSIGNED_NUMBER DEC_BASE DEC_VALUE{
饶先宏's avatar
饶先宏 已提交
5438 5439 5440 5441 5442
        $$ = $1;
        hdl4seConstStringAppend($$, conststringFromVar($2));
        hdl4seConstStringAppend($$, conststringFromVar($3));
        objectRelease($2);
        objectRelease($3);
饶先宏's avatar
饶先宏 已提交
5443 5444 5445
    }
;

饶先宏's avatar
饶先宏 已提交
5446

5447 5448 5449
/*
A.8.8 Strings
*/
饶先宏's avatar
饶先宏 已提交
5450 5451
string : 
    STRING {
5452
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
5453 5454 5455
    }
  ;

5456 5457 5458 5459 5460 5461
/* string ::= " { Any_ASCII_Characters_except_new_line } " */
/*
A.9 General
A.9.1 Attributes
*/
attribute_instance_list :
5462
     %empty   {
饶先宏's avatar
饶先宏 已提交
5463
        $$ = dlistCreate();
5464 5465
    }
|   attribute_instance_list attribute_instance {
5466
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
5467
    dlistConcat($$, $2);
5468 5469
    }
|   attribute_instance {
5470
        $$ = $1;
5471 5472
    }
 ;
饶先宏's avatar
饶先宏 已提交
5473

5474 5475
attribute_instance : 
    ATTRIBUTE_START attribute_instance_spec_list ATTRIBUTE_END {
5476
    $$ = $2;
5477 5478 5479 5480
    }
 ;
attribute_instance_spec_list : 
    attribute_instance_spec_list ',' attr_spec {
5481
    $$ = $1;
饶先宏's avatar
饶先宏 已提交
5482
    dlistAppendItem($$, $3);
5483 5484
    }
|   attr_spec {
饶先宏's avatar
饶先宏 已提交
5485 5486
    $$ = dlistCreate();
    dlistAppendItem($$, $1);
5487 5488
    }
 ;
饶先宏's avatar
饶先宏 已提交
5489

5490 5491
attr_spec :
    attr_name {
5492
    $$ = verilogparseCreateAttrSpec($1, NULL);
饶先宏's avatar
饶先宏 已提交
5493
    objectRelease($1);
5494 5495
    }
|   attr_name  '=' constant_expression {
5496
    $$ = verilogparseCreateAttrSpec($1, $3);
饶先宏's avatar
饶先宏 已提交
5497
    objectRelease($1);
5498
    objectRelease($3);
5499 5500
    }
  ;
饶先宏's avatar
饶先宏 已提交
5501

5502 5503
attr_name : 
    identifier {
5504
        $$ = $1;
5505 5506 5507 5508 5509
    }
 ;
/*
A.9.2 Comments
*/
饶先宏's avatar
饶先宏 已提交
5510

5511 5512 5513 5514 5515 5516 5517 5518
/*
comment ::=
one_line_comment
| block_comment
one_line_comment ::= // comment_text \n
block_comment ::= / * comment_text * /
comment_text ::= { Any_ASCII_character }
*/
饶先宏's avatar
饶先宏 已提交
5519

5520 5521 5522
/*
A.9.3 Identifiers
*/
饶先宏's avatar
饶先宏 已提交
5523

5524 5525 5526 5527
block_identifier : 
    identifier {
    }
 ;
饶先宏's avatar
饶先宏 已提交
5528

5529 5530 5531 5532
cell_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5533

5534 5535 5536
config_identifier :
    identifier {
    }
饶先宏's avatar
饶先宏 已提交
5537
  ;
饶先宏's avatar
饶先宏 已提交
5538

5539 5540 5541 5542
event_identifier : 
    identifier  {
    }
 ;
饶先宏's avatar
饶先宏 已提交
5543

5544 5545 5546 5547
function_identifier :  
    identifier {
    }
 ;
饶先宏's avatar
饶先宏 已提交
5548

5549 5550 5551 5552
gate_instance_identifier : 
    identifier  {
    }
 ;
饶先宏's avatar
饶先宏 已提交
5553

5554 5555 5556 5557
generate_block_identifier : 
    identifier {
    }
 ;
饶先宏's avatar
饶先宏 已提交
5558

5559 5560
genvar_identifier : 
    identifier {
饶先宏's avatar
饶先宏 已提交
5561
    }
5562
 ;
饶先宏's avatar
饶先宏 已提交
5563

5564 5565 5566 5567
hierarchical_block_identifier : 
    hierarchical_identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5568

5569 5570 5571 5572
hierarchical_event_identifier : 
    hierarchical_identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5573

5574 5575 5576 5577
hierarchical_function_identifier : 
    hierarchical_identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5578

饶先宏's avatar
饶先宏 已提交
5579
/*
5580
hierachical_header:
饶先宏's avatar
饶先宏 已提交
5581
    identifier '.' {
5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593
    }
|   identifier '[' constant_expression ']' '.' {
    }
|   hierachical_header identifier '.' {
    }
|   hierachical_header identifier '[' constant_expression ']' '.' {
    }
 ;
    
hierarchical_identifier : 
  hierachical_header identifier {
  }
饶先宏's avatar
饶先宏 已提交
5594 5595
| identifier {
  }
5596
 ;
饶先宏's avatar
饶先宏 已提交
5597
*/
饶先宏's avatar
饶先宏 已提交
5598

5599 5600 5601 5602
hierarchical_net_identifier : 
    hierarchical_identifier {
    }
 ;
饶先宏's avatar
饶先宏 已提交
5603

5604 5605 5606 5607
hierarchical_parameter_identifier : 
    hierarchical_identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5608

5609 5610 5611 5612
hierarchical_variable_identifier : 
    hierarchical_identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5613

5614 5615 5616 5617
hierarchical_task_identifier : 
    hierarchical_identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5618

5619
identifier :
饶先宏's avatar
饶先宏 已提交
5620
    SIMPLE_ID {
5621
        $$ = $1;
5622
    }
饶先宏's avatar
饶先宏 已提交
5623
|   ESCAPED_ID {
5624
        $$ = $1;
饶先宏's avatar
饶先宏 已提交
5625
    }
5626
  ;
饶先宏's avatar
饶先宏 已提交
5627

5628 5629 5630 5631
inout_port_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5632

5633 5634 5635 5636
input_port_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5637

5638 5639 5640 5641
instance_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5642

5643 5644 5645 5646
library_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5647

5648 5649
module_identifier : 
    identifier {
5650
    $$ = $1;
5651 5652
    }
  ;
饶先宏's avatar
饶先宏 已提交
5653

5654 5655
module_instance_identifier : 
    identifier {
饶先宏's avatar
饶先宏 已提交
5656
    $$ = $1;
5657 5658 5659
    }
 ;
net_identifier : identifier {
饶先宏's avatar
饶先宏 已提交
5660
    $$ = $1;
5661 5662
    }
  ;
饶先宏's avatar
饶先宏 已提交
5663

5664 5665 5666 5667
output_port_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5668

5669 5670
parameter_identifier : 
    identifier {
5671
      $$ = $1;
饶先宏's avatar
饶先宏 已提交
5672
    }
5673
  ;
饶先宏's avatar
饶先宏 已提交
5674

5675 5676
port_identifier : 
    identifier {
饶先宏's avatar
饶先宏 已提交
5677
    $$ = $1;
5678 5679
    }
  ;
饶先宏's avatar
饶先宏 已提交
5680

5681 5682 5683 5684
real_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5685

5686 5687 5688 5689
specparam_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5690

5691 5692 5693 5694
task_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5695

5696 5697 5698 5699
terminal_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5700

饶先宏's avatar
饶先宏 已提交
5701
/* handle by preprocess
5702 5703 5704 5705
text_macro_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5706
*/
饶先宏's avatar
饶先宏 已提交
5707

5708 5709
topmodule_identifier : 
    identifier {
5710
    $$ = $1;
5711 5712
    }
  ;
饶先宏's avatar
饶先宏 已提交
5713

5714 5715 5716 5717
udp_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5718

5719 5720 5721 5722 5723 5724 5725 5726
udp_instance_identifier : 
    identifier {
    }
  ;
variable_identifier : 
    identifier {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5727

5728 5729 5730
/*
A.9.4 White space
*/
饶先宏's avatar
饶先宏 已提交
5731
/*
5732 5733 5734 5735 5736 5737 5738 5739 5740 5741
white_space : 
    space  {
    }
|   tab {
    }
|   newline {
    }
|   eof {
    }
  ;
饶先宏's avatar
饶先宏 已提交
5742
*/
饶先宏's avatar
饶先宏 已提交
5743
%%