CN117008919A - Analysis method and device of simulation model file, electronic equipment and storage medium - Google Patents

Analysis method and device of simulation model file, electronic equipment and storage medium Download PDF

Info

Publication number
CN117008919A
CN117008919A CN202310980594.6A CN202310980594A CN117008919A CN 117008919 A CN117008919 A CN 117008919A CN 202310980594 A CN202310980594 A CN 202310980594A CN 117008919 A CN117008919 A CN 117008919A
Authority
CN
China
Prior art keywords
data
parser
file
lexical
analyzer
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310980594.6A
Other languages
Chinese (zh)
Inventor
陆雍
郑建国
包刚强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Pera Corp Ltd
Original Assignee
Pera Corp Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Pera Corp Ltd filed Critical Pera Corp Ltd
Priority to CN202310980594.6A priority Critical patent/CN117008919A/en
Publication of CN117008919A publication Critical patent/CN117008919A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F30/00Computer-aided design [CAD]
    • G06F30/20Design optimisation, verification or simulation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/37Compiler construction; Parser generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/425Lexical analysis
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application relates to a simulation model file analysis method and device, electronic equipment and storage medium. The method comprises the following steps: obtaining a simulation model file and an analyzer interface corresponding to the simulation model file, then calling a lexical analyzer and a grammar analyzer which are associated with the analyzer interface, generating a file analyzer according to the lexical analyzer and the grammar analyzer, carrying out data analysis processing on the simulation model file by adopting the file analyzer to obtain a target data structure corresponding to the data analysis processing, and inputting the target data structure into a preset electromagnetic solver to obtain analysis data for the simulation model file. The scheme provided by the application can optimize the data analysis effect and improve the maintainability and expansibility of the data analyzer.

Description

