Better simple_expression parse rules.
This commit is contained in:
parent
24bd630cb2
commit
ca9616dc7b
|
|
@ -233,6 +233,7 @@ static void touchup_interface_for_functions(std::list<InterfacePort*>*ports)
|
||||||
std::list<prange_t*>*range_list;
|
std::list<prange_t*>*range_list;
|
||||||
|
|
||||||
ExpArithmetic::fun_t arithmetic_op;
|
ExpArithmetic::fun_t arithmetic_op;
|
||||||
|
std::list<struct adding_term>*adding_terms;
|
||||||
|
|
||||||
ExpAggregate::choice_t*choice;
|
ExpAggregate::choice_t*choice;
|
||||||
std::list<ExpAggregate::choice_t*>*choice_list;
|
std::list<ExpAggregate::choice_t*>*choice_list;
|
||||||
|
|
@ -287,6 +288,7 @@ static void touchup_interface_for_functions(std::list<InterfacePort*>*ports)
|
||||||
%type <flag> direction
|
%type <flag> direction
|
||||||
|
|
||||||
%type <arithmetic_op> adding_operator
|
%type <arithmetic_op> adding_operator
|
||||||
|
%type <adding_terms> simple_expression_terms
|
||||||
|
|
||||||
%type <interface_list> interface_element interface_list
|
%type <interface_list> interface_element interface_list
|
||||||
%type <interface_list> port_clause port_clause_opt
|
%type <interface_list> port_clause port_clause_opt
|
||||||
|
|
@ -314,7 +316,7 @@ static void touchup_interface_for_functions(std::list<InterfacePort*>*ports)
|
||||||
%type <expr> expression_logical_xnor expression_logical_xor
|
%type <expr> expression_logical_xnor expression_logical_xor
|
||||||
%type <expr> name prefix selected_name
|
%type <expr> name prefix selected_name
|
||||||
%type <expr> shift_expression signal_declaration_assign_opt
|
%type <expr> shift_expression signal_declaration_assign_opt
|
||||||
%type <expr> simple_expression term waveform_element
|
%type <expr> simple_expression simple_expression_2 term waveform_element
|
||||||
%type <expr> interface_element_expression
|
%type <expr> interface_element_expression
|
||||||
|
|
||||||
%type <expr_list> waveform waveform_elements
|
%type <expr_list> waveform waveform_elements
|
||||||
|
|
@ -1788,12 +1790,12 @@ procedure_call
|
||||||
$$ = tmp;
|
$$ = tmp;
|
||||||
}
|
}
|
||||||
| IDENTIFIER '(' error ')'
|
| IDENTIFIER '(' error ')'
|
||||||
{
|
{ errormsg(@1, "Errors in procedure call.\n");
|
||||||
errormsg(@1, "Errors in procedure call.\n");
|
yyerrok;
|
||||||
yyerrok;
|
delete[]$1;
|
||||||
delete[]$1;
|
$$ = 0;
|
||||||
$$ = 0;
|
}
|
||||||
};
|
;
|
||||||
|
|
||||||
procedure_call_statement
|
procedure_call_statement
|
||||||
: IDENTIFIER ':' procedure_call { $$ = $3; }
|
: IDENTIFIER ':' procedure_call { $$ = $3; }
|
||||||
|
|
@ -2067,6 +2069,11 @@ sequential_statement
|
||||||
|
|
||||||
shift_expression : simple_expression { $$ = $1; } ;
|
shift_expression : simple_expression { $$ = $1; } ;
|
||||||
|
|
||||||
|
sign
|
||||||
|
: '+'
|
||||||
|
| '-'
|
||||||
|
;
|
||||||
|
|
||||||
signal_declaration_assign_opt
|
signal_declaration_assign_opt
|
||||||
: VASSIGN expression { $$ = $2; }
|
: VASSIGN expression { $$ = $2; }
|
||||||
| { $$ = 0; }
|
| { $$ = 0; }
|
||||||
|
|
@ -2085,18 +2092,55 @@ signal_declaration_assign_opt
|
||||||
* Note that although the concatenation operator '&' is syntactically
|
* Note that although the concatenation operator '&' is syntactically
|
||||||
* an addition operator, it is handled differently during elaboration
|
* an addition operator, it is handled differently during elaboration
|
||||||
* so detect it and create a different expression type.
|
* so detect it and create a different expression type.
|
||||||
|
*
|
||||||
|
* Note too that I'm using *right* recursion to implement the {...}
|
||||||
|
* part of the rule. This is normally bad, but expression lists aren't
|
||||||
|
* normally that long, and the while loop going through the formed
|
||||||
|
* list fixes up the associations.
|
||||||
*/
|
*/
|
||||||
simple_expression
|
simple_expression
|
||||||
|
: sign simple_expression_2
|
||||||
|
{ sorrymsg(@1, "Unary expression +- not supported.\n");
|
||||||
|
$$ = $2;
|
||||||
|
}
|
||||||
|
| simple_expression_2
|
||||||
|
{ $$ = $1; }
|
||||||
|
;
|
||||||
|
|
||||||
|
simple_expression_2
|
||||||
: term
|
: term
|
||||||
{ $$ = $1; }
|
{ $$ = $1; }
|
||||||
| simple_expression adding_operator term
|
| term simple_expression_terms
|
||||||
{ Expression*tmp;
|
{ Expression*tmp = $1;
|
||||||
if ($2 == ExpArithmetic::xCONCAT) {
|
list<struct adding_term>*lst = $2;
|
||||||
tmp = new ExpConcat($1, $3);
|
while (! lst->empty()) {
|
||||||
} else {
|
struct adding_term item = lst->front();
|
||||||
tmp = new ExpArithmetic($2, $1, $3);
|
lst->pop_front();
|
||||||
|
if (item.op == ExpArithmetic::xCONCAT)
|
||||||
|
tmp = new ExpConcat(tmp, item.term);
|
||||||
|
else
|
||||||
|
tmp = new ExpArithmetic(item.op, tmp, item.term);
|
||||||
}
|
}
|
||||||
FILE_NAME(tmp, @2);
|
delete lst;
|
||||||
|
$$ = tmp;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
simple_expression_terms
|
||||||
|
: adding_operator term
|
||||||
|
{ struct adding_term item;
|
||||||
|
item.op = $1;
|
||||||
|
item.term = $2;
|
||||||
|
list<adding_term>*tmp = new list<adding_term>;
|
||||||
|
tmp->push_back(item);
|
||||||
|
$$ = tmp;
|
||||||
|
}
|
||||||
|
| simple_expression_terms adding_operator term
|
||||||
|
{ list<adding_term>*tmp = $1;
|
||||||
|
struct adding_term item;
|
||||||
|
item.op = $2;
|
||||||
|
item.term = $3;
|
||||||
|
tmp->push_back(item);
|
||||||
$$ = tmp;
|
$$ = tmp;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
|
||||||
|
|
@ -90,4 +90,10 @@ class prange_t {
|
||||||
prange_t(const prange_t&);
|
prange_t(const prange_t&);
|
||||||
prange_t operator=(const prange_t&);
|
prange_t operator=(const prange_t&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct adding_term {
|
||||||
|
ExpArithmetic::fun_t op;
|
||||||
|
Expression*term;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue