%{
#include "attr_type.h"
#include "token_type.h"
#include "memory.h"
#include "symtab.h"
extern int Source_Position;
extern CEntity *ent;
extern CArchitecture *arch;
extern Symtab *port_tab;
extern Symtab *interface_tab;
%}
%token <Tid> ID
%token <Tid> ABSTRACT_LITERAL
%token <Tid> CHARACTER
%token <Tid> STRING
%token <TsrcPos> BIT_STRING_LITERAL
%token <TsrcPos> BIT_VALUE
%token <TsrcPos> KW_ABS
%token <TsrcPos> KW_ACCESS
%token <TsrcPos> KW_AFTER
%token <TsrcPos> KW_ALIAS
%token <TsrcPos> KW_ALL
%token <TsrcPos> KW_AND
%token <TsrcPos> KW_ARCHITECTURE
%token <TsrcPos> KW_ARRAY
%token <TsrcPos> KW_ASSERT
%token <TsrcPos> KW_ATTRIBUTE
%token <TsrcPos> KW_BEGIN
%token <TsrcPos> KW_BLOCK
%token <TsrcPos> KW_BODY
%token <TsrcPos> KW_BUFFER
%token <TsrcPos> KW_BUS
%token <TsrcPos> KW_CASE
%token <TsrcPos> KW_COMPONENT
%token <TsrcPos> KW_CONFIGURATION
%token <TsrcPos> KW_CONSTANT
%token <TsrcPos> KW_CONSTRAINT
%token <TsrcPos> KW_DISCONNECT
%token <TsrcPos> KW_DOWNTO
%token <TsrcPos> KW_ELSE
%token <TsrcPos> KW_ELSIF
%token <TsrcPos> KW_END
%token <TsrcPos> KW_ENTITY
%token <TsrcPos> KW_EXIT
%token <TsrcPos> KW_FILE
%token <TsrcPos> KW_FOR
%token <TsrcPos> KW_FUNCTION
%token <TsrcPos> KW_GENERATE
%token <TsrcPos> KW_GENERIC
%token <TsrcPos> KW_GUARDED
%token <TsrcPos> KW_GROUP
%token <TsrcPos> KW_IF
%token <TsrcPos> KW_IN
%token <TsrcPos> KW_INERTIAL
%token <TsrcPos> KW_INOUT
%token <TsrcPos> KW_PURE
%token <TsrcPos> KW_INPURE
%token <TsrcPos> KW_IS
%token <TsrcPos> KW_LABEL
%token <TsrcPos> KW_LIBRARY
%token <TsrcPos> KW_LINKAGE
%token <TsrcPos> KW_LOOP
%token <TsrcPos> KW_MAP
%token <TsrcPos> KW_MOD
%token <TsrcPos> NAND_OP
%token <TsrcPos> KW_NEW
%token <TsrcPos> KW_NEXT
%token <TsrcPos> NOR_OP
%token <TsrcPos> XNOR_OP
%token <TsrcPos> KW_NOT
%token <TsrcPos> KW_NULL
%token <TsrcPos> KW_OF
%token <TsrcPos> KW_ON
%token <TsrcPos> KW_OPEN
%token <TsrcPos> OR_OP
%token <TsrcPos> KW_OTHERS
%token <TsrcPos> KW_OUT
%token <TsrcPos> KW_PACKAGE
%token <TsrcPos> KW_PORT
%token <TsrcPos> KW_POSTPONED
%token <TsrcPos> KW_PROCEDURE
%token <TsrcPos> KW_PROCESS
%token <TsrcPos> KW_RANGE
%token <TsrcPos> KW_RECORD
%token <TsrcPos> KW_REGISTER
%token <TsrcPos> KW_REM
%token <TsrcPos> KW_REJECT
%token <TsrcPos> KW_REPORT
%token <TsrcPos> KW_RETURN
%token <TsrcPos> KW_ROL
%token <TsrcPos> KW_ROR
%token <TsrcPos> KW_SELECT
%token <TsrcPos> KW_SEVERITY
%token <TsrcPos> KW_SIGNAL
%token <TsrcPos> KW_SLA
%token <TsrcPos> KW_SLL
%token <TsrcPos> KW_SRA
%token <TsrcPos> KW_SRL
%token <TsrcPos> KW_SUBTYPE
%token <TsrcPos> KW_SHARED
%token <TsrcPos> KW_THEN
%token <TsrcPos> KW_TO
%token <TsrcPos> KW_TRANSPORT
%token <TsrcPos> KW_TYPE
%token <TsrcPos> KW_UNAFFECTED
%token <TsrcPos> KW_UNITS
%token <TsrcPos> KW_UNTIL
%token <TsrcPos> KW_USE
%token <TsrcPos> KW_VARIABLE
%token <TsrcPos> KW_WAIT
%token <TsrcPos> KW_WHEN
%token <TsrcPos> KW_WHILE
%token <TsrcPos> KW_WITH
%token <TsrcPos> XOR_OP
%token <TsrcPos> AND_OP
%token <TsrcPos> APST_OP
%token <TsrcPos> L_PAR
%token <TsrcPos> R_PAR
%token <TsrcPos> L_BRACE
%token <TsrcPos> R_BRACE
%token <TsrcPos> DAST_OP
%token <TsrcPos> AST_OP
%token <TsrcPos> PLUS_OP
%token <TsrcPos> COMMA
%token <TsrcPos> MINUS_OP
%token <TsrcPos> ASGN_OP
%token <TsrcPos> COLON
%token <TsrcPos> SCOLON
%token <TsrcPos> LE_OP
%token <TsrcPos> GE_OP
%token <TsrcPos> LT_OP
%token <TsrcPos> GT_OP
%token <TsrcPos> EQ_OP
%token <TsrcPos> NE_OP
%token <TsrcPos> ARROW_OP
%token <TsrcPos> BOX_OP
%token <TsrcPos> BAR_OP
%token <TsrcPos> NOT_OP
%token <TsrcPos> DOT_OP
%token <TsrcPos> SLASH_OP
%type <Yactual_designator> actual_designator
%type <Yactual_parameter_part> actual_parameter_part
%type <Yactual_part> actual_part
%type <Yadding_operator> adding_operator
%type <Yaggregate> aggregate
%type <Yand_relation> and_relation
%type <Yarchitecture_body> architecture_body
%type <Yarchitecture_declarative_part> architecture_declarative_part
%type <Yarchitecture_statement_part> architecture_statement_part
%type <Yassertion> assertion
%type <Yassertion_statement> assertion_statement
%type <Yassociation_element> association_element
%type <Yassociation_list> association_list
%type <Yattribute_name> attribute_name
%type <Yblock_declarative_item> block_declarative_item
%type <Ycase_statement> case_statement
%type <Ycase_statement_alternative> case_statement_alternative
%type <Ycase_statement_alternative_list> case_statement_alternative_list
%type <Ychoice> choice
%type <Ychoices> choices
%type <Yconcurrent_statement> concurrent_statement
%type <Ycondition> condition
%type <Yconstant_declaration> constant_declaration
%type <Ycontext_clause> context_clause
%type <Ycontext_item> context_item
%type <Ydesign_file> design_file
%type <Ydesign_unit> design_unit
%type <Ydesign_unit_list> design_unit_list
%type <Ydiscrete_range> discrete_range
%type <Yelseif_statement> elseif_statement
%type <Yelseif_statement_list> elseif_statement_list
%type <Yelement_association> element_association
%type <Yelement_association_list> element_association_list
%type <Yentity_declaration> entity_declaration
%type <Yexit_statement> exit_statement
%type <Yexpression> expression
%type <Yfactor> factor
%type <Yformal_part> formal_part
%type <Yfunction_call> function_call
%type <Yidentifier_list> identifier_list
%type <Yif_statement> if_statement
%type <Yinterface_constant_declaration> interface_constant_declaration
%type <Yinterface_declaration> interface_declaration
%type <Yinterface_list> interface_list
%type <Yinterface_variable_declaration> interface_variable_declaration
%type <Yiteration_scheme> iteration_scheme
%type <Ylibrary_clause> library_clause
%type <Ylibrary_unit> library_unit
%type <Yliteral> literal
%type <Yloop_statement> loop_statement
%type <Ymark> mark
%type <Ymode> mode
%type <Ymultiplying_operator> multiplying_operator
%type <Yname> name
%type <Ynand_relation > nand_relation
%type <Ynext_statement> next_statement
%type <Ynor_relation> nor_relation
%type <Ynull_statement> null_statement
%type <Ynumeric_literal> numeric_literal
%type <Yor_relation> or_relation
%type <Yport_clause> port_clause
%type <Yprimary> primary
%type <Yprimary_unit> primary_unit
%type <Yprocedure_call> procedure_call
%type <Yprocedure_call_statement> procedure_call_statement
%type <Yprocess_declarative_item> process_declarative_item
%type <Yprocess_declarative_part> process_declarative_part
%type <Yprocess_statement> process_statement
%type <Yprocess_statement_part> process_statement_part
%type <Yqualified_expression> qualified_expression
%type <Yrelation> relation
%type <Yrelational_operator> relational_operator
%type <Yreport_statement> report_statement
%type <Yreturn_statement> return_statement
%type <Ysecondary_unit> secondary_unit
%type <Yselected_name> selected_name
%type <Yselected_name_list> selected_name_list
%type <Ysequence_of_statements> sequence_of_statements
%type <Ysequential_statement> sequential_statement
%type <Yshift_expression> shift_expression
%type <Yshift_operator> shift_operator
%type <Ysign> sign
%type <Ysignal_assignment_statement> signal_assignment_statement
%type <Ysimple_expression> simple_expression
%type <Ysubprogram_body> subprogram_body
%type <Ysubprogram_declaration> subprogram_declaration
%type <Ysubprogram_declarative_item> subprogram_declarative_item
%type <Ysubprogram_declarative_part> subprogram_declarative_part
%type <Ysubprogram_specification> subprogram_specification
%type <Ysubprogram_statement_part> subprogram_statement_part
%type <Ysuffix> suffix
%type <Ytarget> target
%type <Yterm> term
%type <Ytimeout_clause> timeout_clause
%type <Yuse_clause> use_clause
%type <Yvariable_assignment_statement> variable_assignment_statement
%type <Yvariable_declaration> variable_declaration
%type <Ywait_statement> wait_statement
%type <Ywaveform> waveform
%type <Ywaveform_element> waveform_element
%type <Ywaveform_element_list> waveform_element_list
%type <Yxnor_relation> xnor_relation
%type <Yxor_relation> xor_relation
%type <Yconstraint> constraint
%type <Yrange> range
%union{
int TsrcPos;
id Tid;
actual_designator_type Yactual_designator;
actual_parameter_part_type Yactual_parameter_part;
actual_part_type Yactual_part;
adding_operator_type Yadding_operator;
aggregate_type Yaggregate;
and_relation_type Yand_relation;
architecture_body_type Yarchitecture_body;
architecture_declarative_part_type Yarchitecture_declarative_part;
architecture_statement_part_type Yarchitecture_statement_part;
assertion_type Yassertion;
assertion_statement_type Yassertion_statement;
association_element_type Yassociation_element;
association_list_type Yassociation_list;
attribute_declaration_type Yattribute_declaration;
attribute_name_type Yattribute_name;
block_declarative_item_type Yblock_declarative_item;
case_statement_type Ycase_statement;
case_statement_alternative_type Ycase_statement_alternative;
case_statement_alternative_list_type Ycase_statement_alternative_list;
choice_type Ychoice;
choices_type Ychoices;
concurrent_statement_type Yconcurrent_statement;
condition_type Ycondition;
constant_declaration_type Yconstant_declaration;
context_clause_type Ycontext_clause;
context_item_type Ycontext_item;
design_file_type Ydesign_file;
design_unit_type Ydesign_unit;
design_unit_list_type Ydesign_unit_list;
discrete_range_type Ydiscrete_range;
elseif_statement_type Yelseif_statement;
elseif_statement_list_type Yelseif_statement_list;
element_association_type Yelement_association;
element_association_list_type Yelement_association_list;
entity_declaration_type Yentity_declaration;
exit_statement_type Yexit_statement;
expression_type Yexpression;
factor_type Yfactor;
formal_part_type Yformal_part;
function_call_type Yfunction_call;
identifier_list_type Yidentifier_list;
if_statement_type Yif_statement;
interface_constant_declaration_type Yinterface_constant_declaration;
interface_declaration_type Yinterface_declaration;
interface_list_type Yinterface_list;
interface_variable_declaration_type Yinterface_variable_declaration;
iteration_scheme_type Yiteration_scheme;
library_clause_type Ylibrary_clause;
library_unit_type Ylibrary_unit;
literal_type Yliteral;
loop_statement_type Yloop_statement;
mark_type Ymark;
mode_type Ymode;
multiplying_operator_type Ymultiplying_operator;
name_type Yname;
nand_relation_type Ynand_relation;
next_statement_type Ynext_statement;
nor_relation_type Ynor_relation;
null_statement_type Ynull_statement;
numeric_literal_type Ynumeric_literal;
or_relation_type Yor_relation;
port_clause_type Yport_clause;
primary_type Yprimary;
primary_unit_type Yprimary_unit;
procedure_call_type Yprocedure_call;
procedure_call_statement_type Yprocedure_call_statement;
process_declarative_item_type Yprocess_declarative_item;
process_declarative_part_type Yprocess_declarative_part;
process_statement_type Yprocess_statement;
process_statement_part_type Yprocess_statement_part;
qualified_expression_type Yqualified_expression;
relation_type Yrelation;
relational_operator_type Yrelational_operator;
report_statement_type Yreport_statement;
return_statement_type Yreturn_statement;
secondary_unit_type Ysecondary_unit;
selected_name_type Yselected_name;
selected_name_list_type Yselected_name_list;
sequence_of_statements_type Ysequence_of_statements;
sequential_statement_type Ysequential_statement;
shift_expression_type Yshift_expression;
shift_operator_type Yshift_operator;
sign_type Ysign;
signal_assignment_statement_type Ysignal_assignment_statement;
simple_expression_type Ysimple_expression;
subprogram_body_type Ysubprogram_body;
subprogram_declaration_type Ysubprogram_declaration;
subprogram_declarative_item_type Ysubprogram_declarative_item;
subprogram_declarative_part_type Ysubprogram_declarative_part;
subprogram_specification_type Ysubprogram_specification;
subprogram_statement_part_type Ysubprogram_statement_part;
suffix_type Ysuffix;
target_type Ytarget;
term_type Yterm;
timeout_clause_type Ytimeout_clause;
use_clause_type Yuse_clause;
variable_assignment_statement_type Yvariable_assignment_statement;
variable_declaration_type Yvariable_declaration;
wait_statement_type Ywait_statement;
waveform_type Ywaveform;
waveform_element_type Ywaveform_element;
waveform_element_list_type Ywaveform_element_list;
xnor_relation_type Yxnor_relation;
xor_relation_type Yxor_relation;
range_type Yrange;
constraint_type Yconstraint;
}
%start design_file
%%
design_file
: design_unit_list { $$ = 0; }
;
design_unit_list
: design_unit_list design_unit { $$ = 0; }
| design_unit { $$ = 0; }
;
design_unit
: context_clause library_unit { $$ = 0; }
;
context_clause
: context_clause context_item { $$ = 0; }
| { $$ = 0; }
;
context_item
: library_clause { $$ = 0; }
| use_clause { $$ = 0; }
;
library_clause
: KW_LIBRARY identifier_list SCOLON { $$ = 0; }
;
use_clause
: KW_USE selected_name_list SCOLON { $$ = 0; }
;
selected_name_list
: selected_name_list COMMA selected_name { $$ = 0; }
| selected_name { $$ = 0; }
;
library_unit
: primary_unit { $$ = 0; }
| secondary_unit { $$ = 0; }
;
primary_unit
: entity_declaration {
ent = $1;
$$ = 0;
}
;
secondary_unit
: architecture_body {
arch = $1;
$$ = 0;
}
;
entity_declaration
: KW_ENTITY ID KW_IS port_clause KW_END ID SCOLON {
CEntity *ent = (CEntity*)get_memory(sizeof(CEntity));
CEntity_Initialize(ent, $2.img, $4, 0);
$$ = ent;
}
| KW_ENTITY ID KW_IS KW_END ID SCOLON { $$ = 0; }
| KW_ENTITY ID KW_IS port_clause KW_END SCOLON {
CEntity *ent = (CEntity*)get_memory(sizeof(CEntity));
CEntity_Initialize(ent, $2.img, $4, 0);
$$ = ent;
}
| KW_ENTITY ID KW_IS KW_END SCOLON { $$ = 0; }
;
interface_list
: interface_list SCOLON interface_declaration {
addVector($1, $3);
$$ = $1;
}
| interface_declaration {
$$ = $1;
}
;
interface_declaration
: interface_constant_declaration {
$$ = $1;
}
| interface_variable_declaration {
$$ = $1;
}
;
actual_designator
: expression {
$$ = $1;
}
| KW_OPEN { $$ = 0; }
;
actual_parameter_part
: association_list {
$$ = $1;
}
;
actual_part
: actual_designator {
$$ = $1;
}
;
adding_operator
: PLUS_OP { $$ = 0; }
| MINUS_OP { $$ = 1; }
| AND_OP { $$ = 2; }
;
aggregate
: L_PAR element_association_list R_PAR {
$$ = $2;
}
;
element_association_list
: element_association_list COMMA element_association {
add($1,$3);
$$ = $1;
}
| element_association {
Vector* vec = (Vector*)get_memory(sizeof(Vector));
Vector_Initialize(vec);
add(vec,$1);
$$ = vec;
}
;
architecture_body
: KW_ARCHITECTURE ID KW_OF ID KW_IS architecture_declarative_part KW_BEGIN architecture_statement_part KW_END ID SCOLON {
CArchitecture* obj = (CArchitecture*)get_memory(sizeof(CArchitecture));
CArchitecture_Initialize(obj,$2.img,$4.img,$6,$8->decls,$8->stmts,$7,$9);
$$ = obj;
}
| KW_ARCHITECTURE ID KW_OF ID KW_IS architecture_declarative_part KW_BEGIN architecture_statement_part KW_END SCOLON {
CArchitecture* obj = (CArchitecture*)get_memory(sizeof(CArchitecture));
CArchitecture_Initialize(obj,$2.img,$4.img,$6,$8->decls,$8->stmts,$7,$9);
$$ = obj;
}
;
/*主構造部の定義部*/
architecture_declarative_part
: architecture_declarative_part block_declarative_item {
if($2 != NULL){
add($1, $2);
}
$$ = $1;
}
|/*Empty*/ {
Vector* vec = (Vector*)get_memory(sizeof(Vector));
Vector_Initialize(vec);
$$ = vec;
}
;
/*主構造のstmt部*/
architecture_statement_part
: architecture_statement_part concurrent_statement {
$$ = $2;
}
|/*Empty*/ {
$$ = 0;
}
;
assertion
: KW_ASSERT condition KW_REPORT expression {
CAssertionStmt* obj = (CAssertionStmt*)get_memory(sizeof(CAssertionStmt));
CAssertionStmt_Initialize(obj, $2, $4, $1);
$$ = (CStmt*)obj;
}
;
assertion_statement
: assertion SCOLON {
$$ = $1;
}
;
association_element
: actual_part { $$ = $1; }
| formal_part ARROW_OP actual_part { $$ = 0; }
;
association_list
: association_list COMMA association_element {
add($1, $3);
$$ = $1;
}
| association_element {
Vector *vec = (Vector*)get_memory(sizeof(Vector));
Vector_Initialize(vec);
add(vec, $1);
$$ = vec;
}
;
attribute_name
: name APST_OP ID { $$ = 0; }
;
/*VHDLの定義体*/
block_declarative_item
: subprogram_declaration {
$$ = 0;
}
| subprogram_body {
$$ = $1;
}
| constant_declaration {
$$ = $1;
}
| variable_declaration {
$$ = $1;
}
;
case_statement
: KW_CASE expression KW_IS case_statement_alternative_list KW_END KW_CASE SCOLON { $$ = 0; }
;
case_statement_alternative_list
: case_statement_alternative_list case_statement_alternative { $$ = 0; }
| case_statement_alternative { $$ = 0; }
;
case_statement_alternative
: KW_WHEN choices ARROW_OP sequence_of_statements { $$ = 0; }
;
choice
: simple_expression { $$ = 0; }
| discrete_range { $$ = 0; }
| KW_OTHERS { $$ = 0; }
;
choices
: choices BAR_OP choice { $$ = 0; }
| choice { $$ = 0; }
;
/*Main関数*/
concurrent_statement
: process_statement {
$$ = $1;
}
;
condition
: expression {
$$ = $1;
}
;
constant_declaration
: KW_CONSTANT identifier_list COLON ID constraint ASGN_OP expression SCOLON {
Vector *ids = $2;
int i;
for(i = 0; i < size(ids); i++){
char *img = (char*)elementAt(ids, i);
regist(interface_tab, img, $7);
}
$$ = 0;
}
| KW_CONSTANT identifier_list COLON ID constraint SCOLON { $$ = 0; }
;
discrete_range
: KW_RANGE { $$ = 0; }
;
element_association
: choices ARROW_OP expression { $$ = 0; }
| expression {
$$ = $1;
}
;
exit_statement
: KW_EXIT KW_WHEN condition SCOLON { $$ = 0; }
| KW_EXIT SCOLON { $$ = 0; }
;
expression
: expression KW_AND and_relation {
CExpression *exp = (CExpression*)get_memory(sizeof(CAndExpression));
CAndExpression_Initialize((CAndExpression*)exp, $1, $3);
$$ = exp;
}
| and_relation {
$$ = $1;
}
;
/*exprの関係*/
and_relation
: and_relation OR_OP or_relation {
CExpression *exp = (CExpression*)get_memory(sizeof(COrExpression));
COrExpression_Initialize((COrExpression*)exp, $1, $3);
$$ = exp;
}
| or_relation {
$$ = $1;
}
;
or_relation
: or_relation XOR_OP xor_relation {$$ = 0;}
| xor_relation {
$$ = $1;
}
;
xor_relation
: xor_relation NAND_OP nand_relation { $$ = 0; }
| nand_relation {
$$ = $1;
}
;
nand_relation
: nand_relation NOR_OP nor_relation { $$ = 0; }
| nor_relation {
$$ = $1;
}
;
nor_relation
: nor_relation XNOR_OP xnor_relation { $$ = 0; }
| xnor_relation {
$$ = $1;
}
;
xnor_relation
: relation {
$$ = $1;
}
;
factor
: primary {
$$ = $1;
}
| primary DAST_OP primary { $$ = 0; }
| KW_ABS primary { $$ = 0; }
| KW_NOT primary { $$ = 0; }
;
formal_part
: name { $$ = 0; }
| name L_PAR name R_PAR { $$ = 0; }
;
function_call
: ID L_PAR actual_parameter_part R_PAR {
CExpression *exp = (CExpression*)get_memory(sizeof(CFunctionCall));
CFunctionCall_Initialize((CFunctionCall*)exp, $1.img, $3);
$$ = exp;
}
| ID L_PAR R_PAR {
CExpression *exp = (CExpression*)get_memory(sizeof(CFunctionCall));
CFunctionCall_Initialize((CFunctionCall*)exp, $1.img, 0);
$$ = exp;
}
;
identifier_list
: identifier_list COMMA ID {
add($1, $3.img);
$$ = $1;
}
| ID {
Vector *vec = (Vector*)get_memory(sizeof(Vector));
Vector_Initialize(vec);
add(vec, $1.img);
$$ = vec;
}
;
if_statement
: KW_IF condition KW_THEN sequence_of_statements elseif_statement_list KW_ELSE sequence_of_statements KW_END KW_IF SCOLON {
CIfStmt* obj = (CIfStmt*)get_memory(sizeof(CIfStmt*));
CIfStmt_Initialize(obj,$1, $2, $4, $7);
$$ = (CStmt*)obj;
}
| KW_IF condition KW_THEN sequence_of_statements elseif_statement_list KW_END KW_IF SCOLON {
CIfStmt* obj = (CIfStmt*)get_memory(sizeof(CIfStmt*));
CIfStmt_Initialize(obj,$1, $2, $4, 0);
$$ = (CStmt*)obj;
}
;
elseif_statement_list
: elseif_statement_list elseif_statement { $$ = 0; }
| { $$ = 0; }
;
elseif_statement
: KW_ELSIF condition KW_THEN sequence_of_statements { $$ = 0; }
;
interface_constant_declaration
: KW_CONSTANT identifier_list COLON KW_IN ID constraint ASGN_OP expression { $$ = 0; }
| KW_CONSTANT identifier_list COLON KW_IN ID constraint { $$ = 0; }
| KW_CONSTANT identifier_list COLON ID constraint ASGN_OP expression { $$ = 0; }
| KW_CONSTANT identifier_list COLON ID constraint { $$ = 0; }
;
interface_variable_declaration
: KW_VARIABLE identifier_list COLON mode ID constraint ASGN_OP expression { $$ = 0; }
| KW_VARIABLE identifier_list COLON mode ID constraint { $$ = 0; }
| KW_VARIABLE identifier_list COLON ID constraint ASGN_OP expression { $$ = 0; }
| KW_VARIABLE identifier_list COLON ID constraint { $$ = 0; }
| identifier_list COLON mode ID constraint ASGN_OP expression {
$$ = 0;
}
| identifier_list COLON mode ID constraint {
int i;
Vector *vec = (Vector*)get_memory(sizeof(Vector));
CPort *port = (CPort*)get_memory(sizeof(CPort));
Vector_Initialize(vec);
for(i=0;i<size($1);i++){
CPort_Initialize(port,(char*)elementAt($1,i),$4.img,0);
add(vec,port);
}
$$ = vec;
}
| identifier_list COLON ID constraint ASGN_OP expression { $$ = 0; }
| identifier_list COLON ID constraint {
int i;
Vector *vec = (Vector*)get_memory(sizeof(Vector));
CPort *port = (CPort*)get_memory(sizeof(CPort));
Vector_Initialize(vec);
for(i=0;i<size($1);i++){
CPort_Initialize(port,(char*)elementAt($1,i),$3.img,0);
add(vec,port);
}
$$ = vec;
}
;
/*配列で括弧を付ける*/
constraint
: { $$ = 0; }
| L_PAR range R_PAR {
CExpression *exp = (CExpression*)get_memory(sizeof(CParExpression));
CParExpression_Initialize((CParExpression*)exp, $2);
$$ = exp;
}
;
range
: simple_expression {
$$ = $1;
}
| range COMMA simple_expression {
CToExpression* exp = get_memory(sizeof(CToExpression));
CToExpression_Initialize(exp,$1,$3);
$$ = (CExpression*)exp;
}
;
literal
: numeric_literal {
$$ = $1;
}
| CHARACTER {
CStrExpression* str = (CStrExpression*)get_memory(sizeof(CStrExpression));
CStrExpression_Initialize(str,$1.img);
$$ = (CExpression*)str;
}
| STRING {
CStrExpression* str = (CStrExpression*)get_memory(sizeof(CStrExpression));
CStrExpression_Initialize(str,$1.img);
$$ = (CExpression*)str;
}
| BIT_STRING_LITERAL { $$ = 0; }
| KW_NULL { $$ = 0; }
;
loop_statement
: iteration_scheme KW_LOOP sequence_of_statements KW_END KW_LOOP SCOLON {
CWhileStmt* obj = (CWhileStmt*)get_memory(sizeof(CWhileStmt));
CWhileStmt_Initialize(obj, $1, $3, $2);
$$ = (CStmt*)obj;
}
;
iteration_scheme
: KW_WHILE condition {
$$ = $2;
}
;
mode
: KW_IN { $$ = 0; }
| KW_OUT { $$ = 0; }
| KW_INOUT { $$ = 0; }
| KW_BUFFER { $$ = 0; }
| KW_LINKAGE { $$ = 0; }
;
multiplying_operator
: AST_OP { $$ = 0; }
| SLASH_OP { $$ = 0; }
| KW_MOD { $$ = 0; }
| KW_REM { $$ = 0; }
;
/*符号の文字列*/
name
: mark {
$$ = $1;
}
| attribute_name {
$$ = 0;
}
;
mark
: ID {
$$ = $1.img;
}
| selected_name {
$$ = $1;
}
;
next_statement
: KW_NEXT KW_WHEN condition SCOLON { $$ = 0; }
;
null_statement
: KW_NULL SCOLON { $$ = 0; }
;
numeric_literal
: ABSTRACT_LITERAL {
CNumeric* num = (CNumeric*)get_memory(sizeof(CNumeric));
CNumeric_Initialize(num, $1.img);
$$ = (CExpression*)num;
}
;
port_clause
: KW_PORT L_PAR interface_list R_PAR SCOLON {
$$ = $3;
}
;
/*最下の元*/
primary
: literal {
$$ = $1; /*数字*/
}
| function_call {
$$ = $1; /*関数*/
}
| qualified_expression { $$ = 0; }
| name {
CExpression *id = (CExpression*)get_memory(sizeof(CIdentifier));
CIdentifier_Initialize((CIdentifier*)id, $1);
$$ = id; /*普通の符号*/
}
| L_PAR expression R_PAR {
$$ = $2;
}
;
procedure_call
: ID L_PAR actual_parameter_part R_PAR {
CProcedureCall* obj = (CProcedureCall*)get_memory(sizeof(CProcedureCall));
CProcedureCall_Initialize(obj,$1.img, $3, $1.pos);
$$ = (CStmt*)obj;
}
| ID {
CProcedureCall* obj = (CProcedureCall*)get_memory(sizeof(CProcedureCall));
CProcedureCall_Initialize(obj,$1.img, 0, $1.pos);
$$ = (CStmt*)obj;
}
;
procedure_call_statement
: procedure_call SCOLON {
$$ = $1;
}
;
process_declarative_item
: subprogram_declaration {
$$ = 0;
}
| subprogram_body {
$$ = $1;
}
| constant_declaration {
$$ = $1;
}
| variable_declaration {
$$ = $1;
}
;
/*Main関数定義体*/
process_declarative_part
: process_declarative_part process_declarative_item {
if ($2 !=NULL){
add($1, $2);
}
$$ = $1;
}
| {
Vector *vec = (Vector*)get_memory(sizeof(Vector));
Vector_Initialize(vec);
$$ = vec;
}
;
process_statement
: KW_PROCESS process_declarative_part KW_BEGIN process_statement_part KW_END KW_PROCESS SCOLON {
decl_stmt* obj = (decl_stmt*)get_memory(sizeof(decl_stmt));
obj->decls = $2;
obj->stmts = $4;
$$ = obj;
}
;
/*main関数中のstmt*/
process_statement_part
: process_statement_part sequential_statement {
if($2 != 0){
add($1, $2);
}
$$ = $1;
}
| {
Vector *vec = (Vector*)get_memory(sizeof(Vector));
Vector_Initialize(vec);
$$ = vec;
}
;
qualified_expression
: name APST_OP L_PAR expression R_PAR { $$ = 0; }
| name APST_OP aggregate { $$ = 0; }
;
/*比較の符号:>,<,<=,=*/
relation
: shift_expression relational_operator shift_expression {
CExpression* exp =(CExpression*)get_memory(sizeof(CExpression));
switch ($2){
case 0:/*EQ_OP: = */
CEqExpression_Initialize((CEqExpression*)exp,$1,$3);
break;
case 1:/*NE_OP*/
CNotEqExpression_Initialize((CNotEqExpression*)exp,$1,$3);
break;
case 2:/*LT_OP:<*/
CLtExpression_Initialize((CLtExpression*)exp,$1,$3);
break;
case 3:/*LE_OP:<=*/
CLtEqExpression_Initialize((CLtEqExpression*)exp,$1,$3);
break;
case 4:/*GT_OP*/
CGtExpression_Initialize((CGtExpression*)exp, $1, $3);
break;
case 5:/*GE_OP*/
CGtEqExpression_Initialize((CGtEqExpression*)exp, $1, $3);
break;
default:
break;
}
}
| shift_expression {
$$ = $1;
}
;
relational_operator
: EQ_OP { $$ = 0; }
| NE_OP { $$ = 1; }
| LT_OP { $$ = 2; }
| LE_OP { $$ = 3; }
| GT_OP { $$ = 4; }
| GE_OP { $$ = 5; }
;
report_statement
: KW_REPORT expression SCOLON { $$ = 0; }
;
return_statement
: KW_RETURN expression SCOLON { $$ = 0; }
| KW_RETURN SCOLON { $$ = 0; }
;
/*小数点*/
selected_name
: name DOT_OP suffix {
char *str = (char*)get_memory(sizeof(char) * (strlen($1) + strlen($3) + 2));
str[0] = '/0';
strcat(str, $1);
strcat(str, ".");
strcat(str, $3);
$$ = str;
}
;
/*Stmtの対象結合*/
sequence_of_statements
: sequence_of_statements sequential_statement {
if($2 != NULL){
add($1, $2);
}
$$ = $1;
}
| {
Vector* obj = (Vector*)get_memory(sizeof(Vector));
Vector_Initialize(obj);
$$ = obj;
}
;
sequential_statement
: wait_statement { $$ = $1; }
| assertion_statement { $$ = $1; }
| report_statement { $$ = $1; }
| signal_assignment_statement { $$ = $1; }
| variable_assignment_statement { $$ = $1; }
| procedure_call_statement { $$ = $1; }
| if_statement { $$ = $1; }
| case_statement { $$ = 0; }
| loop_statement { $$ = $1; }
| next_statement { $$ = 0; }
| exit_statement { $$ = 0; }
| return_statement { $$ = $1; }
| null_statement { $$ = 0; }
;
shift_expression
: simple_expression shift_operator simple_expression { $$ = 0; }
| simple_expression {
$$ = $1;
}
;
shift_operator
: KW_SLL { $$ = 0; }
| KW_SRL { $$ = 0; }
| KW_SLA { $$ = 0; }
| KW_SRA { $$ = 0; }
| KW_ROL { $$ = 0; }
| KW_ROR { $$ = 0; }
;
sign
: PLUS_OP { $$ = 0; }
| MINUS_OP { $$ = 0; }
;
signal_assignment_statement
: target LE_OP waveform SCOLON {
CSignalAssignStmt* obj = (CSignalAssignStmt*)get_memory(sizeof(CSignalAssignStmt));
CSignalAssignStmt_Initialize(obj,$1,0,$3,$2);
$$ = (CStmt*)obj;
}
| ID L_PAR actual_parameter_part R_PAR LE_OP waveform SCOLON {
CSignalAssignStmt* obj = (CSignalAssignStmt*)get_memory(sizeof(CSignalAssignStmt));
CSignalAssignStmt_Initialize((CSignalAssignStmt*)obj, $1.img, $3, $6, $5);
$$ = (CStmt*)obj;
}
;
/*簡単のexpr:+,-,& */
simple_expression
: simple_expression adding_operator term {
CExpression *exp;
switch($2){
case 0:
exp = (CExpression*)get_memory(sizeof(CPlusExpression));
CPlusExpression_Initialize((CPlusExpression*)exp, $1, $3);
break;
case 1:
exp = (CExpression*)get_memory(sizeof(CMinusExpression));
CMinusExpression_Initialize((CMinusExpression*)exp, $1, $3);
break;
case 2:
exp = (CExpression*)get_memory(sizeof(CAndOpExpression));
CAndOpExpression_Initialize((CAndOpExpression*)exp, $1, $3);
break;
default:
exp = 0;
}
$$ = exp;
}
| sign term { $$ = $2; }
| term { $$ = $1; }
;
subprogram_body
: KW_PROCEDURE ID L_PAR interface_list R_PAR KW_IS subprogram_declarative_part KW_BEGIN subprogram_statement_part KW_END ID SCOLON {
CDeclaration *decl = (CDeclaration*)get_memory(sizeof(CProcedureDecl));
CProcedureDecl_Initialize((CProcedureDecl*)decl, $2.img, $7, $4, $9, $1, $10);
/*setRefFromTo($1, $1, $10);*/
$$ = decl;
}
| KW_PROCEDURE ID KW_IS subprogram_declarative_part KW_BEGIN subprogram_statement_part KW_END ID SCOLON {
CDeclaration *decl = (CDeclaration*)get_memory(sizeof(CProcedureDecl));
CProcedureDecl_Initialize((CProcedureDecl*)decl, $2.img, $4, 0, $6, $1, $7);
/*setRefFromTo($1, $1, $7);*/
$$ = decl;
}
| KW_FUNCTION ID L_PAR interface_list R_PAR KW_RETURN name KW_IS subprogram_declarative_part KW_BEGIN subprogram_statement_part KW_END ID SCOLON {
CDeclaration *decl = (CDeclaration*)get_memory(sizeof(CFunctionDecl));
CFunctionDecl_Initialize((CFunctionDecl*)decl, $2.img, $9, $4, $7, $11, $1, $12);
//setRefFromTo($1, $1, $12);
$$ = decl;
}
| KW_FUNCTION ID KW_RETURN name KW_IS subprogram_declarative_part KW_BEGIN subprogram_statement_part KW_END ID SCOLON {
CDeclaration *decl = (CDeclaration*)get_memory(sizeof(CFunctionDecl));
CFunctionDecl_Initialize((CFunctionDecl*)decl, $2.img, $6, 0, $4, $8, $1, $9);
//setRefFromTo($1, $1, $9);
$$ = decl;
}
| KW_PROCEDURE ID L_PAR interface_list R_PAR KW_IS subprogram_declarative_part KW_BEGIN subprogram_statement_part KW_END SCOLON {
CDeclaration *decl = (CDeclaration*)get_memory(sizeof(CProcedureDecl));
CProcedureDecl_Initialize((CProcedureDecl*)decl, $2.img, $7, $4, $9, $1, $10);
//setRefFromTo($1, $1, $10);
$$ = decl;
}
| KW_PROCEDURE ID KW_IS subprogram_declarative_part KW_BEGIN subprogram_statement_part KW_END SCOLON {
CDeclaration *decl = (CDeclaration*)get_memory(sizeof(CProcedureDecl));
CProcedureDecl_Initialize((CProcedureDecl*)decl, $2.img, $4, 0, $6, $1, $7);
//setRefFromTo($1, $1, $7);
$$ = decl;
}
| KW_FUNCTION ID L_PAR interface_list R_PAR KW_RETURN name KW_IS subprogram_declarative_part KW_BEGIN subprogram_statement_part KW_END SCOLON {
CDeclaration *decl = (CDeclaration*)get_memory(sizeof(CFunctionDecl));
CFunctionDecl_Initialize((CFunctionDecl*)decl, $2.img, $9, $4, $7, $11, $1, $12);
//setRefFromTo($1, $1, $12);
$$ = decl;
}
| KW_FUNCTION ID KW_RETURN name KW_IS subprogram_declarative_part KW_BEGIN subprogram_statement_part KW_END SCOLON {
CDeclaration *decl = (CDeclaration*)get_memory(sizeof(CFunctionDecl));
CFunctionDecl_Initialize((CFunctionDecl*)decl, $2.img, $6, 0, $4, $8, $1, $9);
//setRefFromTo($1, $1, $9);
$$ = decl;
}
;
subprogram_declaration
: subprogram_specification SCOLON { $$ = 0; }
;
subprogram_declarative_item
: subprogram_declaration {
$$ = $1;
}
| subprogram_body {
$$ = $1;
}
| constant_declaration {
$$ = $1;
}
| variable_declaration {
$$ = $1;
}
;
subprogram_declarative_part
: subprogram_declarative_part subprogram_declarative_item {
if($2 != 0){
add($1, $2);
}
}
| {
Vector *vec = (Vector*)get_memory(sizeof(Vector));
Vector_Initialize(vec);
$$ = vec;
}
;
subprogram_specification
: KW_PROCEDURE ID L_PAR interface_list R_PAR { $$ = 0; }
| KW_PROCEDURE ID { $$ = 0; }
| KW_FUNCTION ID L_PAR interface_list R_PAR KW_RETURN name { $$ = 0; }
| KW_FUNCTION ID KW_RETURN name { $$ = 0; }
;
/*サブ関数内のstmt*/
subprogram_statement_part
: subprogram_statement_part sequential_statement {
if($2 != NULL){
add($1,$2);
}
$$ = $1;
}
|{
Vector* vec = (Vector*)get_memory(sizeof(Vector));
Vector_Initialize(vec);
$$ = vec;
}
;
suffix
: ID { $$ = $1.img; }
| CHARACTER { $$ = $1.img; }
| STRING { $$ = $1.img; }
| KW_ALL { $$ = 0; }
;
target
: name { $$ = $1; }
| aggregate { $$ = 0; }
;
term
: factor L_BRACE multiplying_operator factor R_BRACE { $$ = 0; }
| factor { $$ = $1; }
;
timeout_clause
: KW_FOR expression {
CWaitStmt* obj = (CWaitStmt*)get_memory(sizeof(CWaitStmt));
CWaitStmt_Initialize(obj,$2,"s",$1);
$$ = (CStmt*)obj;
}
;
variable_assignment_statement
: target ASGN_OP expression SCOLON {
CStmt *stmt = (CStmt*)get_memory(sizeof(CVariableAssignStmt));
CVariableAssignStmt_Initialize((CVariableAssignStmt*)stmt, $1, 0, $3, $2);
$$ = stmt;
}
| ID L_PAR actual_parameter_part R_PAR ASGN_OP expression SCOLON {
CStmt *stmt = (CStmt*)get_memory(sizeof(CVariableAssignStmt));
CVariableAssignStmt_Initialize((CVariableAssignStmt*)stmt, $1.img, $3, $6, $5);
$$ = stmt;
}
;
variable_declaration
: KW_VARIABLE ID COLON ID constraint ASGN_OP expression SCOLON { $$ = 0; }
| KW_VARIABLE ID COLON ID constraint SCOLON {
CDeclaration *decl = (CDeclaration*)get_memory(sizeof(CVariableDecl));
CVariableDecl_Initialize((CVariableDecl*)decl, $2.img, $5, $4.img, $1, $6);
$$ = decl;
}
| KW_VARIABLE identifier_list COLON ID constraint SCOLON {
int i;
Vector* var_decls =(Vector*)get_memory(sizeof(Vector));
Vector_Initialize(var_decls);
for(i = 0; i < size($2); i++){
char *name = elementAt($2, i);
CDeclaration *decl = (CDeclaration*)get_memory(sizeof(CVariableDecl));
CVariableDecl_Initialize((CVariableDecl*)decl, name, $5, $4.img, $1, $6);
add(var_decls, decl);
}
$$ = 0;
}
;
wait_statement
: KW_WAIT timeout_clause SCOLON {
$$ = $2;
}
;
waveform
: waveform_element_list KW_UNAFFECTED { $$ = $1; }
| waveform_element_list { $$ = $1; }
;
waveform_element_list
: waveform_element_list waveform_element { $$ = $2; }
| waveform_element { $$ = $1; }
;
waveform_element
: expression { $$ = $1; }
;
%%
int yyerror(char *str){
extern char *yytext;
printf("line %d :[ %s ] %s/n", Source_Position, yytext, str);
}