Analysis method and device of simulation model file, electronic equipment and storage medium
Technical Field
The present application relates to the field of simulation software technologies, and in particular, to a method and apparatus for analyzing a simulation model file, an electronic device, and a storage medium.
Background
With the continuous updating iteration of computer languages, the variety of program languages is increasing, and in the process of compiling the program languages, the program languages often need to be processed through a lexical analyzer and a grammar analyzer. Wherein, lexical analyzer (Lexical analysis) refers to a scanner capable of performing Lexical analysis on a program language, lexical analysis refers to converting character sequences in the program language into words for the grammar analyzer to call. The Parser (Parser) is an interpretation component that examines the grammar of words processed by the Parser.
At present, in the process of data analysis, related technicians generally write a large number of complex codes by directly adopting a C language or C++ to realize a lexical analyzer and a grammar analyzer, and the implementation mode is unfavorable for the related technicians to maintain or expand the lexical analyzer and the grammar analyzer due to the large and complex code quantity, so that the data analysis effect is poor.
Disclosure of Invention
The application provides a method, a device, electronic equipment and a storage medium for analyzing a simulation model file, which are used for solving or partially solving the problems of poor maintainability and expansibility of a data analyzer and poor data analysis effect.
The first aspect of the present application provides a method for parsing a simulation model file, including:
acquiring a simulation model file and a parser interface corresponding to the simulation model file;
invoking a lexical analyzer and a grammar analyzer associated with the parser interface, generating a file parser from the lexical analyzer and the grammar analyzer;
adopting the file analyzer to conduct data analysis processing on the simulation model file to obtain a target data structure corresponding to the data analysis processing;
And inputting the target data structure into a preset electromagnetic solver to obtain analytical data aiming at the simulation model file.
In an embodiment, the parser interface includes a lexical parser interface and a syntax parser interface, the invoking the lexical parser and the syntax parser associated with the parser interface generating a file parser from the lexical parser and the syntax parser, comprising:
invoking a lexical analyzer associated with the lexical analyzer interface and a grammar analyzer associated with the grammar analyzer interface;
and carrying out interface calling on the lexical analyzer and the grammar analyzer to obtain the file analyzer.
In an embodiment, the data parsing process includes content parsing process, where the content parsing process includes lexical parsing and grammatical parsing, and the performing data parsing process on the simulation model file by using the file parser to obtain a target data structure corresponding to the data parsing process includes:
inputting the simulation model file to the file parser;
adopting the file parser to parse the lexical analysis of the simulation model file to obtain a plurality of lexical units;
And carrying out grammar analysis on the plurality of lexical units to obtain a target data structure aiming at the simulation model file.
In an embodiment, the target data structure includes a first data structure, and the parsing the plurality of lexical units to obtain the target data structure for the simulation model file includes:
if the lexical unit comprises a preset ending field, performing the grammar parsing on the plurality of lexical units to obtain a first data structure for the simulation model file;
and taking the first data structure as a target data structure for the simulation model file.
In an embodiment, the simulation model file includes scanned data and model data to be scanned, the data analysis process further includes thread analysis process, the grammar analysis is performed on the plurality of lexical units to obtain a target data structure for the simulation model file, and the method includes:
if the lexical unit does not comprise a preset ending field, acquiring the scanned data and the data to be scanned;
performing the grammar parsing on the plurality of lexical units to obtain a second data structure for the scanned data;
Carrying out thread analysis processing on the data to be scanned to obtain a third data structure aiming at the data to be scanned;
and splicing the second data structure and the third data structure to generate the target data structure.
In an embodiment, the data to be scanned includes a number of subfiles, the thread analysis processing includes multi-thread analysis, and the performing the thread analysis processing on the data to be scanned to obtain a third data structure for the data to be scanned includes:
if the number of the subfiles is larger than the number of the preset files, performing multi-thread analysis on the data to be scanned, and extracting a plurality of model subfiles from the data to be scanned;
inputting the model subfiles into the file analyzer, and simultaneously carrying out the lexical analysis and the grammar analysis on the model subfiles to obtain a third data structure aiming at the data to be scanned.
In an embodiment, the thread analysis processing includes single thread analysis, and the performing the thread analysis processing on the data to be scanned to obtain a third data structure for the data to be scanned includes:
If the number of the subfiles is smaller than or equal to the number of the preset files, single-thread analysis is carried out on the data to be scanned, and the data to be scanned is input into the file analyzer;
and adopting the file parser to perform the lexical parsing and the grammar parsing on the data to be scanned to obtain a third data structure aiming at the data to be scanned.
The second aspect of the present application provides an analysis device for a simulation model file, including:
the data acquisition module is used for acquiring a simulation model file and a parser interface corresponding to the simulation model file;
the file parser generation module is used for calling a lexical parser and a grammar parser associated with the parser interface and generating a file parser according to the lexical parser and the grammar parser;
the data analysis module is used for carrying out data analysis processing on the simulation model file by adopting the file analyzer to obtain a target data structure corresponding to the data analysis processing;
and the analysis data acquisition module is used for inputting the target data structure into a preset electromagnetic solver to obtain analysis data aiming at the simulation model file.
A third aspect of the present application provides an electronic apparatus, comprising:
a processor; and
a memory having executable code stored thereon which, when executed by the processor, causes the processor to perform the method as described above.
A fourth aspect of the application provides a computer readable storage medium having stored thereon executable code which, when executed by a processor of an electronic device, causes the processor to perform a method as described above.
The technical scheme provided by the application can comprise the following beneficial effects:
in the embodiment of the application, a simulation model file and an analyzer interface corresponding to the simulation model file are acquired, then a lexical analyzer and a grammar analyzer which are related to the analyzer interface are called, a file analyzer is generated according to the lexical analyzer and the grammar analyzer, the file analyzer is adopted to conduct data analysis processing on the simulation model file, a target data structure corresponding to the data analysis processing is obtained, the target data structure is input into a preset electromagnetic solver, analysis data for the simulation model file is obtained, and therefore, on one hand, the acquisition flow of the related lexical analyzer and grammar analyzer is rapidly acquired through the analyzer interface, and the file analyzer is generated by utilizing the lexical analyzer and the grammar analyzer, so that the file analyzer is conveniently adopted to conduct data analysis processing on the simulation model file, an effective target data structure is obtained, the preset electromagnetic solver is ensured to effectively process the data of the simulation model file, and the data analysis efficiency is improved. On the other hand, when the file parser is adopted to parse data, abnormal problems occur or the parsing effect of the file parser is poor, related technicians can locate the corresponding lexical parser and grammar parser through the parser interface, and maintain or expand functions of the lexical parser and the grammar parser, so that maintainability and expansibility of the file parser are improved, and the data parsing effect is optimized.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application as claimed.
Drawings
The foregoing and other objects, features and advantages of the application will be apparent from the following more particular descriptions of exemplary embodiments of the application as illustrated in the accompanying drawings wherein like reference numbers generally represent like parts throughout the exemplary embodiments of the application.
FIG. 1 is a flow chart of a method for parsing a simulation model file according to an embodiment of the present application;
FIG. 2 is another flow chart of a method for parsing a simulation model file according to an embodiment of the present application;
FIG. 3 is a flow chart of an optimization method for file parsing according to an embodiment of the present application;
FIG. 4 is a schematic diagram of a device for analyzing a simulation model file according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
Embodiments of the present application will be described in more detail below with reference to the accompanying drawings. While embodiments of the present application are illustrated in the drawings, it should be understood that the present application may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the application to those skilled in the art.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any or all possible combinations of one or more of the associated listed items.
It should be understood that although the terms "first," "second," "third," etc. may be used herein to describe various information, these information should not be limited by these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the application. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include one or more such feature. In the description of the present application, the meaning of "a plurality" is two or more, unless explicitly defined otherwise.
In the data analysis process of the related technology, due to the fact that a related technician is required to write a large number of complex codes to realize the lexical analyzer and the grammar analyzer, the related technician is difficult to maintain and expand functions of the lexical analyzer and the grammar analyzer, and the data analysis effect is poor.
Aiming at the problems, the embodiment of the application provides a method for analyzing a simulation model file, which can pertinently maintain or expand functions of a lexical analyzer and a grammar analyzer and optimize the data analysis effect.
The following describes the technical scheme of the embodiment of the present application in detail with reference to the accompanying drawings.
Fig. 1 is a flow chart of a method for parsing a simulation model file according to an embodiment of the present application. Referring to fig. 1, the method comprises at least the steps of:
step 101, obtaining a simulation model file and a parser interface corresponding to the simulation model file;
in the embodiment of the application, the simulation model file and the resolver interface corresponding to the simulation model file can be obtained.
The simulation model file may be a file containing a programming language, and is mainly used as input data of a simulation model, and a file type of the simulation model file is associated with a model type of the simulation model. For example, the simulation model is a preset electromagnetic solver, and the simulation model file may be an electromagnetic model file corresponding to the electromagnetic solver, so as to be used as input data of the preset electromagnetic solver. The parser interfaces may be API interfaces (Application Programming Interface, application programming interfaces), different API interfaces corresponding to different data parsers, and related technicians may name the corresponding parser interfaces according to information such as functions, generation time, etc. of the data parsers to establish association between the parser interfaces and the data parsers.
Step 102, calling a lexical analyzer and a grammar analyzer associated with the parser interface, and generating a file parser according to the lexical analyzer and the grammar analyzer;
in the embodiment of the application, the lexical analyzer and the grammar analyzer which are associated with the parser interface can be called through the interface name of the parser interface, and the file parser is generated according to the lexical analyzer and the grammar analyzer.
In an alternative embodiment, both the lexical analyzer and the grammar analyzer belong to a data parser, the lexical analyzer (Semantic Analyzer), also known as a scanner, which is capable of reading external data, such as a source program, during compilation and then scanning the source program character by character, thereby converting the strings of the source program into lexical elements, while filtering out portions of invalid content in the source program. Since the lexical unit analyzed by the lexical analyzer belongs to the smallest unit in the source program and cannot be segmented, after the lexical analyzer analyzes the lexical unit, the lexical unit needs to be output to the grammar analyzer, and the grammar analyzer performs further analysis processing on the lexical unit.
A parser (parser) is generally used as a component of a compiler or an interpreter, and can use information such as a syntax tree, a symbol table and the like to perform syntax checking and type checking on a lexical unit output by the lexical analyzer to generate a corresponding data result, and the parser can judge or verify whether the syntax of a source program is correct, if not, error contents can be fed back to related technicians, and the related technicians can correct the error contents.
The file parser refers to a parser composed of a lexical parser and a grammar parser, and can perform lexical parsing and grammar parsing on the simulation model file to generate a corresponding data structure. By combining different lexical analyzers and grammatical analyzers, a file parser is generated such that the file parser can parse the simulation model file in a targeted manner.
Step 103, adopting a file analyzer to conduct data analysis processing on the simulation model file to obtain a target data structure corresponding to the data analysis processing;
in the embodiment of the application, after a file parser is generated according to a lexical parser and a grammar parser, the file parser is adopted to perform data parsing processing on the simulation model file, so as to obtain a target data structure corresponding to the data parsing processing.
In an alternative embodiment, the data analysis processing refers to a processing mode of performing lexical analysis and grammar analysis on the simulation model file, the data analysis processing can reject invalid data (such as blank characters, comments and the like) in the simulation model file, valid data is reserved, a target data structure corresponding to the simulation model file is constructed by using the valid data, the invalid data of the simulation model file is prevented from being analyzed, and the data analysis efficiency is improved.
The data structure refers to an organization or a representation of data, and selecting an appropriate data structure is beneficial to improving the efficiency and performance of the program. In general, the data structures of the C language or C++ may include structures, linked lists, queues, stacks, trees, graphs, and the like. The target data structure of the application can be a structure body based on a simulation model file, such as Struct (structure body) in C++, wherein Struct belongs to an aggregate data type, and can be declared as a variable, an array and a pointer so as to realize a data structure with higher complexity. In order to enable the file parser to be provided with data of a lexical parser and a grammatical parser corresponding to the parser interface, the format of the Struct data can be converted into a format suitable for a simulation model in a serialization manner.
And 104, inputting the target data structure into a preset electromagnetic solver to obtain analytical data for the simulation model file.
In the embodiment of the application, an effective target data structure is input to a preset electromagnetic solver to obtain analytical data for a simulation model file.
In an alternative embodiment, the pre-set electromagnetic solver (ElectroMagnetic, EM) may be a solver for simulating an electromagnetic process corresponding to a simulation model file, which is capable of combining a finite element method (Finite Element Method, FEM) and a boundary element method (Boundary Element Method, BEM), the pre-set electromagnetic solver being primarily used to solve engineering problems occurring in multiple physical fields. The analysis data refers to data obtained by solving the structural body by a preset electromagnetic solver, such as a solution of a matrix.
In the embodiment of the application, a simulation model file and an analyzer interface corresponding to the simulation model file are acquired, then a lexical analyzer and a grammar analyzer which are related to the analyzer interface are called, a file analyzer is generated according to the lexical analyzer and the grammar analyzer, the file analyzer is adopted to conduct data analysis processing on the simulation model file, a target data structure corresponding to the data analysis processing is obtained, the target data structure is input into a preset electromagnetic solver, analysis data for the simulation model file is obtained, and therefore, on one hand, the acquisition flow of the related lexical analyzer and grammar analyzer is rapidly acquired through the analyzer interface, and the file analyzer is generated by utilizing the lexical analyzer and the grammar analyzer, so that the file analyzer is conveniently adopted to conduct data analysis processing on the simulation model file, an effective target data structure is obtained, the preset electromagnetic solver is ensured to effectively process the data of the simulation model file, and the data analysis efficiency is improved. On the other hand, when the file parser is adopted to parse data, abnormal problems occur or the parsing effect of the file parser is poor, related technicians can locate the corresponding lexical parser and grammar parser through the parser interface, and maintain or expand functions of the lexical parser and the grammar parser, so that maintainability and expansibility of the file parser are improved, and the data parsing effect is optimized.
Fig. 2 is a flow chart of a method for parsing a simulation model file according to another embodiment of the present application. Fig. 2 illustrates in more detail the technical solution of an embodiment of the present application with respect to fig. 1, the method may comprise the following steps:
step 201, obtaining a simulation model file and a parser interface corresponding to the simulation model file;
in the embodiment of the application, the simulation model file and the parser interface corresponding to the simulation model file can be obtained, the parser interface can comprise a lexical parser interface and a grammar parser interface, the lexical parser interface is associated with a corresponding lexical parser, and the grammar parser interface is also associated with a corresponding grammar parser.
Step 202, invoking a lexical analyzer associated with the lexical analyzer interface and a grammar analyzer associated with the grammar analyzer interface;
in the embodiment of the application, a related technician selects different parser interfaces according to the actual requirements or the content of the simulation model file, so as to call the lexical parser associated with the lexical parser interface and the grammar parser associated with the grammar parser interface.
As an example, the construction process of the lexical analyzer may comprise the following sub-steps:
S21, writing a first grammar file for a lexical analyzer generator;
alternatively, the lexical analyzer generator is a tool that automatically generates a lexical analyzer based on regular expressions, such as a Flex lexical analyzer generation tool.
The first grammar file may be a set of rules corresponding to regular expressions, each rule in the first grammar file corresponding to an action. For example, the first grammar file contains rules: if { return TIF; }.
S22, the lexical analyzer generator may generate a lexical analyzer from the first syntax file.
Alternatively, the lexical analyzer generator may generate a series of codes matching the respective strings using the first grammar file, wherein the lexical analyzer is included.
As another example, the construction process of the parser may include the sub-steps of:
s23, writing a second grammar file for a grammar analyzer generator;
alternatively, the parser generator is a tool that automatically generates parsers based on a production formula, with different parsers corresponding to different parsers generating tools. Although the expressions processed by the different parser generators may differ in expression, the different parser generators may automatically construct the corresponding parsers using the grammar corresponding to themselves as a principle of constructing the data parser.
The second grammar file may be a set of a series of production formulas, most of which correspond to corresponding actions, and when a certain production formula is matched, the actions corresponding to the production formulas may be executed, and the number of codes for executing the actions may be set by a relevant technician as required. For example, the second grammar file includes a production formula: stmt- > if (expr) stmt else stmt. Wherein stmt and expr both belong to non-terminators and if key and brackets belong to terminators.
S24, the parser generator may generate a parser from the second syntax file.
Alternatively, the parser generator may generate a matching series of codes using the second grammar file, wherein the parser is included.
The automatic generation of the data parser is realized by adopting a mode that the lexical parser generator automatically generates the lexical parser corresponding to the regular expression and adopting the mode that the grammar parser generator automatically generates the grammar parser corresponding to the generating expression, so that the problem that a large number of codes need to be written to realize the data parser is avoided by adopting the generator, the workload of writing the data parser by related technicians is reduced, the related technicians can flexibly write the regular expression and the generating expression according to actual user demands, and the data parser meeting the user demands is generated.
And when related technicians want to expand functions of the lexical analyzer or the grammar analyzer, new rules can be directly added in a first grammar file of the lexical analyzer generator, and new generation formulas and actions are added in a second grammar file of the grammar analyzer generator, so that the expansion of the lexical analyzer or the grammar analyzer is improved. Similarly, when a related technician wants to maintain the lexical analyzer or the grammar analyzer, the related technician only needs to maintain the first grammar file or the second grammar file, so that the maintainability of the data analyzer is improved.
Step 203, performing interface call on the lexical analyzer and the grammar analyzer to obtain a file analyzer;
in the embodiment of the application, the lexical analyzer and the grammar analyzer can be subjected to interface call to obtain the file analyzer.
In an alternative embodiment, the interface call may be a process of interfacing the parser interfaces of the lexical parser and the syntax parser, so that the file parser has both the lexical parsing function of the lexical parser and the syntax parsing function of the syntax parser.
As an example, if the lexical analyzer provides an API interface (1): int yylex () and API interface (2): char yvalue (), a set of morphemes can be obtained through the API interface (1) and the API interface (2), and the parser provides the API interface (3): the interface call procedure for the lexical analyzer and the syntax analyzer may be to obtain the API interface (1), the API interface (2) and the API interface (3), and then pass through "int code=yylex (); while (code) { yyperse (code, yyvalue ()); the method comprises the steps of realizing calling an API interface (1), an API interface (2) and an API interface (3), and accordingly interfacing a parser interface of a lexical parser with a parser interface of a grammar parser to generate a file parser.
204, carrying out data analysis processing on the simulation model file by adopting a file analyzer to obtain a target data structure corresponding to the data analysis processing;
in the embodiment of the application, the data analysis processing at least comprises content analysis processing, and the content analysis processing can comprise lexical analysis and grammar analysis. The lexical parsing may divide the simulation model file into a number of lexical units.
As an example, a lexical element in a simulation model file may be the smallest element in a programming language that has an independent meaning, and in general, a lexical element is composed of a lexical element name that characterizes the category of a word and an attribute value that characterizes the specific content of the word, e.g., a lexical element may include separators, keywords, reserved words, identifiers, operators, literal values, and so forth. Grammar parsing can combine lexical units into various grammar phrases such as programs, sentences or expressions and the like based on lexical analysis, and the grammar parsing is mainly used for processing the structure and the format of data.
The data resolution process may also include a thread resolution process, which may include multi-threaded resolution and single-threaded resolution. Multithreading analysis aims at that a plurality of subfiles exist in a simulation model file, and multithreading refers to that a plurality of different threads are operated in one program at the same time to execute different tasks, such as obtaining the plurality of subfiles of the simulation model file, establishing a plurality of threads, and then simultaneously operating the plurality of different threads to analyze the plurality of subfiles. Single-thread parsing refers to the fact that multiple subfiles do not exist in the simulation model file, and single-thread refers to that only one thread exists in one program, for example, a single thread is operated to parse the simulation model file.
In an alternative embodiment, the simulation model file may be input to a file parser, and the file parser is used to perform lexical parsing on the simulation model file to obtain a plurality of lexical units, and then perform syntax parsing on the plurality of lexical units to obtain the target data structure for the simulation model file.
Referring to fig. 3, fig. 3 is a flow chart illustrating an optimization method of file parsing according to an embodiment of the present application. After the simulation model file and the parser interface of the simulation model file are obtained, the simulation model file can be stored in a preset database, then the lexical parser and the grammar parser are respectively obtained by adopting the parser interface, and the lexical parser and the grammar parser are combined through interface call so as to generate the file parser. When data analysis is started, the file analyzer is directly adopted to read the simulation model file from the preset database, and the simulation model file is subjected to data analysis processing, wherein the specific data analysis processing can comprise the following cases:
the first case is: if the lexical unit generated by lexical analysis comprises a preset end field after the file analyzer is adopted to conduct lexical analysis on the simulation model file, the file analyzer is explained to scan the tail end of the simulation model file, the lexical unit of the simulation model file can be directly analyzed in grammar, data after grammar analysis are stored in a structural body, and a first data structure aiming at the simulation model file is generated.
The first data structure at this time may completely represent the simulation model file, and thus, the first data structure is taken as the target data structure.
The second case is: if the lexical unit generated by lexical analysis does not comprise a preset end field after the file analyzer is adopted to conduct lexical analysis on the simulation model file, the file analyzer is not shown to scan the tail end of the simulation model file, and the current lexical unit belongs to the part data of the current scan. The file parser may divide the partial data currently scanned into scanned data and other data not scanned into data to be scanned. And then firstly carrying out grammar analysis on lexical units of the scanned data, and storing the data after grammar analysis into a structural body to generate a second data structure aiming at the scanned data. And then carrying out thread analysis processing on the data to be scanned according to the number of subfiles of the data to be scanned so as to obtain a third data structure aiming at the data to be scanned.
And finally splicing the second data structure and the third data structure into a complete data structure, wherein the data structure can also completely represent the simulation model file, so that the complete data structure is taken as a target data structure.
In the second case, the quantitative relationship between the number of subfiles and the number of preset files of the data to be scanned determines whether to perform multi-threaded parsing of the data to be scanned. The number of preset files may be an integer value of subfiles set in advance, e.g., the number of preset files may be 1.
If the number of the subfiles of the data to be scanned is larger than the number of the preset files, the data to be scanned is indicated to comprise a plurality of subfiles, multithreading analysis can be carried out on the data to be scanned, a plurality of model subfiles are extracted from the data to be scanned, the model subfiles are input into a file analyzer, the model subfiles are subjected to lexical analysis and grammar analysis, the data after grammar analysis are stored into a structure body, and a third data structure aiming at the data to be scanned is generated, so that the data analysis efficiency is improved by starting the multithreading analysis function.
If the number of the subfiles of the data to be scanned is smaller than or equal to the preset number of the files, the data to be scanned does not comprise a plurality of subfiles, single-thread analysis can be performed on the data to be scanned, the data to be scanned is input into a file analyzer, lexical analysis and grammar analysis are performed on the data to be scanned by adopting the file analyzer, and then the data after grammar analysis are stored into a structural body to generate a third data structure aiming at the data to be scanned.
It should be noted that the subfiles of the data to be scanned may be introduced by the import syntax, such as the include of c++. The file parser is provided with a switch control for multi-thread parsing, the default switch control is in an off state, and is triggered to be in an on state when the import grammar is identified.
Step 205, inputting the target data structure to a preset electromagnetic solver to obtain analytical data for the simulation model file.
In the embodiment of the application, the target data structure analyzed by the file analyzer is used as input data and is input into a preset electromagnetic solver, so that analysis data aiming at the simulation model file is obtained.
Alternatively, the solving process of the preset electromagnetic solver may be: the target data structure may be a coefficient matrix, a left end matrix and a right end vector corresponding to the coefficient matrix are generated, then the coefficient matrix is solved, and a solution of the solved coefficient matrix is used as analysis data and stored in a Resource file (Res) file.
In the embodiment of the application, the lexical analyzer and the grammar analyzer are automatically generated by adopting the lexical analyzer generator and the grammar analyzer generator, so that the generation flow of the lexical analyzer and the grammar analyzer can be simplified, the data analysis efficiency is improved, meanwhile, the maintenance function can be realized by carrying out grammar correction on the first grammar file of the lexical analyzer generator and the second grammar file of the grammar analyzer generator, and the expansion function can be realized by adding related contents in the first grammar file of the lexical analyzer generator and the grammar analyzer generator.
In addition, in the process of analyzing the simulation model file by adopting the file analyzer, whether the multi-thread analysis is started or not can be judged according to the lexical analysis result so as to ensure that the multi-thread analysis is performed under the condition that the simulation model file has a plurality of subfiles, further improve the efficiency of the file analyzer and optimize the data analysis effect.
Corresponding to the embodiment of the application function implementation method, the application also provides a device for analyzing the simulation model file, electronic equipment and corresponding embodiments.
Fig. 4 is a schematic structural diagram of an analysis device for a simulation model file according to an embodiment of the present application. Referring to fig. 4, the apparatus comprises at least the following modules:
the data acquisition module 401 is configured to acquire a simulation model file and a parser interface corresponding to the simulation model file;
a file parser generation module 402 for invoking a lexical parser and a syntax parser associated with the parser interface, generating a file parser from the lexical parser and the syntax parser;
the data analysis module 403 is configured to perform data analysis processing on the simulation model file by using a file analyzer, so as to obtain a target data structure corresponding to the data analysis processing;
The analysis data acquisition module 404 is configured to input the target data structure to a preset electromagnetic solver, and obtain analysis data for the simulation model file.
In an alternative embodiment, the parser interface includes a lexical parser interface and a grammatical parser interface, and the file parser generation module 402 is specifically configured to:
invoking a lexical analyzer associated with the lexical analyzer interface and a grammar analyzer associated with the grammar analyzer interface;
and calling interfaces of the lexical analyzer and the grammar analyzer to obtain a file analyzer.
In an alternative embodiment, the data parsing process includes a content parsing process including lexical parsing and grammar parsing, and the data parsing module 403 includes:
the file input sub-module is used for inputting the simulation model file to the file analyzer;
the lexical unit obtaining submodule is used for carrying out lexical analysis on the simulation model file by adopting the file analyzer to obtain a plurality of lexical units;
and the target data structure acquisition sub-module is used for carrying out grammar analysis on the plurality of lexical units to obtain a target data structure aiming at the simulation model file.
In an alternative embodiment, the target data structure comprises a first data structure and the target data structure acquisition sub-module may comprise a first data structure acquisition unit.
The first data structure acquisition unit is used for carrying out grammar analysis on the plurality of lexical units if the lexical units comprise a preset end field to obtain a first data structure aiming at the simulation model file;
the first data structure is used as a target data structure for the simulation model file.
In an alternative embodiment, the simulation model file includes scanned data and model data to be scanned, the data parsing process further includes a thread parsing process, and the target data structure obtaining sub-module may further include a second data structure obtaining unit, a third data structure obtaining unit, and a target data structure generating unit.
The second data structure acquisition unit is used for acquiring scanned data and data to be scanned if the lexical unit does not comprise a preset end field;
carrying out grammar analysis on a plurality of lexical units to obtain a second data structure aiming at scanned data;
the third data structure acquisition unit is used for carrying out thread analysis processing on the data to be scanned to obtain a third data structure aiming at the data to be scanned;
and the target data structure generating unit is used for splicing the second data structure and the third data structure to generate a target data structure.
In an alternative embodiment, the data to be scanned includes the number of subfiles, the thread parsing includes multi-thread parsing, and the third data structure obtaining unit is specifically configured to:
if the number of the subfiles is larger than the number of the preset files, performing multi-thread analysis on the data to be scanned, and extracting a plurality of model subfiles from the data to be scanned;
inputting the model subfiles into a file analyzer, and performing lexical analysis and grammar analysis on the model subfiles to obtain a third data structure aiming at the data to be scanned.
In an alternative embodiment, the thread parsing process includes single thread parsing, the data to be scanned is processed by thread parsing, and the third data structure obtaining unit is further configured to:
if the number of the subfiles is smaller than or equal to the number of the preset files, single-thread analysis is carried out on the data to be scanned, and the data to be scanned is input into a file analyzer;
and performing lexical analysis and grammar analysis on the data to be scanned by adopting a file analyzer to obtain a third data structure aiming at the data to be scanned.
The specific manner in which the respective modules perform the operations in the apparatus of the above embodiments has been described in detail in the embodiments related to the method, and will not be described in detail herein.
Fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Referring to fig. 5, an electronic device 500 includes a memory 510 and a processor 520.
The processor 520 may be a central processing unit (Central Processing Unit, CPU), but may also be other general purpose processors, digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (Application Specific Integrated Circuit, ASIC), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Memory 510 may include various types of storage units, such as system memory, read Only Memory (ROM), and persistent storage. Where the ROM may store static data or instructions that are required by the processor 520 or other modules of the computer. The persistent storage may be a readable and writable storage. The persistent storage may be a non-volatile memory device that does not lose stored instructions and data even after the computer is powered down. In some embodiments, the persistent storage device employs a mass storage device (e.g., magnetic or optical disk, flash memory) as the persistent storage device. In other embodiments, the persistent storage may be a removable storage device (e.g., diskette, optical drive). The system memory may be a read-write memory device or a volatile read-write memory device, such as dynamic random access memory. The system memory may store instructions and data that are required by some or all of the processors at runtime. Furthermore, memory 510 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (e.g., DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), magnetic disks, and/or optical disks may also be employed. In some embodiments, memory 510 may include a readable and/or writable removable storage device, such as a Compact Disc (CD), a digital versatile disc read only (e.g., DVD-ROM, dual layer DVD-ROM), a blu-ray read only disc, an ultra-dense disc, a flash memory card (e.g., SD card, min SD card, micro-SD card, etc.), a magnetic floppy disk, and the like. The computer readable storage medium does not contain a carrier wave or an instantaneous electronic signal transmitted by wireless or wired transmission.
The memory 510 has stored thereon executable code that, when processed by the processor 520, causes the processor 520 to perform some or all of the methods described above.
Furthermore, the method according to the application may also be implemented as a computer program or computer program product comprising computer program code instructions for performing part or all of the steps of the above-described method of the application.
Alternatively, the application may also be embodied as a computer-readable storage medium (or non-transitory machine-readable storage medium or machine-readable storage medium) having stored thereon executable code (or a computer program or computer instruction code) which, when executed by a processor of an electronic device (or a server, etc.), causes the processor to perform part or all of the steps of the above-described method according to the application.
The foregoing description of embodiments of the application has been presented for purposes of illustration and description, and is not intended to be exhaustive or limited to the embodiments disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the various embodiments described. The terminology used herein was chosen in order to best explain the principles of the embodiments, the practical application, or the improvement of technology in the marketplace, or to enable others of ordinary skill in the art to understand the embodiments disclosed herein.

