Skip to content

Commit 3f4585f

Browse files
committed
Add basic Structured Text parser
Includes support for simple arithmetic and boolean expressions as well as other ST language features, such as networks, functions and function blocks.
1 parent 3d9a71b commit 3f4585f

16 files changed

+1856
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ src/json/json_lex.yy.cpp
8484
src/json/json_y.output
8585
src/json/json_y.tab.cpp
8686
src/json/json_y.tab.h
87+
src/structured-text/structured_text_lex.yy.cpp
88+
src/structured-text/structured_text_y.output
89+
src/structured-text/structured_text_y.tab.cpp
90+
src/structured-text/structured_text_y.tab.h
8791
src/xmllang/xml_lex.yy.cpp
8892
src/xmllang/xml_y.output
8993
src/xmllang/xml_y.tab.cpp
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************\
2+
3+
Module: Structured Text Language Conversion
4+
5+
Author: Matthias Weiss, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Structured Text Language Conversion
11+
12+
#include "convert_int_value.h"
13+
#include <util/std_types.h>
14+
15+
constant_exprt convert_int_value(const std::string &src)
16+
{
17+
signedbv_typet type(16);
18+
type.set(ID_structured_text_type, ID_structured_text_int_value);
19+
return constant_exprt(src, type);
20+
}
21+
22+
constant_exprt convert_bit_value(const std::string &src)
23+
{
24+
bool_typet type;
25+
type.set(ID_structured_text_type, ID_structured_text_bit_value);
26+
return constant_exprt(src, type);
27+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*******************************************************************\
2+
3+
Module: Structured Text Language Conversion
4+
5+
Author: Matthias Weiss, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Structured Text Language Conversion
11+
12+
#ifndef CPROVER_STRUCTURED_TEXT_CONVERTERS_CONVERT_INT_VALUE_H
13+
#define CPROVER_STRUCTURED_TEXT_CONVERTERS_CONVERT_INT_VALUE_H
14+
15+
#include <string>
16+
17+
#include <util/expr.h>
18+
#include <util/std_expr.h>
19+
20+
/// Converts a string into the corresponding 'Int' expression.
21+
/// \param src: String returned by the parser.
22+
/// \return Constant expression representing the integer value.
23+
constant_exprt convert_int_value(const std::string &src);
24+
25+
/// Converts a string into the corresponding 'Bool' expression.
26+
/// \param src: String returned by the parser.
27+
/// \return Constant expression representing the boolean value.
28+
constant_exprt convert_bit_value(const std::string &src);
29+
30+
#endif // CPROVER_STRUCTURED_TEXT_CONVERTERS_CONVERT_INT_VALUE_H
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*******************************************************************\
2+
3+
Module: Structured Text Language Conversion
4+
5+
Author: Matthias Weiss, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Structured Text Language Conversion
11+
12+
#include "convert_real_value.h"
13+
#include <util/ieee_float.h>
14+
#include <util/std_expr.h>
15+
16+
constant_exprt convert_real_value(const std::string &src)
17+
{
18+
floatbv_typet type = ieee_float_spect::single_precision().to_type();
19+
type.set(ID_structured_text_type, ID_structured_text_real_value);
20+
21+
return constant_exprt(src, type);
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*******************************************************************\
2+
3+
Module: Structured Text Language Conversion
4+
5+
Author: Matthias Weiss, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Structured Text Language Conversion
11+
12+
#ifndef CPROVER_STRUCTURED_TEXT_CONVERTERS_CONVERT_REAL_VALUE_H
13+
#define CPROVER_STRUCTURED_TEXT_CONVERTERS_CONVERT_REAL_VALUE_H
14+
15+
#include <string>
16+
17+
#include <util/expr.h>
18+
#include <util/std_types.h>
19+
20+
/// Converts a string into the corresponding 'Real' expression.
21+
/// \param src: String returned by the parser.
22+
/// \return Constant expression representing the real value.
23+
constant_exprt convert_real_value(const std::string &src);
24+
25+
#endif // CPROVER_STRUCTURED_TEXT_CONVERTERS_CONVERT_REAL_VALUE_H
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************\
2+
3+
Module: Structured Text Language Conversion
4+
5+
Author: Matthias Weiss, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Structured Text Language Conversion
11+
12+
#include "convert_string_value.h"
13+
14+
string_constantt convert_identifier(const std::string &src)
15+
{
16+
string_constantt result(src);
17+
result.set(ID_structured_text_type, ID_structured_text_identifier);
18+
return result;
19+
}
20+
21+
string_constantt convert_title(const std::string &src)
22+
{
23+
string_constantt result(src);
24+
result.set(ID_structured_text_type, ID_structured_text_title);
25+
return result;
26+
}
27+
28+
code_labelt convert_label(const std::string &src)
29+
{
30+
// Cut the trailing colon
31+
std::string value = src.substr(0, src.length() - 1);
32+
33+
return code_labelt(value, codet(ID_label));
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************\
2+
3+
Module: Structured Text Language Conversion
4+
5+
Author: Matthias Weiss, [email protected]
6+
7+
\*******************************************************************/
8+
9+
/// \file
10+
/// Structured Text Language Conversion
11+
12+
#ifndef CPROVER_STRUCTURED_TEXT_CONVERTERS_CONVERT_STRING_VALUE_H
13+
#define CPROVER_STRUCTURED_TEXT_CONVERTERS_CONVERT_STRING_VALUE_H
14+
15+
#include <util/expr.h>
16+
#include <util/std_code.h>
17+
#include <util/string_constant.h>
18+
19+
/// Converts a string into a Structured Text identifier.
20+
/// \param src: String returned by the parser.
21+
/// \return Constant string expression representing the identifier.
22+
string_constantt convert_identifier(const std::string &src);
23+
24+
/// Converts a string into a Structured Text title.
25+
/// \param src: String returned by the parser.
26+
/// \return Constant string expression representing the title.
27+
string_constantt convert_title(const std::string &src);
28+
29+
/// Converts a string into a Structured Text label.
30+
/// \param src: String returned by the parser.
31+
/// \return Code label expression representing the label.
32+
code_labelt convert_label(const std::string &src);
33+
34+
#endif // CPROVER_STRUCTURED_TEXT_CONVERTERS_CONVERT_STRING_VALUE_H
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
structured-text
2+
structured-text/converters
3+
util
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
converters
2+
langapi
3+
linking
4+
structured-text
5+
util

0 commit comments

Comments
 (0)