SysMLv2.0 text model synchronization method based on ANTLR
By building an ANTLR-based SysMLv2.0 text model synchronization method, the problems of insufficient parsing capabilities and inaccurate difference positioning in SysML modeling tools are solved, accurate model updates and cross-tool loading are achieved, and modeling consistency and automation levels are improved.
Patent Information
- Application Number
- CN202510835615.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-20
- Publication Date
- 2025-10-17
AI Technical Summary
Existing SysML modeling tools lack the standardized parsing capabilities for SysMLv2.0 text models, making it impossible to achieve accurate comparison and difference location. This leads to inconsistencies between models, redundant reconstruction, and difficulties in engineering traceability. In addition, the visual conversion of text models after export suffers from semantic mapping loss and format distortion.
An ANTLR-based SysMLv2.0 text model synchronization method is constructed. The grammatical parsing is performed through the Lexer lexical analyzer and the Parser syntax analyzer, an abstract syntax tree is generated, and a mapping relationship between syntax nodes and semantic model elements is established. The model differences are identified and incremental synchronization updates are performed to generate modeling text that conforms to the SysMLv2.0 standard syntax format.
It achieves accurate updating and cross-tool loading of SysMLv2.0 text models, improves modeling consistency management capabilities, supports multi-tool integration and multi-person collaboration, and improves the degree of automation of the system modeling process.
Smart Images

Figure CN120805889A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of system modeling language processing and model-driven engineering technology, and particularly relates to a SysMLv2.0 text model synchronization method based on ANTLR. BACKGROUND
[0002] With the in-depth development of model-driven engineering and model-based system engineering, SysML (Systems Modeling Language) as a general-purpose modeling language for system modeling is widely used in complex system requirement modeling, structure modeling, behavior modeling and constraint modeling. Since the release of SysMLv2.0 draft, it has introduced text-based modeling syntax support, allowing modelers to directly define system model structure and behavior logic in code form, significantly improving the flexibility and automation processing capability of modeling expression. At the same time, with the increasing demand for collaborative development, version evolution and parallel use of heterogeneous modeling tools, the synchronization and consistency management of SysMLv2.0 text model has gradually become prominent.
[0003] In the prior art, for the parsing and synchronization of SysML text model, it is mostly dependent on the special format processing module encapsulated in the internal of specific modeling tools (such as MagicDraw, Cameo, Papyrus). These modules often only support the loading and saving of specific model fragments, lack independent parsing capability for the complete language structure of SysMLv2.0, and do not have an open semantic extraction mechanism. In the context of text model version management and multi-source model fusion, the existing technology generally adopts a coarse-grained strategy of static text comparison or model full replacement, which is difficult to accurately identify the subtle differences in the modeling structure hierarchy, leading to inconsistency between models, redundant reconstruction and difficulty in engineering traceability. In addition, in the process of bidirectional conversion between text input and graphical output, the current modeling tools generally have the problems of missing semantic mapping, format distortion and loss of visual information, which seriously affect the continuity and maintainability of the modeling process.
[0004] Specifically, the existing SysML modeling environment generally has the following technical defects: first, it lacks a standardized text model syntax parsing engine, and cannot structure abstract and semantic recognition of SysMLv2.0 text modeling language; second, it lacks a synchronization mechanism based on syntax tree and semantic model, and cannot realize accurate comparison and difference positioning of models between different versions or sources; third, the existing synchronization methods mostly use manual copying, graphical export or full file replacement, lack incremental recognition capability for local modifications, leading to serious model redundancy update and high maintenance cost; finally, the visualization conversion of text model after export highly depends on the private interface of modeling tools, and lacks a cross-tool model consistency guarantee mechanism.
[0005] To solve the above problems, the application provides a SysMLv2.0 text model synchronization method based on ANTLR, a complete SysMLv2.0 language syntax rule is constructed, a Lexer lexical analyzer and a Parser syntax analyzer are generated, the original modeling text is structurally parsed and an abstract syntax tree is constructed, a mapping relationship between a syntax node and a semantic model element is further established, core modeling elements such as structure, connection, port, behavior and constraint are extracted, and a semantic model structure that can be compared and reconstructed is formed. On this basis, the semantic structure of multiple version models is respectively processed, the semantic basis of different models is unified through path reduction, naming consistency and reference format alignment, then, a model difference comparison algorithm at the attribute level is used to identify the semantic change content of the types of addition, deletion and modification, and the text model is incrementally synchronized and updated based on a difference positioning table, finally, an ANTLR output module is called to generate modeling text in accordance with the syntax format of the SysMLv2.0 standard, the model is deserialized and loaded across tools, and the visualization restoration in the graphical modeling tool is supported. The application solves the problems in the prior art that the processing granularity of the SysMLv2.0 text model is coarse, the difference positioning is inaccurate, the synchronization mode is inefficient, and the visualization reconstruction is strongly dependent, significantly improves the automation degree and the model consistency management capability of the system modeling process, and is suitable for complex system engineering modeling scenarios such as multi-tool integration, multi-person cooperation and cross-version maintenance.
[0006] Therefore, how to provide a SysMLv2.0 text model synchronization method based on ANTLR is a problem that those skilled in the art need to solve. SUMMARY
[0007] An object of the application is to provide a SysMLv2.0 text model synchronization method based on ANTLR, the application constructs a SysMLv2.0 text model parsing and synchronization system based on ANTLR, supports model syntax tree construction, semantic structure extraction, difference identification and incremental synchronization, solves the problems in the prior art that the model version comparison is coarse, the structure is not unified, and the synchronization efficiency is low, realizes accurate updating and cross-tool loading of the model text, and improves the modeling consistency and automation level.
[0008] According to the SysMLv2.0 text model synchronization method based on ANTLR, the following steps are included:
[0009] S1, constructing a syntax parsing framework of the SysMLv2.0 modeling language based on ANTLR, the syntax parsing framework comprising defining the lexical rules and the syntax rules of the SysMLv2.0 modeling language, and generating a Lexer lexical analyzer and a Parser syntax analyzer for syntax analysis;
[0010] S2, parsing the original SysMLv2.0 text model by using the ANTLR syntax analyzer to generate an abstract syntax tree AST containing structural elements, behavioral elements and constraint elements, for representing the syntax structure of the SysMLv2.0 model;
[0011] S3, constructing an intermediate semantic model structure of the SysMLv2.0 model based on the abstract syntax tree, the intermediate semantic model structure containing model structures, connection relationships, port configurations, behavioral processes and attribute constraints by mapping syntax nodes to semantic elements;
[0012] S4, performing S1 to S3 on a plurality of SysMLv2.0 text models to be synchronized respectively to construct original model semantic structures and target model semantic structures, and performing standardization processing on element identifiers, namespaces and reference paths in the semantic models;
[0013] S5, performing semantic difference comparison on the original model semantic structure and the target model semantic structure to identify added, deleted and modified differences of the model in the structure layer, the connection layer and the constraint layer, and generating a difference list containing difference types, difference positions and modification contents;
[0014] S6, performing an incremental synchronization operation of the SysMLv2.0 text model according to the difference list, the incremental synchronization operation comprising inserting, deleting or replacing related model statements in the original model text according to the difference types, and keeping the syntax structure integrity of the synchronized model;
[0015] S7, converting the synchronized semantic model structure into a SysMLv2.0 modeling language text, calling an ANTLR output module to generate a text representation conforming to the syntax specification according to the semantic model, and completing a deserialization process of the model;
[0016] S8, outputting the SysMLv2.0 text model file after synchronization, the output comprising saving the generated text file to a specified path, and providing a graphical modeling tool to load to complete visual presentation and subsequent modeling operations of the model.
[0017] Optionally, the Lexer lexical analyzer and the Parser syntax analyzer for syntax analysis specifically comprise:
[0018] S11, the Lexer lexical analyzer is used to define the lexical rules of the SysMLv2.0 language based on regular expressions, to build a set of lexical units including keywords, identifiers, data types, operators and separators, and to perform character-by-character scanning on the input SysMLv2.0 modeling text to generate an ordered sequence of lexical units;
[0019] S12, the Parser syntax analyzer is used to define the syntax rules of the SysMLv2.0 language based on context-free grammars, to build a syntax description structure including a set of non-terminal symbols, a set of terminal symbols, a starting symbol and a set of productions;
[0020] S13, the Parser syntax analyzer receives the lexical unit sequence output by the Lexer, performs recursive descent syntax analysis according to the syntax description structure, and generates an abstract syntax tree with a model structure as the root node, each node of the abstract syntax tree corresponding to a non-terminal and a terminal in the syntax rule;
[0021] S14, the Parser syntax analyzer performs structure legality verification on the completed abstract syntax tree, confirms that all leaf nodes are legal lexical units and all paths conform to the defined syntax production rules, and takes the verified abstract syntax tree as the input structure for subsequent semantic model mapping and model difference analysis.
[0022] Optionally, the S2 specifically comprises:
[0023] S21, load the Lexer lexical analyzer and the Parser syntax analyzer, and preprocess the SysMLv2.0 modeling text, the Lexer lexical analyzer identifies keywords, identifiers, type names, operators and structural separators in the modeling text to form an ordered lexical unit sequence;
[0024] S22, input the lexical unit sequence to the Parser syntax analyzer, and the Parser performs top-down recursive syntax matching according to the syntax rules of SysMLv2.0 to build an abstract syntax tree from the model starting structure, the non-terminal nodes of the abstract syntax tree representing the composition of the model structure, and the terminal nodes corresponding to the actual lexical units;
[0025] S23, perform a traversal operation on the completed abstract syntax tree to identify model structure units, extract the type information, name, nesting level, parent-child relationship and source text position index of each structure unit, including the starting line number and ending column number;
[0026] S24, perform a subtree extraction operation on the behavior semantics and constraint semantics part of the abstract syntax tree to identify control flow expressions, Boolean conditions, nested operators and numerical constraint statements, and output a set of semantic subtrees for subsequent semantic mapping;
[0027] S25, performing structure normalization processing on the abstract syntax tree, removing empty nodes, merging duplicate syntax branches, and completing omitted statements to ensure that the generated syntax tree meets the requirements of completeness, uniqueness, and syntax closure;
[0028] S26, constructing a model structure dependency table according to the node relationships in the normalized abstract syntax tree, the dependency table recording the reference path, dependency order, and nesting range between structure units in a two-dimensional mapping form, for expressing the structure dependency of modeling elements;
[0029] S27, outputting the normalized abstract syntax tree and the corresponding model structure dependency table, and using them as input data structures for subsequent semantic mapping, difference identification, and synchronization processing.
[0030] Optionally, the S3 specifically includes:
[0031] S31, based on the constructed abstract syntax tree, extracting a set of syntax nodes, performing type identification on each node, and dividing the nodes into model structure nodes, connection relationship nodes, port configuration nodes, behavior flow nodes, and attribute constraint nodes according to structure types;
[0032] S32, constructing a corresponding semantic model element for each syntax node, establishing a mapping relationship from syntax to semantics, and defining a mapping function as mapping a syntax node to a semantic model element, each semantic model element including type, name, level, and parent-child dependency information;
[0033] S33, constructing an attribute set for each semantic model element, the attribute set including element name, semantic type, scope range, and connection relationship with other elements, for expressing the context and dependency path in the modeling structure;
[0034] S34, constructing a semantic model tree according to the reference, nesting, and connection relationships between semantic model elements, the semantic model tree taking structure elements as the main trunk, connection relationships, port configurations, behavior flows, and constraint conditions as subsidiary substructures, forming a complete SysMLv2.0 semantic expression system;
[0035] S35, recording the location range of each semantic model element in the original SysMLv2.0 modeling text to form a semantic mapping table, each record in the semantic mapping table including element identification, starting line number, and ending line number, for subsequent difference positioning and model rewriting;
[0036] S36, performing structure integrity checking on the semantic model tree to confirm that all semantic elements have associated paths, and all references and level definitions can be traced back in the syntax tree, ensuring semantic structure closure and clear relationships;
[0037] S37, output the semantic model tree and the semantic mapping table as the basic data structure for the subsequent steps of semantic difference identification, synchronous execution and text generation.
[0038] Optionally, the S4 specifically comprises:
[0039] S41, performing the steps S1 to S3 on the original version SysMLv2.0 text model and the target version SysMLv2.0 text model respectively to construct the original semantic model and the target semantic model, wherein the semantic models both include structural elements, connection relationships, port configurations, behavior processes and attribute constraints;
[0040] S42, extracting the identifiers of all semantic model elements in the original semantic model and the target semantic model, and performing uniform format processing on all the identifiers, wherein the format processing includes uniform case, standardized name prefix and suffix, and elimination of special characters and redundant symbols, so as to ensure that the same semantic element has consistent naming representation in different model versions;
[0041] S43, extracting the namespace path of each semantic model element, performing hierarchical analysis on the namespace according to the four-level structure of model, package, subsystem and module, classifying all elements under the corresponding namespace, and constructing a namespace index structure;
[0042] S44, identifying all internal reference relationships existing in the semantic model, and extracting the reference paths between elements, wherein the paths are represented in the form of namespace plus element name, and include structural hierarchy and reference direction information;
[0043] S45, performing standardized conversion on the original reference path and the target reference path respectively, unifying the path separator format, eliminating path hierarchy inconsistency and naming misalignment, and performing full path replacement on the relative path to form a standard reference path set;
[0044] S46, re-injecting the identifiers, namespace paths and reference paths after the standardization processing into the original semantic model and the target semantic model, replacing the original naming information and reference fields, and forming a standardized semantic model with unified structure specification;
[0045] S47, outputting the semantic model structure after the completion of the standardization processing as the basic data input for the subsequent semantic difference comparison and model synchronization operation.
[0046] Optionally, the S5 specifically comprises:
[0047] S51, receiving the standardized original semantic model and the target semantic model output according to claim 5, extracting the structural elements, connection elements, port elements, behavior elements and constraint elements therefrom, and classifying and preparing comparison according to semantic types;
[0048] S52, match all semantic elements in two semantic models by element type and namespace, if element name, type and path are completely consistent, it is considered as a candidate alignment, and an alignment pair set is established, each pair set contains an original element and a target element;
[0049] S53, perform attribute comparison on the original element and the target element in each alignment pair set, the attributes include name, semantic type, scope, reference path and parent-child structure relationship, if any field value is inconsistent, it is marked as "modification difference";
[0050] S54, when there is a semantic element in the target semantic model and there is no corresponding matching item in the original semantic model, it is marked as "add difference"; when there is a semantic element in the original semantic model and there is no corresponding matching item in the target semantic model, it is marked as "delete difference";
[0051] S55, all difference results are summarized to generate a difference list, each record in the difference list includes difference type, difference element name, belonging namespace, difference field and its change value, the difference type includes three types of addition, deletion and modification;
[0052] S56, according to the semantic mapping table in claim 4, the position information of the difference element in the original SysMLv2.0 text model is obtained, the start line number and the end line number of each difference element are extracted, and a difference positioning table is constructed, the difference positioning table is used to guide the local replacement of the text model;
[0053] S57, output the difference list and the difference positioning table as the input data structure of the S6 step in claim 1 to perform incremental synchronization processing.
[0054] Optionally, the S6 specifically comprises:
[0055] S61, receive the difference list and the difference positioning table output in claim 6, determine the specific element set that needs to be synchronized and updated in the original SysMLv2.0 text model, and classify the synchronization operation according to the difference type;
[0056] S62, for the element with the difference type of "add", according to the structure position in the target semantic model, insert the text representation of the semantic element under the corresponding namespace or structure node of the original model, and the insertion position is determined according to the parent node line number recorded in the difference positioning table;
[0057] S63, for the element with the difference type of "delete", perform the whole text deletion operation according to the start line number and the end line number of the element in the difference positioning table in the original model text, and remove the connection path and the constraint statement associated with the element;
[0058] S64. For elements with a difference type of "modification", extract the text fragment of the corresponding semantic element in the original model and perform field-level replacement based on the corresponding element attribute value in the target model, including element name, type, port configuration, constraint expression and behavior content;
[0059] S65. When performing an insert, delete, or replace operation, the indentation format, grammatical structure, and line break strategy of the text model are kept consistent, ensuring that all synchronized texts conform to the left and right structure requirements of each production in the ANTLR grammar rule definition;
[0060] S66. Perform a complete syntax check on the synchronized original model text, use the Parser syntax analyzer to rebuild the abstract syntax tree, and confirm that all changed locations have corresponding mappings in the syntax tree and there are no syntax conflicts or dangling references;
[0061] S67. Output the updated text that has passed the syntax check as the model version after synchronization is completed, and retain the corresponding update record, including the synchronization type, operation location, modification content and change time, to form a synchronization log for audit tracking and version management.
[0062] Optionally, the S7 specifically includes:
[0063] S71, receiving the semantic model after synchronization processing in claim 7, and calling the ANTLR output module to perform a text generation operation based on the attribute set of each semantic model element in the semantic structure tree, including name, type, namespace and connection relationship;
[0064] S72. Construct a corresponding modeling language sentence fragment for each semantic model element. The sentence fragment is generated by reverse engineering the nodes of the Parser syntax tree according to SysMLv2.0 syntax rules, and its structure satisfies the construction requirements of each right-hand symbol string in the production rule P.
[0065] S73. Assemble the sentence fragments of the multiple semantic model elements according to their hierarchical relationship in the semantic model tree. If two elements have a containment relationship, their corresponding text sentences maintain a nested format. If two elements have a connection relationship, a path reference syntax is introduced into the sentence to indicate the connection target.
[0066] S74. All the sentence fragments are spliced together to form a complete SysMLv2.0 model text. During the splicing process, uniform indentation, line separators, and structural comments are maintained to generate a text file model Text_out that conforms to the grammatical specification. The Text_out satisfies the reversible reconstruction condition of the abstract syntax tree constructed by ANTLR.
[0067] S75, call the Lexer and Parser modules to perform a complete integrity analysis on Text_out, reconstruct the abstract syntax tree AST_check and compare it with the synchronized pre-semantic model structure tree for consistency, if the structure, quantity and semantic identification in AST_check match the semantic model, it is determined that the text output is valid;
[0068] S76, save Text_out as the final synchronization result as a standard SysMLv2.0 modeling language file, and record its path, version information and timestamp in the version control table for subsequent model version evolution and engineering traceability analysis;
[0069] S77, output Text_out and the version control table as input data sources in the subsequent modeling tool loading, graphical visualization and automated modeling process.
[0070] Optionally, the S8 specifically comprises:
[0071] S81, receive the standardized SysMLv2.0 text model file output in claim 8, save the file to a specified output path, generate a modeling file named with a model identifier and a timestamp, and the output format is ".sysml";
[0072] S82, perform format verification and information extraction on the output text file, the extracted content includes model name, structure body quantity, behavior model quantity, total line number and update time, and the above information is arranged into a model metadata table for subsequent version management and visualization;
[0073] S83, load the output text file into a graphical modeling tool supporting the SysMLv2.0 standard, call the text parsing interface provided by the modeling tool to perform model import, and the import process includes two stages of syntax structure analysis and semantic element identification;
[0074] S84, after completing the model loading in the graphical modeling tool, render the definition graph, internal connection graph, port graph and state graph visualization interface according to the semantic structure, and the rendering operation is performed according to the default view template of the modeling tool;
[0075] S85, record the model file path, model basic information, modeling tool loading state and rendering completion time, generate a model loading log, and the log includes a model identifier, a tool response result and an associated version number;
[0076] S86, output the model text file, the model metadata table and the loading log for visual review, structure verification and subsequent model expansion by modeling personnel.
[0077] The beneficial effects of the present application are:
[0078] The application provides a complete structure, fine processing, automatic process and strong traceability system solution, and has significant beneficial technical effects.
[0079] Firstly, the application constructs an ANTLR grammar analysis framework which completely covers the language structure of SysMLv2.0, can automatically generate high-precision Lexer lexical analyzer and Parser syntax analyzer, and realizes accurate identification and classified abstraction of structural elements, behavior description and constraint expression in modeling text. The mechanism breaks through the technical bottleneck that the existing modeling tool has limited support for SysML text modeling and depends on private engine for syntax processing, and provides a technical basis for realizing model structure analysis independent of the tool platform.
[0080] Secondly, the application constructs a semantic model structure based on the abstract syntax tree, comprehensively extracts the type, scope, namespace and reference path of the model element, and forms a standardized, mappable and locatable semantic representation system. By uniformly standardizing the naming, hierarchical path and reference relationship in the model to be synchronized, the structural alignment capability between different versions or different modeling sources is greatly improved, and the problem that the existing model is difficult to compare under the condition of inconsistent naming and chaotic hierarchy is effectively solved.
[0081] In addition, the application designs a difference analysis mechanism based on semantic attribute comparison, can accurately identify the addition, deletion and modification operations of structure, connection, port, behavior and constraint layer in the semantic model, and generate a structured difference list and positioning information table. Combined with the difference information, the application further supports the incremental synchronization of the text model according to the difference type, avoids the structural redundancy brought by full model coverage, and greatly improves the efficiency and safety of model modification. At the same time, the original syntax structure and format style of the model are maintained in the synchronization operation, the generated update text conforms to the SysMLv2.0 language specification defined by ANTLR, and the syntax closure of the model structure and the tool analyzability are ensured.
[0082] Finally, the present invention realizes automatic deserialization of the updated semantic model through the ANTLR output module, outputs standardized SysMLv2.0 modeling language text, and supports importing into mainstream graphic modeling tools for visual loading. The output file has a complete grammatical structure, accurate model expression and version recording functions, supports modeling tools for graphic presentation, structural navigation and model expansion, significantly improves the consistency and reconfigurability between text models and graphic models, and meets the comprehensive needs of model collaborative development, version control and traceable modeling in engineering practice. The method proposed in the present invention not only improves the grammatical parsing depth and structural abstraction capabilities of the SysMLv2.0 text model, but also realizes accurate comparison and automatic incremental synchronization between multiple versions of models, and closes the whole process from parsing to reconstruction through deserialization and visual output, and has strong engineering applicability, technological advancement and promotion value. BRIEF DESCRIPTION OF THE DRAWINGS
[0083] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0084] Fig. 1 This is the overall flow chart of the SysMLv2.0 text model synchronization method based on ANTLR proposed by the present invention;
[0085] Fig. 2 This is a flowchart of the abstract syntax tree generation and semantic structure mapping of the SysMLv2.0 text model synchronization method based on ANTLR proposed by the present invention;
[0086] Fig. 3 The present invention proposes a model output and graphic modeling tool loading structure diagram of a SysMLv2.0 text model synchronization method based on ANTLR. DETAILED DESCRIPTION
[0087] The present invention will now be described in further detail with reference to the accompanying drawings, which are simplified schematic diagrams that illustrate the basic structure of the present invention in a schematic manner.
[0088] refer to Figs. 1-3 , a SysMLv2.0 text model synchronization method based on ANTLR, comprising the following steps:
[0089] S1. Constructing a syntax parsing framework of the SysMLv2.0 modeling language based on ANTLR, wherein the syntax parsing framework includes defining lexical rules and grammatical rules of the SysMLv2.0 modeling language and generating a Lexer lexical analyzer and a Parser grammatical analyzer for syntax analysis;
[0090] S2, parse the original SysMLv2.0 text model using the ANTLR grammar analyzer to generate an abstract syntax tree AST containing structural elements, behavioral elements and constraint elements, for representing the syntax structure of the SysMLv2.0 model;
[0091] S3, based on the abstract syntax tree, build the intermediate semantic model structure of the SysMLv2.0 model, which contains model structure, connection relationship, port configuration, behavior flow and attribute constraint by mapping syntax nodes to semantic elements;
[0092] S4, perform S1 to S3 on each of the plurality of SysMLv2.0 text models to be synchronized to build the original model semantic structure and the target model semantic structure, and standardize the element identification, namespace and reference path in the semantic model;
[0093] S5, perform semantic difference comparison on the original model semantic structure and the target model semantic structure to identify the addition, deletion and modification differences of the model in the structure layer, connection layer and constraint layer, and generate a difference list containing the difference type, difference location and modification content;
[0094] S6, perform incremental synchronization operation of the SysMLv2.0 text model according to the difference list, the incremental synchronization operation including inserting, deleting or replacing related model statements in the original model text according to the difference type, and keeping the syntax structure integrity of the synchronized model;
[0095] S7, convert the synchronized semantic model structure into SysMLv2.0 modeling language text, call the ANTLR output module to generate text representation conforming to the syntax specification according to the semantic model, and complete the deserialization process of the model;
[0096] S8, output the synchronized SysMLv2.0 text model file, the output including saving the generated text file to a specified path, and loading the text file into a graphical modeling tool to complete the visual presentation and subsequent modeling operation of the model.
[0097] The present application establishes a complete SysMLv2.0 text model synchronization method based on ANTLR, realizes the whole process closed loop from model text analysis, semantic structure extraction, model standardization, difference identification, incremental update to text generation and visualization loading. The method makes up for the short board of the existing tool chain in the aspect of insufficient text processing ability of SysMLv2.0, has the advantages of strong integrity, high automation and good integrability, significantly improves the version consistency guarantee ability in the system modeling process, and is especially suitable for version evolution and content tracing scenes in multi-team collaborative development and model life cycle management.
[0098] In this embodiment, the Lexer lexical analyzer and the Parser syntax analyzer for syntax analysis specifically include:
[0099] S11, the Lexer lexical analyzer is used to define the lexical rules of the SysMLv2.0 language based on regular expressions, to construct a set of lexical units including keywords, identifiers, data types, operators and separators, and to perform character-by-character scanning on the input SysMLv2.0 modeling text to generate an ordered sequence of lexical units;
[0100] S12, the Parser syntax analyzer is used to define the syntax rules of the SysMLv2.0 language based on context-free grammar, to construct a syntax description structure including a set of non-terminal symbols, a set of terminal symbols, a starting symbol and a set of productions;
[0101] S13, the Parser syntax analyzer receives the lexical unit sequence output by the Lexer, performs recursive descent syntax analysis according to the syntax description structure, and generates an abstract syntax tree with a model structure as the root node, each node of the abstract syntax tree corresponding to a non-terminal symbol and a terminal symbol in the syntax rule;
[0102] S14, the Parser syntax analyzer performs structure legality verification on the constructed abstract syntax tree, confirms that all leaf nodes are legal lexical units, all paths conform to the defined syntax production rules, and takes the verified abstract syntax tree as the input structure for subsequent semantic model mapping and model difference analysis.
[0103] By constructing a special Lexer and Parser module for the SysMLv2.0 language, the present application realizes high-precision recognition of all lexical and syntax structures in the text model, avoiding the problem of parsing failure or structure error caused by inconsistent syntax and ambiguous expression in the traditional model import mechanism. ANTLR as the underlying parsing engine not only supports complex syntax nesting processing, but also can be extended to support SysML syntax updates, enhancing the adaptability and evolution ability of the parsing system, and providing strong technical support for building a standardized foundation for model parsing.
[0104] In this embodiment, the S2 specifically includes:
[0105] S21, load the Lexer lexical analyzer and the Parser syntax analyzer, and preprocess the SysMLv2.0 modeling text, the Lexer lexical analyzer identifies keywords, identifiers, type names, operators and structural separators in the modeling text to form an ordered sequence of lexical units;
[0106] S22, input the word sequence to a Parser grammar analyzer, the Parser performs top-down recursive grammar matching according to the grammar rules of SysMLv2.0, and an abstract syntax tree is constructed from a model starting structure, wherein a non-terminal node of the abstract syntax tree represents a model structure composition, and a terminal node corresponds to an actual word;
[0107] S23, performing a traversal operation on the constructed abstract syntax tree, identifying model structure units, and extracting type information, name, nesting level, parent-child relationship and source text position index of each structure unit, including a starting line number and an ending column number;
[0108] S24, performing a sub-tree extraction operation on the behavior semantics and constraint semantics part of the abstract syntax tree, identifying control flow expressions, Boolean conditions, nested operators and numerical constraint statements, and outputting a semantic sub-tree set for subsequent semantic mapping;
[0109] S25, performing structure normalization processing on the abstract syntax tree, removing empty nodes, merging duplicate syntax branches, and completing omitted statements, to ensure that the generated syntax tree meets the requirements of completeness, uniqueness and syntax closure;
[0110] S26, constructing a model structure dependency table according to the node relationship in the normalized abstract syntax tree, wherein the dependency table records the reference path, dependency order and nesting range between structure units in a two-dimensional mapping form, for expressing the structure dependency of modeling elements;
[0111] S27, outputting the normalized abstract syntax tree and the corresponding model structure dependency table, and taking them as input data structures for subsequent semantic mapping, difference identification and synchronization processing.
[0112] Based on the completion of the syntax tree generation, the original syntax structure is converted into a modeling element with engineering semantics through structure traversal and classification extraction, realizing the key transition from syntax table to semantic representation of the model. Especially, the hierarchical extraction of behavior control flow, nested constraints, semantic position and other information improves the accuracy of modeling semantic understanding, and provides a clear and analyzable basic structure for subsequent semantic modeling and structure change tracking.
[0113] In the embodiment, the S3 specifically comprises:
[0114] S31, based on the constructed abstract syntax tree, extracting a syntax node set, performing type identification on each node, and dividing the nodes into model structure nodes, connection relationship nodes, port configuration nodes, behavior flow nodes and attribute constraint nodes according to structure types;
[0115] S32, constructing a corresponding semantic model element for each syntax node, establishing a mapping relationship from syntax to semantics, and mapping function is defined as mapping syntax node to semantic model element, each semantic model element includes type, name, hierarchy and parent-child dependency information;
[0116] S33, constructing an attribute set for each semantic model element, the attribute set includes element name, semantic type, scope range and connection relationship with other elements, for expressing context and dependency path in modeling structure;
[0117] S34, constructing a semantic model tree according to the reference, nesting and connection relationship between the semantic model elements, the semantic model tree takes the structural element as the main stem, and the connection relationship, port configuration, behavior flow and constraint condition as the subsidiary substructure, forming a complete SysMLv2.0 semantic expression system;
[0118] S35, recording the position range of each semantic model element in the original SysMLv2.0 modeling text to form a semantic mapping table, each record in the semantic mapping table includes element identification, starting line number and ending line number, for subsequent difference positioning and model rewriting;
[0119] S36, performing structural integrity checking on the semantic model tree, confirming that all semantic elements have associated paths, and all references and hierarchy definitions can be traced back in the syntax tree, ensuring that the semantic structure is closed and the relationship is clear;
[0120] S37, outputting the semantic model tree and the semantic mapping table as the basic data structure for subsequent semantic difference identification, synchronization execution and text generation.
[0121] With the help of the mapping mechanism from AST to semantic structure, the application constructs a semantic model tree with clear structure, complete type and clear hierarchy, and establishes a bidirectional mapping relationship between each element and its source text, effectively solving the problem of lack of semantic consistent expression between graphics and text in traditional modeling tools. The mechanism improves the model traceability and traceability, and is suitable for the structure tracing requirements in engineering change management and complex system verification.
[0122] In the embodiment, the S4 specifically includes:
[0123] S41, respectively performing S1 to S3 steps on the original version SysMLv2.0 text model and the target version SysMLv2.0 text model, constructing an original semantic model and a target semantic model, the semantic model includes structural elements, connection relationships, port configurations, behavior flows and attribute constraints;
[0124] S42, extract identifiers of all semantic model elements in the original semantic model and the target semantic model, perform uniform format processing on all identifiers, the format processing including uniform case, standardizing prefix and suffix of name, removing special characters and redundant symbols, ensuring consistent naming representation of the same semantic element in different model versions;
[0125] S43, extract the namespace path of each semantic model element, perform hierarchical parsing on the namespace according to the four-level structure of model, package, subsystem and module, classify all elements under the corresponding namespace, and build a namespace index structure;
[0126] S44, identify all internal reference relationships existing in the semantic model, extract the reference path between elements, the path is in the form of namespace plus element name, including structure level and reference direction information;
[0127] S45, standardize the original reference path and the target reference path respectively, unify the path separator format, eliminate the inconsistency of path level and the misalignment of name, and replace the relative path with the full path to form a standard reference path set;
[0128] S46, re-inject the identifiers, namespace paths and reference paths after standardization into the original semantic model and the target semantic model, replace the original naming information and reference field, and form a standardized semantic model with uniform structure;
[0129] S47, output the semantic model structure after completing the standardization process as the basic data input for subsequent semantic difference comparison and model synchronization operation.
[0130] For the naming conflict and path misplacement problems common in inconsistent versions and heterogeneous team modeling, the application unifies the identification, naming format and reference path structure of the modeling elements, realizes the normalization of modeling structure across versions and files. This standardization process not only improves the accuracy of difference comparison, but also lays a foundation for subsequent automatic merging, model fusion and semantic unification, significantly enhancing the model collaboration and alignment capability in the modeling environment.
[0131] In the embodiment, the S5 specifically includes:
[0132] S51, receive the standardized original semantic model and the target semantic model output according to claim 5, extract the structure elements, connection elements, port elements, behavior elements and constraint elements therein, and classify and prepare according to the semantic type;
[0133] S52, match all semantic elements in two semantic models by element type and namespace in a one-to-one manner, if the element name, type and path are completely consistent, it is considered as a candidate alignment item, and an alignment pair set is established, each group of the alignment pair set contains an original element and a target element;
[0134] S53, perform attribute comparison on the original element and the target element in each alignment pair set, the attributes include name, semantic type, belonging scope, reference path and parent-child structure relationship, if any field value is inconsistent, it is marked as "modification difference";
[0135] S54, when there is a certain semantic element in the target semantic model and there is no corresponding matching item in the original semantic model, it is marked as "new difference"; when there is a certain semantic element in the original semantic model and there is no corresponding matching item in the target semantic model, it is marked as "deletion difference";
[0136] S55, all difference results are summarized to generate a difference list, each record in the difference list includes difference type, difference element name, belonging namespace, difference field and its change value, the difference type includes three types of addition, deletion and modification;
[0137] S56, according to the semantic mapping table in claim 4, the position information of the difference element in the original SysMLv2.0 text model is obtained, the start line number and the end line number of each difference element are extracted, and a difference positioning table is constructed, the difference positioning table is used to guide the local replacement of the text model;
[0138] S57, output the difference list and the difference positioning table as the input data structure of the S6 step in claim 1 to perform incremental synchronization processing.
[0139] The application realizes accurate identification of addition, deletion and modification types of differences by comparing the differences of modeling elements at the attribute level, and can map back to the original text position to construct a difference positioning table. This mechanism breaks through the limitation of the existing model comparison tool which can only provide structural level change prompt and cannot realize text level change tracking, and provides high-precision and operable data basis for realizing difference-driven model updating and version evolution control.
[0140] In the embodiment, the S6 specifically includes:
[0141] S61, receive the difference list and the difference positioning table output in claim 6, determine the specific element set that needs to be synchronized and updated in the original SysMLv2.0 text model, and classify the synchronization operation according to the difference type;
[0142] S62, for the element with the difference type of "add", inserting the text representation of the semantic element under the namespace or structure node corresponding to the original model according to the structure position in the target semantic model, and the insertion position is determined according to the parent node line number recorded in the difference positioning table;
[0143] S63, for the element with the difference type of "delete", performing a whole text deletion operation in the original model text according to the start line number and the end line number of the element in the difference positioning table, and simultaneously removing the connection path and the constraint statement associated with the element;
[0144] S64, for the element with the difference type of "modify", extracting the text segment of the corresponding semantic element in the original model, and performing field-level replacement according to the attribute values of the corresponding element in the target model, including element name, type, port configuration, constraint expression and behavior content;
[0145] S65, when performing the insertion, deletion or replacement operation, the indentation format, syntax structure and line break strategy of the text model are kept consistent, and it is ensured that all the synchronized texts meet the left part and right part structure requirements of each production in the ANTLR grammar rule definition;
[0146] S66, performing a complete syntax verification on the synchronized original model text, using the Parser syntax analyzer to reconstruct the abstract syntax tree, confirming that all change positions have corresponding mappings in the syntax tree, and there is no syntax conflict or dangling reference;
[0147] S67, outputting the updated text that passes the syntax verification as the model version after synchronization is completed, and retaining the corresponding update record, including the synchronization type, operation position, modification content and change time, forming a synchronization log for audit tracking and version management.
[0148] Unlike the traditional model synchronization strategy which needs to replace the whole file, the application realizes "partial synchronization" processing of the text model by constructing the linkage mechanism between the difference type and the positioning information. The difference items of addition, deletion and modification can be respectively executed to perform accurate insertion, positioning deletion or field-level update, thereby greatly reducing unnecessary structure rewriting, improving model evolution efficiency, and maximizing the structure logic and semantic style of the original modeler.
[0149] In the embodiment, the S7 specifically comprises:
[0150] S71, receiving the semantic model after the synchronization processing in claim 7 is completed, calling the ANTLR output module to perform text generation operation according to the attribute set of each semantic model element in the semantic structure tree, including name, type, namespace and connection relationship;
[0151] S72, constructing corresponding modeling language sentence fragments for each semantic model element, the sentence fragments being reversely generated from nodes of the Parser syntax tree according to SysMLv2.0 syntax rules, and the structure satisfying the construction requirement of each right part symbol string in the production rule P;
[0152] S73, assembling the sentence fragments of the plurality of semantic model elements according to the hierarchical relationship in the semantic model tree, if two elements have a containing relationship, the corresponding text sentences are kept in a nested format, and if two elements have a connection relationship, a path reference syntax is introduced in the sentences to represent a connection target;
[0153] S74, splicing all the sentence fragments to form a complete SysMLv2.0 model text, keeping uniform indentation, line separators and structure annotations during the splicing process, generating a text file model Text_out that meets the syntax specification, and the Text_out satisfies the reversible reconstruction condition of the abstract syntax tree constructed by ANTLR;
[0154] S75, calling the Lexer and Parser modules to perform a complete integrity analysis on Text_out, reconstructing the abstract syntax tree AST_check and comparing it with the synchronous previous semantic model structure tree for consistency, if the structure, quantity and semantic identifier in AST_check all match the semantic model, it is determined that the text output is valid;
[0155] S76, saving Text_out as a final synchronization result as a standard SysMLv2.0 modeling language file, and recording its path, version information and timestamp in the version control table for subsequent model version evolution and engineering traceability analysis;
[0156] S77, outputting Text_out and the version control table as input data sources in the subsequent modeling tool loading, graphical visualization and automated modeling process.
[0157] The application generates a modeling language text that meets the SysMLv2.0 syntax specification through the deserialization processing of the semantic model structure, ensures that the output content is not only structurally complete, but also semantically accurate. The process cooperates with the output rule control mechanism of ANTLR to ensure the bidirectional consistency of the generated text and the syntax tree structure, so that the updated model can be immediately loaded and used by the modeling tool, eliminating the risk of format loss and semantic drift in the conversion process.
[0158] In the embodiment, the S8 specifically includes:
[0159] S81, receiving the standardized SysMLv2.0 text model file output in claim 8, saving the file to a specified output path, generating a modeling file named with model identification and timestamp, and outputting the file in ".sysml" format;
[0160] S82, performing format verification and information extraction on the output text file, extracting model name, structure quantity, behavior model quantity, total line number, and update time, and arranging the above information into a model metadata table for subsequent version management and visualization;
[0161] S83, loading the output text file into a graphical modeling tool supporting SysMLv2.0 standard, calling the text parsing interface provided by the modeling tool to perform model import, which includes two stages of syntax structure parsing and semantic element recognition;
[0162] S84, after completing the model loading in the graphical modeling tool, rendering the definition graph, internal connection graph, port graph, and state graph visualization interface according to the semantic structure, and performing the rendering operation according to the default view template of the modeling tool;
[0163] S85, recording the model file path, model basic information, modeling tool loading state, and rendering completion time, generating a model loading log, and the log includes model identification, tool response result, and associated version number;
[0164] S86, outputting the model text file, model metadata table, and loading log for modeling personnel to perform visual review, structure verification, and subsequent model expansion.
[0165] In the model output stage, the present application realizes the whole process closed loop from text to graphical view by exporting standardized modeling language text file, generating metadata information and supporting graphical modeling tool loading. The visualization loading process not only preserves the structure information of the semantic model, but also restores the graph element through the view template, significantly improves the model display effect, structure review efficiency and cross-tool integration capability, and meets the strict requirements of enterprise-level modeling engineering for the consistency of "structure-semantic-view".
[0166] Embodiment 1:
[0167] To verify the feasibility of the application in practice, the application is applied to a certain large-scale aviation power equipment R&D enterprise's model development project as an application background. The project adopts the MBSE method to organize multiple R&D centers to model in parallel, establishes independent SysML models around the air path system, electronic control system, fuel system and health monitoring system of the aero-engine whole machine, and integrates and manages through the main model. In the modeling process, the team gradually migrates from the graphical modeling tool to the text modeling interface to improve the modeling efficiency, so the SysMLv2.0 text language is used to express the model. With the expansion of the model size and the increase of the team collaboration density, the model synchronization and consistency maintenance face obvious technical bottlenecks, the main problems are concentrated in the frequent version conflicts, inconsistent grammar, inefficient manual merging, update deletion and other aspects, which seriously affect the system integration efficiency and model credibility.
[0168] To solve the above problems, the project team introduces the SysMLv2.0 text model synchronization method based on ANTLR proposed in the application, and carries out landing verification in two rounds of model version iteration. The test platform is deployed on the private modeling server of the unit, and the environment configuration is as follows: the server model is Dell PowerEdge R740, equipped with dual Intel Xeon Gold6230R processor, 256GB memory, 4TB SSD storage, the operating system is Ubuntu Server 22.04, the SysMLv2.0 model version is the March 2024 draft, and the ANTLR version is 4.13.
[0169] In practical application, first, the SysMLv2.0 text model submitted by each subsystem team is input into the ANTLR syntax parsing framework, and the system automatically generates an abstract syntax tree and constructs a semantic model structure accordingly. Taking the health monitoring system as an example, the original text model file is about 7,200 lines, and the ANTLR parsing takes 1.8 seconds, and the generated abstract syntax tree contains 19,874 nodes. Subsequently, the system compares and analyzes its integrated model version with the air path system, and finds that there are 132 difference items in total, including 48 new items, 27 deleted items and 57 modified items. Each difference generates corresponding difference type, influence range, text positioning and other data, and the overall difference identification accuracy reaches 100%, which is about 8 times more efficient than the original manual checking process used by the team.
[0170] After the difference comparison, the system performs an incremental synchronization operation of the text model according to the difference list. Taking the modification item as an example, the port definition is changed from "sensorPort" to "diagnosticPort" in the target model, the system automatically locates to the range of the 421st to 426th lines of the original text, and replaces the corresponding structure statement to complete the field-level update. The whole synchronization process takes 2.4 seconds, which reduces the processing time by about 85% compared with the full file replacement operation, and completely retains the original annotations, indentation and syntax structure of the model.
[0171] The synchronized semantic model is generated into a standard SysML v2.0 modeling language text through ANTLR deserialization, and is imported into a MagicDraw modeling tool for visual verification. The import success rate is 100%, and the Block diagram and StateMachine diagram rendered are completely consistent with the expected structure, without node drift, path loss or type confusion problems. The model structure integrity verification is performed by using a self-developed verification tool, and the result shows that the structure consistency rate is 99.93%, which is much higher than about 85.4% of the previous manual comparison method.
[0172] In addition, in order to further verify the model consistency maintenance capability, the team introduces an automated regression testing mechanism, performs five rounds of continuous update simulation on the model, involves more than 2,300 lines of text changes, and changes 428 modeling elements. The final model structure still maintains the semantic consistency of the whole process. In this test cycle, the method is used to perform model synchronization 72 times, with a total time of 185 seconds, an average processing time of about 2.57 seconds each time, which is significantly better than the original manual synchronization process (about 17 minutes on average each time), and a total labor time of more than 35 hours is saved.
[0173] As can be seen from the above specific application practice, the present application has stable, efficient and precise technical advantages in the aspects of SysML v2.0 text model analysis, modeling semantic structure extraction, difference positioning, local update and tool visualization integration. The method not only solves the common problems of text model distortion, difficulty in comparison, slow update and the like in large system engineering projects, but also has strong universality and expandability, and is suitable for complex product research and development environment with model as the core. Its popularization and application can greatly reduce the cooperation cost, maintenance cost and error repair cost of system modeling team, thereby improving the system design quality and development efficiency.
[0174] The above is only the preferred specific embodiment of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can make equivalent replacement or change according to the technical scheme and inventive concept of the present application within the technical range disclosed by the present application, which should be covered within the protection scope of the present application.
Claims
1. A SysMLv2.0 text model synchronization method based on ANTLR, characterized in that: The steps include: S1. Constructing a syntax parsing framework of the SysMLv2.0 modeling language based on ANTLR, wherein the syntax parsing framework includes defining lexical rules and grammatical rules of the SysMLv2.0 modeling language and generating a Lexer lexical analyzer and a Parser grammatical analyzer for syntax analysis; S2. Parse the original SysMLv2.0 text model using the ANTLR parser to generate an abstract syntax tree (AST) containing structural elements, behavioral elements, and constraint elements, which is used to represent the grammatical structure of the SysMLv2.0 model. S3. Constructing an intermediate semantic model structure of the SysMLv2.0 model based on the abstract syntax tree. The intermediate semantic model structure includes model structure, connection relationship, port configuration, behavior flow and attribute constraints by mapping syntax nodes to semantic elements. S4. Execute S1 to S3 for each of the multiple SysMLv2.0 text models to be synchronized, construct the semantic structure of the original model and the semantic structure of the target model, and standardize the element identifiers, namespaces, and reference paths in the semantic models. S5. Perform semantic difference comparison between the original model semantic structure and the target model semantic structure, identify the addition, deletion, and modification differences of the model at the structure layer, connection layer, and constraint layer, and generate a difference list including the difference type, difference location, and modification content; S6. Performing an incremental synchronization operation of the SysMLv2.0 text model according to the difference list, wherein the incremental synchronization operation includes inserting, deleting, or replacing relevant model statements in the original model text according to the difference type, so as to maintain the grammatical structure integrity of the synchronized model; S7, converting the synchronized semantic model structure into SysMLv2.0 modeling language text, calling the ANTLR output module to generate a text representation that conforms to the grammatical specification based on the semantic model, and completing the deserialization process of the model; S8. Outputting the synchronized SysMLv2.0 text model file. The outputting includes saving the generated text file to a specified path and providing it for loading by a graphical modeling tool to complete the model visualization and subsequent modeling operations.
2. A SysMLv2.0 text model synchronization method based on ANTLR according to claim 1, characterized in that, The Lexer lexical analyzer and Parser grammatical analyzer for grammatical analysis specifically include: S11. The Lexer lexical analyzer is used to define the lexical rules of the SysMLv2.0 language based on regular expressions, construct a set of lexical units including keywords, identifiers, data types, operators, and separators, and perform character-by-character scanning on the input SysMLv2.0 modeling text to generate an ordered sequence of lexical units; S12. Parser is used to define the grammatical rules of SysMLv2.0 language based on context-free grammar, and to construct a grammatical description structure including a non-terminal symbol set, a terminal symbol set, a start symbol, and a production rule set; S13. The Parser receives the lexical unit sequence output by the Lexer, performs recursive descent grammar analysis based on the grammatical description structure, and generates an abstract syntax tree with the model structure as the root node. Each node of the abstract syntax tree corresponds to a non-terminal symbol and a terminal symbol in the grammatical rule; S14. The Parser performs a structural validity check on the constructed abstract syntax tree to confirm that all leaf nodes are legal lexical units and all paths comply with the defined grammatical production rules. The abstract syntax tree that passes the check is used as the input structure for subsequent semantic model mapping and model difference analysis.
3. A SysMLv2.0 text model synchronization method based on ANTLR according to claim 1, characterized in that, The S2 specifically includes: S21. Load the Lexer lexical analyzer and the Parser syntax analyzer to preprocess the SysMLv2.0 modeling text. The Lexer lexical analyzer identifies keywords, identifiers, type names, operators, and structure delimiters in the modeling text to form an ordered sequence of lexical units. S22. Input the lexical unit sequence into the Parser syntax analyzer. The Parser performs a top-down recursive syntax matching based on the syntax rules of SysMLv2.0 and constructs an abstract syntax tree from the model starting structure. The non-terminal symbol nodes of the abstract syntax tree represent the model structure components, and the terminal symbol nodes correspond to the actual lexical units. S23. Perform a traversal operation on the constructed abstract syntax tree to identify model structural units, and extract the type information, name, nesting level, parent-child relationship, and source text position index of each structural unit, including the starting row number and ending column number; S24, performing a subtree extraction operation on the behavioral semantics and constraint semantics parts in the abstract syntax tree, identifying control flow expressions, Boolean conditions, nested operators, and numerical constraint statements, and outputting a semantic subtree set for subsequent semantic mapping; S25. Perform structural normalization on the abstract syntax tree, remove empty nodes, merge duplicate syntax branches, and complete omitted statements to ensure that the generated syntax tree meets the requirements of completeness, uniqueness, and grammatical closure; S26. Constructing a model structure dependency table based on the node relationships in the normalized abstract syntax tree. The dependency table records reference paths, dependency orders, and nested scopes between structural units in a two-dimensional mapping format, and is used to express the structural dependencies of modeling elements. S27. Output the normalized abstract syntax tree and the corresponding model structure dependency table, and use them as the input data structure for subsequent semantic mapping, difference identification, and synchronization processing.
4. A SysMLv2.0 text model synchronization method based on ANTLR according to claim 1, characterized in that, The S3 specifically includes: S31. Based on the constructed abstract syntax tree, extract the syntax node set, perform type identification on each node, and divide the nodes into model structure nodes, connection relationship nodes, port configuration nodes, behavior process nodes, and attribute constraint nodes according to the structure type; S32. Construct a corresponding semantic model element for each syntax node and establish a mapping relationship from syntax to semantics. The mapping function is defined as mapping the syntax node to the semantic model element. Each semantic model element includes type, name, hierarchy, and parent-child dependency information. S33. Construct an attribute set for each semantic model element. The attribute set includes the element name, semantic type, scope, and connection relationship with other elements, which is used to express the context and dependency path in the modeling structure; S34. Construct a semantic model tree based on the reference, nesting, and connection relationships between the semantic model elements. The semantic model tree has structural elements as the main trunk and connection relationships, port configurations, behavior processes, and constraints as subsidiary substructures, forming a complete SysMLv2.0 semantic expression system. S35. Record the position range of each semantic model element in the original SysMLv2.0 modeling text to form a semantic mapping table. Each record in the semantic mapping table contains an element identifier, a starting line number, and an ending line number for subsequent difference location and model writeback. S36. Verify the structural integrity of the semantic model tree to confirm that all semantic elements have associated paths and that all references and hierarchical definitions can be traced in the syntax tree to ensure that the semantic structure is closed and the relationships are clear. S37. Output the semantic model tree and semantic mapping table as the basic data structure for semantic difference recognition, synchronous execution, and text generation in subsequent steps.
5. A SysMLv2.0 text model synchronization method based on ANTLR according to claim 1, characterized in that, The S4 specifically includes: S41. Execute steps S1 to S3 on the original version SysMLv2.0 text model and the target version SysMLv2.0 text model respectively to construct an original semantic model and a target semantic model, wherein the semantic models both include structural elements, connection relationships, port configurations, behavior processes, and attribute constraints. S42. Extract identifiers of all semantic model elements in the original semantic model and the target semantic model, and perform unified formatting on all identifiers. The formatting includes unifying uppercase and lowercase letters, standardizing naming prefixes and suffixes, and removing special characters and redundant symbols to ensure that the same semantic element has consistent naming representation in different model versions. S43. Extract the namespace path of each semantic model element, perform hierarchical parsing on the namespace according to the four-level structure of model, package, subsystem, and module, classify all elements into the corresponding namespace, and build a namespace index structure; S44. Identify all internal reference relationships in the semantic model and extract reference paths between elements. The paths are represented in the form of namespace plus element name, including structural hierarchy and reference direction information. S45. Standardize the original reference path and the target reference path respectively, unify the path separator format, eliminate the path hierarchy inconsistency and naming misalignment problems, and replace the relative path with the full path to form a standard reference path set; S46. Re-injecting the standardized identifier, namespace path, and reference path into the original semantic model and the target semantic model, replacing the original naming information and reference fields, to form a standardized semantic model with a unified structure. S47. Output the semantic model structure that has completed the standardization process as the basic data input for subsequent semantic difference comparison and model synchronization operations.
6. The SysMLv2.0 text model synchronization method based on ANTLR according to claim 1, characterized in that: The S5 specifically includes: S51, receiving the standardized original semantic model and the target semantic model output according to claim 5, extracting the structural elements, connection elements, port elements, behavior elements, and constraint elements therein, and performing classification and comparison according to semantic types; S52, performing a one-to-one match on all semantic elements in the two semantic models by element type and namespace. If the element name, type, and path are completely consistent, they are considered candidate comparison items, and a set of comparison pairs is established, where each pair contains an original element and a target element; S53. Perform attribute comparison on the original element and the target element in each comparison pair. The attributes include name, semantic type, scope, reference path, and parent-child structure relationship. If any field value is inconsistent, it is marked as "modification difference"; S54: When a semantic element exists in the target semantic model but has no corresponding matching item in the original semantic model, it is marked as "added difference"; when a semantic element exists in the original semantic model but has no corresponding matching item in the target semantic model, it is marked as "deleted difference"; S55. Summarize all the difference results to generate a difference list. Each record in the difference list includes the difference type, the difference element name, the namespace to which it belongs, the difference field, and its changed value. The difference types include addition, deletion, and modification. S56. According to the semantic mapping table in claim 4, obtain the position information of the difference elements in the original SysMLv2.0 text model, extract the starting line number and the ending line number of each difference element, and construct a difference positioning table, wherein the difference positioning table is used to guide the partial replacement of the text model; S57. Output the difference list and the difference location table as the input data structure for performing the incremental synchronization process in step S6 of claim 1.
7. The SysMLv2.0 text model synchronization method based on ANTLR according to claim 1, characterized in that: The S6 specifically includes: S61. Receive the difference list and difference location table output in claim 6, determine a specific set of elements that need to be synchronized and updated in the original SysMLv2.0 text model, and classify the synchronization operations according to the difference type; S62. For elements with a difference type of "newly added," insert the text representation of the semantic element under the corresponding namespace or structural node in the original model according to its structural position in the target semantic model. The insertion position is determined by the row number of the parent node recorded in the difference location table. S63. For an element with a difference type of "delete," perform a deletion operation on the entire text in the original model text according to its starting and ending line numbers in the difference location table, and simultaneously remove the connection path and constraint statements associated with the element. S64. For elements with a difference type of "modified", extract the text fragment of the corresponding semantic element in the original model and perform field-level replacement based on the corresponding element attribute value in the target model, including element name, type, port configuration, constraint expression, and behavior content; S65. When performing an insert, delete, or replace operation, the indentation format, grammatical structure, and line break strategy of the text model are kept consistent, ensuring that all synchronized texts conform to the left and right structure requirements of each production in the ANTLR grammar rule definition; S66. Perform a complete syntax check on the synchronized original model text, use the Parser syntax analyzer to rebuild the abstract syntax tree, and confirm that all changed locations have corresponding mappings in the syntax tree and there are no syntax conflicts or dangling references; S67. Output the updated text that has passed the syntax check as the model version after synchronization is completed, and retain the corresponding update record, including the synchronization type, operation location, modification content and change time, to form a synchronization log for audit tracking and version management.
8. The SysMLv2.0 text model synchronization method based on ANTLR according to claim 1, wherein: The S7 specifically includes: S71, receiving the semantic model after synchronization processing in claim 7, and calling the ANTLR output module to perform a text generation operation based on the attribute set of each semantic model element in the semantic structure tree, including name, type, namespace and connection relationship; S72. Construct a corresponding modeling language sentence fragment for each semantic model element. The sentence fragment is generated by reverse engineering the nodes of the Parser syntax tree according to SysMLv2.0 syntax rules, and its structure satisfies the construction requirements of each right-hand symbol string in the production rule P. S73. Assemble the sentence fragments of the multiple semantic model elements according to their hierarchical relationship in the semantic model tree. If two elements have a containment relationship, their corresponding text sentences maintain a nested format. If two elements have a connection relationship, a path reference syntax is introduced into the sentence to indicate the connection target. S74. All the sentence fragments are spliced together to form a complete SysMLv2.0 model text. During the splicing process, uniform indentation, line separators, and structural comments are maintained to generate a text file model Text_out that conforms to the grammatical specification. The Text_out satisfies the reversible reconstruction condition of the abstract syntax tree constructed by ANTLR. S75. Call the Lexer and Parser modules to perform a completeness analysis on Text_out, reconstruct the abstract syntax tree AST_check, and compare it with the semantic model structure tree before synchronization. If the structure, quantity, and semantic identifiers in AST_check all match the semantic model, the text output is determined to be valid. S76. Save Text_out as the final synchronization result as a standard SysMLv2.0 modeling language file, and record its path, version information, and timestamp in the version control table for subsequent model version evolution and engineering traceability analysis. S77. Output Text_out and the version control table as the input data source for subsequent modeling tool loading, graphic visualization, and automated modeling processes.
9. The SysMLv2.0 text model synchronization method based on ANTLR according to claim 1, wherein: The S8 specifically includes: S81. Receive the standardized SysMLv2.0 text model file output in claim 8, save the file to a specified output path, generate a modeling file named with a model identifier and a timestamp, and output the file in a ".sysml" format; S82. Perform format verification and information extraction on the output text file. The extracted content includes the model name, number of structures, number of behavior models, total number of rows, and update time. The above information is organized into a model metadata table for subsequent version management and visualization. S83, loading the output text file into a graphical modeling tool that supports the SysMLv2.0 standard, calling a text parsing interface provided by the modeling tool to perform model import, wherein the import process includes two stages: grammatical structure parsing and semantic element recognition; S84, after the model is loaded into the graphical modeling tool, a definition diagram, an internal connection diagram, a port diagram, and a state diagram visualization interface are rendered according to the semantic structure, and the rendering operation is performed according to a default view template of the modeling tool; S85, recording the model file path, basic model information, modeling tool loading status, and rendering completion time, and generating a model loading log, wherein the log includes the model identifier, tool response result, and associated version number; S86. Output model text files, model metadata tables, and loading logs for modelers to use for visual review, structural verification, and subsequent model expansion.
Citation Information
Cited By
Code generation method based on unidirectional mapping synchronization and incremental updating
CN121680910A