Claims (10)

1. The method for analyzing the simulation model file is characterized by comprising the following steps of:
acquiring a simulation model file and a parser interface corresponding to the simulation model file;
invoking a lexical analyzer and a grammar analyzer associated with the parser interface, generating a file parser from the lexical analyzer and the grammar analyzer;
adopting the file analyzer to conduct data analysis processing on the simulation model file to obtain a target data structure corresponding to the data analysis processing;
and inputting the target data structure into a preset electromagnetic solver to obtain analytical data aiming at the simulation model file.
2. The method of claim 1, wherein the parser interface comprises a lexical parser interface and a grammatical parser interface, wherein the invoking the lexical parser and the grammatical parser associated with the parser interface generates a file parser from the lexical parser and the grammatical parser, comprising:
invoking a lexical analyzer associated with the lexical analyzer interface and a grammar analyzer associated with the grammar analyzer interface;
and carrying out interface calling on the lexical analyzer and the grammar analyzer to obtain the file analyzer.
3. The method according to claim 1, wherein the data parsing process includes a content parsing process including lexical parsing and syntax parsing, the employing the file parser to perform data parsing process on the simulation model file to obtain a target data structure corresponding to the data parsing process, comprising:
inputting the simulation model file to the file parser;
adopting the file parser to parse the lexical analysis of the simulation model file to obtain a plurality of lexical units;
and carrying out grammar analysis on the plurality of lexical units to obtain a target data structure aiming at the simulation model file.
4. The method of claim 3, wherein the target data structure comprises a first data structure, wherein the parsing the plurality of lexical units to obtain the target data structure for the simulation model file comprises:
if the lexical unit comprises a preset ending field, performing the grammar parsing on the plurality of lexical units to obtain a first data structure for the simulation model file;
And taking the first data structure as a target data structure for the simulation model file.
5. The method of claim 3, wherein the simulation model file includes scanned data and model data to be scanned, the data parsing process further includes a thread parsing process, the parsing the plurality of lexical units to obtain a target data structure for the simulation model file, comprising:
if the lexical unit does not comprise a preset ending field, acquiring the scanned data and the data to be scanned;
performing the grammar parsing on the plurality of lexical units to obtain a second data structure for the scanned data;
carrying out thread analysis processing on the data to be scanned to obtain a third data structure aiming at the data to be scanned;
and splicing the second data structure and the third data structure to generate the target data structure.
6. The method of claim 5, wherein the data to be scanned comprises a number of subfiles, the thread parsing process comprises a multi-threaded parsing, the thread parsing process is performed on the data to be scanned to obtain a third data structure for the data to be scanned, comprising:
If the number of the subfiles is larger than the number of the preset files, performing multi-thread analysis on the data to be scanned, and extracting a plurality of model subfiles from the data to be scanned;
inputting the model subfiles into the file analyzer, and simultaneously carrying out the lexical analysis and the grammar analysis on the model subfiles to obtain a third data structure aiming at the data to be scanned.
7. The method of claim 6, wherein the thread resolution process comprises a single thread resolution, wherein the performing the thread resolution process on the data to be scanned to obtain a third data structure for the data to be scanned comprises:
if the number of the subfiles is smaller than or equal to the number of the preset files, single-thread analysis is carried out on the data to be scanned, and the data to be scanned is input into the file analyzer;
and adopting the file parser to perform the lexical parsing and the grammar parsing on the data to be scanned to obtain a third data structure aiming at the data to be scanned.
8. An apparatus for analyzing a simulation model file, comprising:
the data acquisition module is used for acquiring a simulation model file and a parser interface corresponding to the simulation model file;
The file parser generation module is used for calling a lexical parser and a grammar parser associated with the parser interface and generating a file parser according to the lexical parser and the grammar parser;
the data analysis module is used for carrying out data analysis processing on the simulation model file by adopting the file analyzer to obtain a target data structure corresponding to the data analysis processing;
and the analysis data acquisition module is used for inputting the target data structure into a preset electromagnetic solver to obtain analysis data aiming at the simulation model file.
9. An electronic device, comprising:
a processor; and
a memory having executable code stored thereon, which when executed by the processor, causes the processor to perform the method of any of claims 1-7.
10. A computer readable storage medium having stored thereon executable code which when executed by a processor of an electronic device causes the processor to perform the method of any of claims 1-7.
CN202310980594.6A 2023-08-04 2023-08-04 Analysis method and device of simulation model file, electronic equipment and storage medium Pending CN117008919A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310980594.6A CN117008919A (en) 2023-08-04 2023-08-04 Analysis method and device of simulation model file, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310980594.6A CN117008919A (en) 2023-08-04 2023-08-04 Analysis method and device of simulation model file, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117008919A true CN117008919A (en) 2023-11-07

