Skip to content

Commit 6feb680

Browse files
authored
Merge pull request #1195 from diffblue/smvlang-complex-identifier
SMV: complex identifiers are now parsed as expressions
2 parents 8b76c4e + 23a2b05 commit 6feb680

File tree

1 file changed

+53
-21
lines changed

1 file changed

+53
-21
lines changed

src/smvlang/parser.y

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,41 @@ static void j_binary(YYSTYPE & dest, YYSTYPE & op1, const irep_idt &id, YYSTYPE
130130

131131
/*******************************************************************\
132132
133+
Function: merge_complex_identifier
134+
135+
Inputs:
136+
137+
Outputs:
138+
139+
Purpose:
140+
141+
\*******************************************************************/
142+
143+
irep_idt merge_complex_identifier(const exprt &expr)
144+
{
145+
if(expr.id() == ID_symbol)
146+
return to_symbol_expr(expr).get_identifier();
147+
else if(expr.id() == ID_member)
148+
{
149+
auto &member_expr = to_member_expr(expr);
150+
return id2string(merge_complex_identifier(member_expr.compound())) + '.' + id2string(member_expr.get_component_name());
151+
}
152+
else if(expr.id() == ID_index)
153+
{
154+
auto &index_expr = to_index_expr(expr);
155+
auto &index = index_expr.index();
156+
PRECONDITION(index.is_constant());
157+
auto index_string = id2string(to_constant_expr(index).get_value());
158+
return id2string(merge_complex_identifier(index_expr.array())) + '.' + index_string;
159+
}
160+
else
161+
{
162+
DATA_INVARIANT_WITH_DIAGNOSTICS(false, "unexpected complex_identifier", expr.pretty());
163+
}
164+
}
165+
166+
/*******************************************************************\
167+
133168
Function: new_module
134169
135170
Inputs:
@@ -820,7 +855,7 @@ identifier : IDENTIFIER_Token
820855

821856
variable_identifier: complex_identifier
822857
{
823-
const irep_idt &id=stack_expr($1).id();
858+
auto id = merge_complex_identifier(stack_expr($1));
824859

825860
bool is_enum=(PARSER.module->enum_set.find(id)!=
826861
PARSER.module->enum_set.end());
@@ -850,6 +885,7 @@ variable_identifier: complex_identifier
850885
}
851886
| STRING_Token
852887
{
888+
// Not in the NuSMV grammar.
853889
const irep_idt &id=stack_expr($1).id();
854890

855891
init($$, ID_symbol);
@@ -860,35 +896,31 @@ variable_identifier: complex_identifier
860896

861897
complex_identifier:
862898
identifier
899+
{
900+
$$ = $1;
901+
irep_idt identifier = stack_expr($$).id();
902+
stack_expr($$).id(ID_symbol);
903+
stack_expr($$).set(ID_identifier, identifier);
904+
}
863905
| complex_identifier DOT_Token QIDENTIFIER_Token
864906
{
865-
std::string id(stack_expr($1).id_string());
866-
id+=".";
867-
id+=std::string(stack_expr($3).id_string(), 1); // remove backslash
868-
init($$, id);
907+
unary($$, ID_member, $1);
908+
auto component = std::string(stack_expr($3).id_string(), 1); // remove backslash
909+
stack_expr($$).set(ID_component_name, component);
869910
}
870911
| complex_identifier DOT_Token IDENTIFIER_Token
871912
{
872-
std::string id(stack_expr($1).id_string());
873-
id+=".";
874-
id+=stack_expr($3).id_string();
875-
init($$, id);
913+
unary($$, ID_member, $1);
914+
stack_expr($$).set(ID_component_name, stack_expr($3).id());
876915
}
877-
| complex_identifier '[' NUMBER_Token ']'
916+
| complex_identifier '[' term ']'
878917
{
879-
std::string id(stack_expr($1).id_string());
880-
id+="[";
881-
id+=stack_expr($3).id_string();
882-
id+="]";
883-
init($$, id);
918+
binary($$, $1, ID_index, $3);
884919
}
885-
| complex_identifier '(' NUMBER_Token ')'
920+
| complex_identifier '(' term ')'
886921
{
887-
std::string id(stack_expr($1).id_string());
888-
id+="(";
889-
id+=stack_expr($3).id_string();
890-
id+=")";
891-
init($$, id);
922+
// Not in the NuSMV grammar.
923+
binary($$, $1, ID_index, $3);
892924
}
893925
;
894926

0 commit comments

Comments
 (0)