Lexical analysis system and method for SysML V2 language
By designing a lexical analysis system for the SysML V2 language, and employing character-by-character scanning and predefined concatenation rules, the system addresses the issues of insufficient recognition accuracy and low efficiency in SysML V2 lexical analysis. It achieves efficient and accurate lexical analysis and supports the extension and system integration of the SysML V2 language.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-03
- Publication Date
- 2026-03-13
AI Technical Summary
Existing technologies for lexical analysis of the SysML V2 language suffer from insufficient recognition accuracy, maintenance difficulties, low processing efficiency, and inadequate support for the unique syntax of the SysML V2 language, making it difficult to adapt to the needs of language evolution and system integration.
A lexical analysis system is adopted, which includes an input and file management module, a character type judgment module, a lexical unit recognition and extraction module, and an output and log module. Through character-by-character scanning and set concatenation rules, the system accurately identifies lexical objects of the SysML V2 language, and ensures the accuracy and efficiency of the analysis process through an error detection and processing module.
It achieves high-precision lexical analysis of the SysML V2 language, improves processing efficiency, avoids matching conflicts, supports the extension of the SysML V2 language, and has a complete error detection mechanism to ensure the robustness and reliability of the analysis process.
Smart Images

Figure CN121658006A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to lexical analysis of the SysML V2 language, and more specifically to a lexical analysis system and method for the SysML V2 language. Background Technology
[0002] SysML V2 is a next-generation systems modeling language developed under the leadership of the Object Management Group (OMG), aiming to comprehensively improve the expressiveness, interoperability, and automation support capabilities of systems modeling languages. Compared to SysML V1, SysML V2 has achieved profound innovations in its language architecture and adopts a unified meta-model structure based on KerML.
[0003] SysML V2's unified metamodel structure comprises three layers: concrete grammar, abstract grammar, and semantic layer. The concrete grammar includes two sub-layers: textual grammar and graphical grammar. The textual grammar, based on the Extended Backus Form (EBNF) definition, precisely specifies how lexical tags (including keywords, terminal symbols, and various grammatical rules) are combined to construct the abstract grammatical structure. This layered architecture not only enhances the clarity and precision of language expression but also provides a formal semantic foundation for model validation, automated reasoning, and behavioral simulation.
[0004] In the translation process from SysML V2 models to C++ interpreted code, the text representation in the concrete syntax layer plays a crucial role. It precisely defines the syntactic structure of the language, providing a direct foundation for the development of lexical analyzers and parsers. Simultaneously, the abstract syntax layer provides a semantically neutral structural framework, offering a standardized data model structure for the translator during the code generation phase.
[0005] Existing lexical analysis techniques for the SysML V2 language mainly include: (1) Lexical analysis method based on regular expressions. This method uses regular expressions to define lexical unit patterns and uses finite automata to identify input text. However, when processing the complex language SysML V2, the complexity of regular expressions increases dramatically, which can easily lead to matching conflicts. It is also difficult to accurately identify unique complex operators, resulting in insufficient recognition accuracy, maintenance difficulties, and low processing efficiency. (2) Tool-based lexical analyzers: Lexical analyzers automatically generated by tools such as Lex and Flex lack flexibility and scalability, are difficult to adapt to the evolution of SysML V2 language, and rely on third-party tools, which makes them easily restricted in system integration and customized development. (3) Model-driven lexical analysis method models lexical rules as platform-independent models and generates lexical analyzers for specific platforms through model transformation. It has good portability, but lacks support for the syntax specific to SysML V2 language. Summary of the Invention
[0006] To address the technical problems of insufficient recognition accuracy, maintenance difficulties, low processing efficiency, limitations in system integration and customized development, and insufficient support for the unique syntax of the SysML V2 language in existing lexical analysis technologies, this invention provides a lexical analysis system and method for the SysML V2 language.
[0007] To achieve the above objectives, the present invention adopts the following technical solution: This invention provides a lexical analysis system for the SysML V2 language, characterized in that it includes an input and file management module, a character type judgment module, a lexical unit recognition and extraction module, and an output and log module. The input and file management module is used to obtain the SysML source file address, find the source code text based on the source file address, scan the source code text character by character, obtain each character and then transmit it to the character type judgment module. The character type determination module is used to concatenate the received characters and the next received characters according to the set concatenation rules to form a lexical object, and then transmit the lexical object to the lexical unit recognition and extraction module in the form of a character stream; the lexical object includes single-line comments, multi-line comments, arithmetic operators, relational operators, identifiers, numbers, keywords, and delimiters as specified by the SysML V2 language; The lexical unit identification and extraction module is used to identify and extract lexical objects from the character stream, then perform lexical category matching on the lexical objects, encapsulate them into structured lexical units, and then transmit the lexical units to the output and log module. The output and log module is used to record and output lexical units, and at the same time record the execution process of each module, thereby completing the lexical analysis of the SysML V2 language.
[0008] Furthermore, the set splicing rules are as follows: When the received character is " / ", when the next received character is " / ", they are concatenated to form " / / ", forming a single-line comment; when the next received character is "*", and subsequent received characters contain "*" and " / " in sequence, they are concatenated to form " / ** / ", forming a multi-line comment; when the next received character is any other character, no concatenation is performed, and the received character " / " is directly used to form an arithmetic operator. When the received character is "'", all received characters are concatenated until the next received character is "'" to form an identifier; When the received character is a number, and the subsequent received characters are all numbers or decimal points, all characters are concatenated until the next received character is not a number or decimal point, at which point the concatenation stops and a number is formed. When the received character is a letter, and the subsequent received characters are all letters or numbers, all characters are concatenated until the next received character is not a letter or number. Then, the concatenation stops and it is determined whether the concatenated character is within the keyword set specified by the SysML V2 language. If it is, a keyword is formed; otherwise, an identifier is formed. When the received character is a delimiter, no concatenation is performed and the delimiter is formed directly; When the received characters are single-character operators, they are directly converted into arithmetic operators without concatenation. When the received character is a two-character operator prefix, including "=", "<", ">", and "!", the next received character is "=", then they are concatenated to form a relational operator; when the received two-character operator prefix is not "!" and the next received character is not "=", then no concatenation is performed, and an arithmetic operator is formed directly. When the received characters are single-character relational operators, no concatenation is performed to directly form a relational operator; When the received character is a double-character relational operator prefix ":", when the next received character is ":" or "=", they are concatenated to form "::" or ":=", thus forming a relational operator; when the next received character is any other character, no concatenation is performed, and the relational operator is formed directly. When the received character is a blank character, it is skipped without concatenation. When the received character is an unknown character, it is not concatenated and is marked as abnormal; If the received character and the next received character do not conform to the set concatenation rules, it is marked as abnormal; When the received character is the end-of-file character, no concatenation is performed, indicating that the file reading is complete.
[0009] Furthermore, it also includes an error detection and handling module, as well as an initialization and resource management module; The error detection and handling module is used to handle anomalies during the lexical analysis process and provide corresponding prompts based on the anomalies. The initialization and resource management module is used to initialize the parameters of each module and allocate resources for each module during execution.
[0010] Furthermore, the rules for matching the lexical object and the lexical category are as follows: If the lexical object is an arithmetic operator, then the corresponding lexical category is of type OPERATOR; If the lexical object is a relational operator, then the corresponding lexical category is of type RELATION_OPERATORS; If the lexical object is an identifier, then the corresponding lexical category is of type IDENTIFIER; If the lexical object is a number, then the corresponding lexical category is of type NUM; If the lexical object is a keyword, then the corresponding lexical category is of type KEYWORD; If the lexical object is a delimiter, then the corresponding lexical category is of type BORDER; If the lexical object is a single-line comment or a multi-line comment, no matching is performed, and it is directly transmitted to the output and logging module.
[0011] Meanwhile, this invention also provides a lexical analysis method for the SysML V2 language, which employs the aforementioned lexical analysis system for the SysML V2 language. Its unique feature lies in the inclusion of the following steps: S1. The input and file management module obtains the SysML source file address and finds the source code text based on the source file address; S2. The input and file management module scans the source code text character by character, obtains each character, and then transmits it to the character type judgment module. S3. The character type judgment module concatenates the received characters and the next received characters according to the set concatenation rules to form a lexical object, and then transmits the lexical object to the lexical unit recognition and extraction module in the form of a character stream; the lexical object includes single-line comments, multi-line comments, arithmetic operators, relational operators, identifiers, numbers, keywords, and delimiters as specified by the SysML V2 language; S4, the lexical unit identification and extraction module identifies and extracts lexical objects from the character stream, then performs lexical category matching on the lexical objects, encapsulates them into structured lexical units, and transmits the lexical units to the output and log module; S5, the output and log module records and outputs the lexical units. At the same time, it records the execution process of each module and returns to step S2 until the current character obtained is the end character. Then the SysML source file is read and the lexical analysis of the SysML V2 language is completed.
[0012] Furthermore, in step S3, the splicing rules are set as follows: If the received character is " / ", when the next received character is " / ", they are concatenated to form " / / ", creating a single-line comment; if the next received character is "*", and subsequent received characters contain "*" and " / " in sequence, they are concatenated to form " / ** / ", creating a multi-line comment; if the next received character is any other character, no concatenation is performed, and the received character " / " forms an arithmetic operator. When the received character is "'", all received characters are concatenated until the next received character is "'" to form an identifier; When the received character is a number, and the subsequent received characters are all numbers or decimal points, all characters are concatenated until the next received character is not a number or decimal point, at which point the concatenation stops and a number is formed. When the received character is a letter, and the subsequent received characters are all letters or numbers, all characters are concatenated until the next received character is not a letter or number. Then, the concatenation stops and it is determined whether the concatenated character is within the keyword set specified by the SysML V2 language. If it is, a keyword is formed; otherwise, an identifier is formed. When the received character is a delimiter, no concatenation is performed and the delimiter is formed directly; When the received characters are single-character operators, they are directly converted into arithmetic operators without concatenation. When the received character is a two-character operator prefix, including "=", "<", ">", and "!", the next received character is "=", then they are concatenated to form a relational operator; when the received two-character operator prefix is not "!" and the next received character is not "=", then no concatenation is performed, and an arithmetic operator is formed directly. When the received characters are single-character relational operators, no concatenation is performed to directly form a relational operator; When the received character is a double-character relational operator prefix ":", when the next received character is ":" or "=", they are concatenated to form "::" or ":=", thus forming a relational operator; when the next received character is any other character, no concatenation is performed, and the relational operator is formed directly. When the received character is a blank character, it is skipped without concatenation. When the received character is an unknown character, it is not concatenated and is marked as abnormal; If the received character and the next received character do not conform to the set concatenation rules, it is marked as abnormal; When the received character is the end-of-file character, no concatenation is performed, indicating that the file reading is complete.
[0013] Furthermore, in step S3, when an abnormality occurs during the splicing process, the abnormality is transmitted to the error detection and processing module, which processes the abnormality and provides corresponding prompts based on the abnormality.
[0014] Further, in step S4, the rule for matching the lexical object and the lexical category is as follows: If the lexical object is an arithmetic operator, then the corresponding lexical category is of type OPERATOR; If the lexical object is a relational operator, then the corresponding lexical category is of type RELATION_OPERATORS; If the lexical object is an identifier, then the corresponding lexical category is of type IDENTIFIER; If the lexical object is a number, then the corresponding lexical category is of type NUM; If the lexical object is a keyword, then the corresponding lexical category is of type KEYWORD; If the lexical object is a delimiter, then the corresponding lexical category is of type BORDER; If the lexical object is a single-line comment or a multi-line comment, no matching is performed, and it is directly transmitted to the output and logging module.
[0015] Furthermore, prior to step S1, the following steps are also included: S0, the initialization and resource management module initializes the parameters of each module and allocates resources for each module during execution; the parameters include row counters, column counters, and step counters; The input and file management module is equipped with a row counter and a column counter, both of which are initialized to 1. The row counter and column counter are updated according to the position of the characters during the character-by-character scanning of the source code text. The output and log module is equipped with a step counter, which is initialized to 1. The step counter is updated after the output and log module receives a lexical unit.
[0016] The beneficial effects of this invention are: 1. This invention provides a lexical analysis system for the SysML V2 language. By establishing an input and file management module, a character type judgment module, and a lexical unit recognition and extraction module, it can accurately assemble and recognize the lexical structure of SysML V2 text. This solves the technical problems of insufficient recognition accuracy, maintenance difficulties, low processing efficiency, easy limitations in system integration and customized development, and insufficient support for the unique syntax of the SysML v2 language in existing technologies. 2. This invention provides a lexical analysis method for the SysML V2 language, which can accurately concatenate and identify SysML V2-specific operators and keywords, avoiding mis-concatenation. Simultaneously, it performs precise matching and identification of all lexical objects, resolving the matching conflict problem present in existing technologies. By employing character-by-character scanning of source code text, it significantly improves lexical analysis speed, avoiding the performance overhead of using regular expression engines in existing technologies, making it particularly suitable for large-scale system models. Furthermore, it can be seamlessly integrated into the MDA compilation framework, without relying on any third-party libraries or regular expression engines, achieving a completely autonomous and controllable lexical analysis solution, and supporting future extensions of SysML V2 syntax. 3. The present invention provides a lexical analysis system for the SysML V2 language. Its error detection and processing module has a complete error detection mechanism, which intercepts lexical splicing errors in advance, reduces the risk of failure in the subsequent recognition and matching stage, and provides accurate error location information by referencing row counters and column counters, which facilitates rapid problem diagnosis and repair, and ensures the robustness of the lexical analysis process. Attached Figure Description
[0017] Figure 1 This is an overall architecture diagram of an embodiment of a lexical analysis system for the SysML V2 language according to the present invention; Figure 2 This is a flowchart illustrating an embodiment of a lexical analysis method for the SysML V2 language according to the present invention. Figure 3 This is a schematic diagram of the splicing rules for an embodiment of the lexical analysis method for the SysML V2 language according to the present invention. Figure 1 (For comments, identifiers, numbers, keywords, delimiters); Figure 4 This is a schematic diagram of the splicing rules for an embodiment of the lexical analysis method for the SysML V2 language according to the present invention. Figure 2 (For operators, whitespace characters, unknown characters, and terminators). Detailed Implementation
[0018] The technical solution of the present invention will be clearly and completely described below with reference to the embodiments. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0019] This embodiment presents a lexical analysis system and method for the SysML V2 language. It is an efficient lexical analysis system and method tailored to the characteristics of the SysML V2 language, capable of accurately identifying and processing the textual syntax structure of SysML V2, including its Extended Backus-Noor Normal Form (EBNF) syntax rules, keyword set, operator system, and various identifier types, providing a high-quality sequence of lexical units for subsequent syntax analysis and code generation.
[0020] This embodiment provides a lexical analysis system for the SysML V2 language. It employs a lexical analysis algorithm implemented in C++, without relying on any third-party lexical analysis tools or regular expression engines, achieving accurate identification and efficient processing of SysML V2 language lexical elements. Its architecture is as follows: Figure 1 As shown, it includes an input and file management module, a character type judgment module, a lexical unit recognition and extraction module, an output and log module, an error detection and handling module, and an initialization and resource management module; The input and file management module is used to obtain the SysML source file address, locate the source code text based on the source file address, scan the source code text character by character, obtain each character, and then transmit it to the character type judgment module. This module is the input foundation for lexical analysis and is responsible for the initialization of the source code file, character reading, and character position tracking.
[0021] The character type judgment module is used to concatenate the received characters and the next received characters according to the set concatenation rules to form a lexical object. After forming the lexical object, the lexical object is transmitted to the lexical unit recognition and extraction module in the form of a character stream. The lexical object includes single-line comments, multi-line comments, arithmetic operators, relational operators, identifiers, numbers, keywords, and delimiters as specified by the SysML V2 language. This module provides basic character classification and concatenation capabilities, providing key basis for the lexical unit recognition and extraction module. Through a series of dedicated judgment functions, it realizes the concatenation recognition of letters, numbers, single-character arithmetic operators, double-character arithmetic operator prefixes, single-character relational operators, double-character relational operator prefixes, and whitespace characters. The returned result after concatenation directly guides the subsequent lexical object extraction logic, ensuring that different types of characters can be correctly classified and processed.
[0022] The lexical unit identification and extraction module is used to identify and extract lexical objects from the character stream, then perform lexical category matching on the lexical objects, encapsulate them into structured lexical units, and transmit the lexical units to the output and log module. This module is responsible for identifying and extracting various lexical objects of the SysML V2 language from the character stream. By cyclically scanning characters, it processes comments, negative numbers, numbers, identifiers, keywords, delimiters, and operators according to priority, filters single-line / / and multi-line / * * / comments, identifies numbers containing negative numbers (including integers and floating-point numbers), special identifiers enclosed in single quotes, matches exclusive keywords through the KEYWORDS set, identifies delimiters through the BORDERS set, distinguishes between single and double character operators, further encapsulates the processing results, supplements the string representation of the lexical objects, triggers detailed output logic, and finally generates structured lexical units.
[0023] The output and log module is used to record and output lexical units, and to record the execution process of each module, thereby completing the lexical analysis of the SysML V2 language. This module is responsible for recording and outputting the lexical analysis results, supporting debugging and result traceability. When the detailed output mode is enabled, the step number, lexical unit type (array converted to readable string), value and exception warning of each analysis step are written to the specified log file, and the lexical analysis steps are recorded by a step counter to ensure that the analysis process is traceable and verifiable.
[0024] The initialization and resource management module is used to initialize parameters for each module and allocate resources for each module during execution. This module runs through the entire lifecycle of lexical analysis, responsible for parameter initialization and resource release. The constructor initializes the row counter, column counter, and step counter to 1 and disables verbose output mode by default, preparing for the analysis process. The destructor closes the opened source code file stream and log output file stream after the analysis is completed, releasing system resources, avoiding resource leaks, and ensuring the stable operation of the analysis process and the rational use of resources.
[0025] The error detection and handling module is used to handle anomalies during lexical analysis and provide corresponding prompts based on the anomalies. This module is responsible for identifying abnormal situations during lexical analysis and providing clear prompts. During scanning and concatenation, it will detect unclosed multi-line comments, unclosed single quote identifiers, and illegal characters that cannot match any rules (such as @, #). Once an error is detected, it will return a lexical object of type UNKNOWN, which contains the line number and column number of the erroneous character, and then output a warning message to terminate the analysis process in a timely manner, prevent the erroneous character from being passed to subsequent stages, and reduce the overall compilation risk.
[0026] Based on the SysML V2 language specification, this system explicitly defines the following main lexical objects and their corresponding algorithmic processing logic, as summarized in Table 1: Table 1 (1) Keywords: 98 system reserved words including about, abstract, accept, etc. Lexical analysis identifies them as KEYWORDS type and performs precise matching through a predefined KEYWORDS set; (2) Operators: They are further divided into arithmetic operators (such as +, -, *, / , =, etc.) and relational operators (such as ., ::, :=, :>, etc.), which are respectively classified as OPERATOR and RELATION_OPERATORS types; (3) Separators: including parentheses, curly braces and semicolons, etc. The system uniformly marks them as BORDER type to identify program structure boundaries; (4) Numeric literals: support the recognition of integer and floating-point values, and can handle negative signs and decimal parts, and are defined as NUM type; (5) Identifiers: encompass strings that begin with a letter, as well as named entities enclosed in single quotes (such as 'action test1'), all of which are classified as IDENTIFIER type and used to represent user-defined named objects such as variables and functions; (6) Comments and whitespace: The system actively ignores single-line comments ( / / ), multi-line comments ( / ** / ) and all whitespace characters (including spaces, newlines\n, tabs\t, and end-of-file markers EOF) during lexical analysis. These elements do not participate in subsequent lexical analysis.
[0027] This embodiment provides a lexical analysis method for the SysML V2 language. Through character stream processing, multi-level classification and recognition, finite state machine analysis, structured output, and a configurable control mechanism, it constructs a high-precision lexical analysis algorithm system for SysML V2. This system significantly improves processing efficiency while ensuring analysis accuracy, laying the foundation for the automated translation of SysML V2 models into target code (C++). Figure 2 As shown, it includes the following steps: S0, the initialization and resource management module initializes the parameters of each module and allocates resources for each module during execution; the parameters include a row counter, a column counter, and a step counter; the input and file management module has a row counter and a column counter, both initialized to 1, and the row counter and column counter are updated according to the position of the characters during the character-by-character scanning of the source code text; the output and log module has a step counter, initialized to 1, and the step counter is updated after each lexical unit is received.
[0028] S1. The input and file management module obtains the SysML source file address and locates the source code text based on the address. This process sequentially detects the attributes and combination features of each character, laying the foundation for subsequent lexical rule matching. By opening the SysML source file and the optional log output file .txt, the necessary resources for analysis are ensured to be ready. Then, the file characters are read sequentially, and the row counter and column counter are updated synchronously to accurately record the row and column positions of the current character, providing support for error location. The position information is dynamically updated while the character is being read, thus providing accurate row and column coordinate support in subsequent error reporting, debugging, and lexical location. Compared with the traditional static counting method, it has the advantages of strong real-time performance, low memory consumption, and high positioning accuracy.
[0029] S2. The input and file management module scans the source code text character by character, obtains each character, and then transmits it to the character type judgment module. S3. The character type judgment module concatenates the received characters and the next received characters according to the set concatenation rules to form a lexical object. The lexical object is then transmitted to the lexical unit recognition and extraction module in the form of a character stream. The lexical object includes single-line comments, multi-line comments, arithmetic operators, relational operators, identifiers, numbers, keywords, and delimiters as defined by the SysML V2 language. When an exception occurs during the concatenation process, it is transmitted to the error detection and handling module. The error detection and handling module processes the exception, terminates the current lexical analysis process, and provides corresponding prompts based on the exception to ensure the legality of the input code and the validity of the compilation process. Its core processing flow includes: intelligent comment processing, i.e., supporting the complete recognition and skipping of " / / " single-line comments and " / * * / " multi-line comments; and special identifier processing, i.e., supporting 'State' with single quotes. Actions type special identifier; numeric constant recognition, that is, it supports the complete recognition of integers and decimals, including the handling of negative signs; separation of keywords and identifiers, that is, it achieves fast classification through a predefined keyword table; hierarchical recognition of operators, that is, it uses a prefix prediction mechanism to distinguish between single-character and double-character operators; error recovery mechanism, that is, it provides accurate error location information for abnormal morphemes.
[0030] S4, the lexical unit identification and extraction module identifies and extracts lexical objects from the character stream, then performs lexical category matching on the lexical objects, encapsulates them into structured lexical units, and transmits the lexical units to the output and log module; if a matching failure occurs during the matching process, it is identified as a user-defined identifier and classified as IDENTIFIER type.
[0031] S5, the output and log module records and outputs lexical units. It also records the execution process of each module before returning to step S2. This continues until the current character is the end-of-line character, at which point the SysML source file reading is complete, and the lexical analysis of the SysML source file is finished. Its output processing flow includes type normalization (converting internal type encoding into readable string representations), value normalization (uniformly formatting specific types such as numbers and identifiers), detailed logging (supporting configurable detailed analysis process recording), and error reporting (providing precise row and column position information for unknown morphemes).
[0032] Upon identifying each complete lexical unit, the system outputs its word content and corresponding type, ultimately forming a structured lexical unit. This serves as input for the syntax analysis phase, providing a standardized and clearly categorized vocabulary flow for the subsequent construction of an abstract syntax tree.
[0033] In the above embodiments, such as Figure 3 and Figure 4 As shown, the splicing rules are set as follows: If the received character is " / ", when the next received character is " / ", they are concatenated to form " / / ", creating a single-line comment; if the next received character is "*", and subsequent received characters contain "*" and " / " in sequence, they are concatenated to form " / ** / ", creating a multi-line comment; if the next received character is any other character, no concatenation is performed, and the received character " / " forms an arithmetic operator. When the received character is "'", all received characters are concatenated until the next received character is "'" to form an identifier; When the received character is a number, and the subsequent received characters are all numbers or decimal points, all characters are concatenated until the next received character is not a number or decimal point, at which point the concatenation stops and a number is formed. When the received character is a letter, and the subsequent received characters are all letters or numbers, all characters are concatenated until the next received character is not a letter or number. Then, the concatenation stops and it is determined whether the concatenated character is within the keyword set specified by the SysML V2 language. If it is, a keyword is formed; otherwise, an identifier is formed. When the received characters are delimiters (such as {,}, (, ) etc.), they are directly formed into delimiters without concatenation; When the received characters are single-character operators, they are directly converted into arithmetic operators without concatenation. When the received character is a two-character operator prefix, including "=", "<", ">", and "!", the next received character is "=", then they are concatenated to form a relational operator; when the received two-character operator prefix is not "!" and the next received character is not "=", then no concatenation is performed, and an arithmetic operator is formed directly. When the received characters are single-character relational operators, no concatenation is performed to directly form a relational operator; When the received character is a double-character relational operator prefix ":", when the next received character is ":" or "=", they are concatenated to form "::" or ":=", thus forming a relational operator; when the next received character is any other character, no concatenation is performed, and the relational operator is formed directly. When the received character is a blank character, it is skipped without concatenation. When the received character is an unknown character, it is not concatenated and is marked as abnormal; If the received character and the next received character do not conform to the set concatenation rules, it is marked as abnormal; When the received character is the end-of-file character, no concatenation is performed, indicating that the file reading is complete.
[0034] In the above embodiments, the rules for matching lexical objects and lexical categories are as follows: If the lexical object is an arithmetic operator, then the corresponding lexical category is of type OPERATOR; If the lexical object is a relational operator, then the corresponding lexical category is of type RELATION_OPERATORS; If the lexical object is an identifier, then the corresponding lexical category is of type IDENTIFIER; If the lexical object is a number, then the corresponding lexical category is of type NUM; If the lexical object is a keyword, then the corresponding lexical category is of type KEYWORD; If the lexical object is a delimiter, then the corresponding lexical category is of type BORDER; If the lexical object is a single-line comment or a multi-line comment, no matching is performed, and it is directly transmitted to the output and logging module.
[0035] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present invention should be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A lexical analysis system for the SysML V2 language, characterized in that: It includes an input and file management module, a character type judgment module, a lexical unit recognition and extraction module, and an output and log module; The input and file management module is used to obtain the SysML source file address, find the source code text based on the source file address, scan the source code text character by character, obtain each character and then transmit it to the character type judgment module. The character type determination module is used to concatenate the received characters and the next received characters according to the set concatenation rules to form a lexical object, and then transmit the lexical object to the lexical unit recognition and extraction module in the form of a character stream. The lexical objects include single-line comments, multi-line comments, arithmetic operators, relational operators, identifiers, numbers, keywords, and delimiters as defined by the SysML V2 language; The lexical unit identification and extraction module is used to identify and extract lexical objects from the character stream, then perform lexical category matching on the lexical objects, encapsulate them into structured lexical units, and then transmit the lexical units to the output and log module. The output and log module is used to record and output lexical units, and at the same time record the execution process of each module, thereby completing the lexical analysis of the SysML V2 language.
2. The lexical analysis system for SysML V2 language according to claim 1, characterized in that, The established splicing rules are as follows: When the received character is / , and the next received character is / , they are concatenated to form / / , forming a single-line comment; when the next received character is *, and subsequent received characters contain * and / in sequence, they are concatenated to form / ** / , forming a multi-line comment; when the next received character is any other character, no concatenation is performed, and the received character / directly forms an arithmetic operator. When the received character is ', all received characters are concatenated until the next received character is ', to form an identifier; When the received character is a number, and the subsequent received characters are all numbers or decimal points, all characters are concatenated until the next received character is not a number or decimal point, at which point the concatenation stops and a number is formed. When the received character is a letter, and the subsequent received characters are all letters or numbers, all characters are concatenated until the next received character is neither a letter nor a number. Then, the concatenation stops, and it is determined whether the concatenated character is within the keyword set specified by the SysMLV2 language. If it is, a keyword is formed; otherwise, an identifier is formed. When the received character is a delimiter, no concatenation is performed and the delimiter is formed directly; When the received characters are single-character operators, they are directly converted into arithmetic operators without concatenation. When the received character is a two-character operator prefix, including =, <, >, and !, if the next received character is =, then concatenation is performed to form a relational operator; if the received two-character operator prefix is not ! and the next received character is not =, then no concatenation is performed, and arithmetic operators are formed directly. When the received characters are single-character relational operators, no concatenation is performed to directly form a relational operator; When the received character is a two-character relational prefix: , when the next received character is : or = , it is concatenated to :: or := to form a relational operator; when the next received character is any other character, no concatenation is performed, and the relational operator is formed directly. When the received character is a blank character, it is skipped without concatenation. When the received character is an unknown character, it is not concatenated and is marked as abnormal; If the received character and the next received character do not conform to the set concatenation rules, it is marked as abnormal; When the received character is the end-of-file character, no concatenation is performed, indicating that the file reading is complete.
3. A lexical analysis system for SysML V2 language according to claim 2, characterized in that: It also includes an error detection and handling module, as well as an initialization and resource management module; The error detection and handling module is used to handle anomalies during the lexical analysis process and provide corresponding prompts based on the anomalies. The initialization and resource management module is used to initialize the parameters of each module and allocate resources for each module during execution.
4. A lexical analysis system for SysML V2 language according to claim 3, characterized in that: The rules for matching the lexical object and the lexical category are as follows: If the lexical object is an arithmetic operator, then the corresponding lexical category is of type OPERATOR; If the lexical object is a relational operator, then the corresponding lexical category is of type RELATION_OPERATORS; If the lexical object is an identifier, then the corresponding lexical category is of type IDENTIFIER; If the lexical object is a number, then the corresponding lexical category is of type NUM; If the lexical object is a keyword, then the corresponding lexical category is of type KEYWORD; If the lexical object is a delimiter, then the corresponding lexical category is of type BORDER; If the lexical object is a single-line comment or a multi-line comment, no matching is performed, and it is directly transmitted to the output and logging module.
5. A lexical analysis method for the SysML V2 language, employing the lexical analysis system for the SysML V2 language as described in any one of claims 1-4, characterized in that, Includes the following steps: S1. The input and file management module obtains the SysML source file address and finds the source code text based on the source file address; S2. The input and file management module scans the source code text character by character, obtains each character, and then transmits it to the character type judgment module. S3. The character type judgment module concatenates the received characters and the next received characters according to the set concatenation rules to form a lexical object, and then transmits the lexical object to the lexical unit recognition and extraction module in the form of a character stream. The lexical objects include single-line comments, multi-line comments, arithmetic operators, relational operators, identifiers, numbers, keywords, and delimiters as defined by the SysML V2 language; S4, the lexical unit identification and extraction module identifies and extracts lexical objects from the character stream, then performs lexical category matching on the lexical objects, encapsulates them into structured lexical units, and transmits the lexical units to the output and log module; S5, the output and log module records and outputs the lexical units. At the same time, it records the execution process of each module and returns to step S2 until the current character obtained is the end character. Then the SysML source file is read and the lexical analysis of the SysML V2 language is completed.
6. The lexical analysis method for SysML V2 language according to claim 5, characterized in that: In step S3, the splicing rules are set as follows: If the received character is " / ", when the next received character is " / ", they are concatenated to form " / / ", forming a single-line comment; if the next received character is "*", and subsequent received characters contain "*" and " / " in sequence, they are concatenated to form " / ** / ", forming a multi-line comment; if the next received character is any other character, no concatenation is performed, and the received character " / " forms an arithmetic operator. When the received character is "', all received characters are concatenated until the next received character is "'" to form an identifier; When the received character is a number, and the subsequent received characters are all numbers or decimal points, all characters are concatenated until the next received character is not a number or decimal point, at which point the concatenation stops and a number is formed. When the received character is a letter, and the subsequent received characters are all letters or numbers, all characters are concatenated until the next received character is neither a letter nor a number. Then, the concatenation stops, and it is determined whether the concatenated character is within the keyword set specified by the SysMLV2 language. If it is, a keyword is formed; otherwise, an identifier is formed. When the received character is a delimiter, no concatenation is performed and the delimiter is formed directly; When the received characters are single-character operators, they are directly converted into arithmetic operators without concatenation. When the received character is a two-character operator prefix, including "=", "<", ">", and "!", when the next received character is "=", they are concatenated to form a relational operator; when the received two-character operator prefix is not "!" and the next received character is not "=", they are not concatenated and are directly used to form an arithmetic operator. When the received characters are single-character relational operators, no concatenation is performed to directly form a relational operator; When the received character is a double-character relational prefix ":", when the next received character is ":" or "=", they are concatenated to form "::" or ":=", thus forming a relational operator; when the next received character is any other character, no concatenation is performed, and the relational operator is formed directly. When the received character is a blank character, it is skipped without concatenation. When the received character is an unknown character, it is not concatenated and is marked as abnormal; If the received character and the next received character do not conform to the set concatenation rules, it is marked as abnormal; When the received character is the end-of-file character, no concatenation is performed, indicating that the file reading is complete.
7. A lexical analysis method for SysML V2 language according to claim 6, characterized in that: In step S3, when an abnormality occurs during the splicing process, the abnormality is transmitted to the error detection and processing module. The error detection and processing module processes the abnormality and provides corresponding prompts based on the abnormality.
8. A lexical analysis method for SysML V2 language according to claim 7, characterized in that: In step S4, the matching rule between the lexical object and the lexical category is as follows: If the lexical object is an arithmetic operator, then the corresponding lexical category is of type OPERATOR; If the lexical object is a relational operator, then the corresponding lexical category is of type RELATION_OPERATORS; If the lexical object is an identifier, then the corresponding lexical category is of type IDENTIFIER; If the lexical object is a number, then the corresponding lexical category is of type NUM; If the lexical object is a keyword, then the corresponding lexical category is of type KEYWORD; If the lexical object is a delimiter, then the corresponding lexical category is of type BORDER; If the lexical object is a single-line comment or a multi-line comment, no matching is performed, and it is directly transmitted to the output and logging module.
9. A lexical analysis method for SysML V2 language according to claim 8, characterized in that, Before step S1, the following is also included: S0, the initialization and resource management module initializes the parameters of each module and allocates resources for each module during execution; the parameters include row counters, column counters, and step counters; The input and file management module is equipped with a row counter and a column counter, both of which are initialized to 1. The row counter and column counter are updated according to the position of the characters during the character-by-character scanning of the source code text. The output and log module is equipped with a step counter, which is initialized to 1. The step counter is updated after the output and log module receives a lexical unit.