Family

ID=88565118

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310980594.6A Pending CN117008919A (en) 2023-08-04 2023-08-04 Analysis method and device of simulation model file, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117008919A (en)

Similar Documents

Publication Publication Date Title
US7962904B2 (en) Dynamic parser
US9122540B2 (en) Transformation of computer programs and eliminating errors
US20170279691A1 (en) System and Method for Validating Documentation of Representational State Transfer (Rest) Services
US7917899B2 (en) Program development apparatus, method for developing a program, and a computer program product for executing an application for a program development apparatus
US20070226720A1 (en) System and Method for Efficiently Passing Information Between Compiler and Post-Compile-Time Software
CN111459500A (en) Safety compiling method and device based on sea eagle wing brightness operating system
Kuramitsu Nez: practical open grammar language
CN111813670A (en) Non-invasive MC/DC coverage statistical analysis method
US7882429B2 (en) High-level virtual machine for fast XML parsing and validation
CN117009231B (en) Automatic generation method and device for high-reliability unit test based on conversational large language model
KR102614967B1 (en) Automation system and method for extracting intermediate representation based semantics of javascript
CN115951890A (en) Method, system and device for code conversion between different front-end frames
CN117008919A (en) Analysis method and device of simulation model file, electronic equipment and storage medium
CN111381826A (en) Method and device for generating syntax tree of code file and electronic equipment
US7318221B2 (en) Windows™ F-language interpreter
CN107577476A (en) A kind of Android system source code difference analysis method, server and medium based on Module Division
Lester et al. Information flow analysis for a dynamically typed language with staged metaprogramming
CN116560667B (en) Splitting scheduling system and method based on precompiled delay execution
CN112286784A (en) Test case generation method and device, server and storage medium
Gonçalves A Reference Implementation of ECMAScript Built-in Objects
CN114238469B (en) Data extraction interface opening method and device, computer equipment and storage medium
JPH07121379A (en) Plural languages mixing compiler
JP2001034482A (en) Compile device, program optimizing device, compile processing method and recording medium
Jiang Scalable Data-Parallel Processing of Semi-Structured Data
Pottier Reachability and error diagnosis in LR (1) automata

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination