A kind of anatomy of C language realistic model and method for supervising
Technical field
The present invention relates to computer simulation technique field, particularly relate to a kind of anatomy and method for supervising of C language realistic model.
Background technology
The core of computer simulation technique comprises realistic model and emulation platform.Realistic model is the abstractdesription to simulated entity object characteristic, has the mathematics similar to entity and physical attribute, the characteristic sum rule of reflection entity.The description of realistic model can by various computerese as formula translation, C language, M language etc., carry out coding according to the coding rule of correspondence to realize, also realize as MATLAB/Simulink carries out the building of basic mathematical computing module such as addition subtraction multiplication and division in the mode played with building blocks by modeling tool.The realistic model no matter described in which way, finally all needs to be compiled into executable application program, downloads on emulation platform and carry out simulation and calculation.
Emulation platform is the carrier that realistic model resolves, and is made up of software and hardware, and accordingly, real-time simulation platform is made up of real-time oss simulation computer of unifying.In order to realize real-time simulation, i.e. realistic model real-time resolving, carries out data interaction with peripherals in real time, then need realistic model compiling to download to implement emulation platform runs.Therefore, complete real-time simulation platform generally includes emulation host computer and emulation slave computer.Emulation host computer runs a simulation management software, be responsible for carrying out model compiling the model described by computerese or by the model that modeling tool is built, generate executable application program, and download to emulation slave computer by network communications such as Ethernets.Emulation slave computer is responsible for real-time resolving and has been compiled the realistic model generating executable application programs.When model is when emulating slave computer and carrying out simulation and calculation, emulation host computer needs to extract the variable data in realistic model, and online instant playback, so that whether the personnel of emulation have a clear understanding of realistic model calculation result correct, simultaneously, emulation personnel can carry out manual intervention, the parameter in online modification realistic model, and realistic model is resolved according to the result of emulation personnel budget.In order to realize extraction to realistic model built-in variable parameter and amendment, carry out before real-time simulation resolves at realistic model, need to dissect realistic model, namely to the information in realistic model, comprise function name and parametric variable name and variable number, module parameter, global variable etc. extract, be kept in message file.
At present, for the model using modeling tool MATLAB/Simulink to build, the TLC template file that can be provided by amendment MATLAB/Simulink realizes the anatomy to realistic model, and for the anatomy of the realistic model using C language coding rule to write, domestic also do not have suitable method, it can only be built into MATLAB/Simulink model again at present, more just can realize parsing process by TLC template file, this method will cause unnecessary, a large amount of repeated work.In addition, in practical engineering application, most of realistic model adopts C language to write, if can not dissect C language, by the range of application of restriction C language realistic model.
Summary of the invention
In view of this, the invention provides a kind of anatomy and method for supervising of C language realistic model, the problem of unnecessary, a large amount of repeated work can be caused for solving existing anatomy and method for supervising.
A kind of method for decomposing of C language realistic model, in advance by grammatical file generated C code method for decomposing class, described grammatical file under speech recognition too development environment by developer's hand-coding, wherein, generate after described C code method for decomposing class compiles grammatical file by speech recognition instrument, it comprises syntax Analysis Module, Lexical Analysis Module and syntax tree generation module;
The method comprises:
The lexical content of Lexical Analysis Module to the C language realistic model imported called in C code method for decomposing class dissects, and forms mark stream;
Call the syntax Analysis Module in C code method for decomposing class, according to described mark stream, the syntactic structure of the C language realistic model imported is dissected;
The syntax tree generation module called in C code method for decomposing class generates corresponding syntax tree according to the syntactic structure that described analysis obtains;
From described syntax tree, extract variable information sum functions information, and the variable information sum functions information of described extraction is saved in model information file.
Preferably, described speech recognition instrument is the speech recognition instrument ANTLR that increases income.
The compiling procedure of described grammatical file comprises:
Determine the integral frame of grammatical file, by the division of teaching contents of described grammatical file be: head module, option mod, syntax analyzer generic module and lexical analyzer generic module, described head module and described option mod, for defining the essential information of grammatical file, described syntax analyzer generic module, for defining the grammatical analysis content that grammatical file comprises, described lexical analyzer generic module, for the lexical analysis content comprised due to grammatical file;
Define the grammatical analysis content that grammatical file comprises;
Define the lexical analysis content that grammatical file comprises;
Add distinctive Jave class methods, described distinctive Jave class methods do not become for described ANTLR is raw but carries out the distinctive java class method required for the anatomy of C code.
Described grammatical analysis content comprises: data type mark, structure or community identification, data structure variable list mark, enumeration type mark, variable array mark, pointer mark, parameter list mark, identifier list mark.
Described lexical analysis content comprises: character type marking variable, special character mark, 16 system marks, 10 system marks, 8 system marks, floating number mark, block annotation form mark, row annotation mark.
Described C code method for decomposing class is C code method for decomposing java class, C code method for decomposing C++ class or C code method for decomposing C# class.
A method for supervising for C language realistic model, comprising:
Host computer simulation management software transfer C language compiler compiles the C language realistic model imported, and compiling generates executable application program;
Host computer simulation management software adopts the method for decomposing of above-mentioned C language realistic model to dissect the C language realistic model imported;
Described executable application programs is downloaded to emulation slave computer by host computer simulation management software, carries out the real-time resolving of model;
Variable information in model information file is extracted the model variable that will carry out monitoring to emulation personnel and from the variable information described model information file by host computer simulation management software by showing interface, and the described model parameter that will monitor is sent to emulation slave computer, emulation slave computer is according to variable name, the data of corresponding described variable name are extracted from internal memory, return to host computer simulation management software to show, if will modify to variable, the variable name then directly will revised and the data of correspondence thereof send to emulation slave computer, data corresponding for the described variable name that will revise are write in internal memory corresponding to the described variable name that will revise by emulation slave computer.
The invention provides a kind of anatomy and method for supervising of C language realistic model, the method is write grammatical file in advance and is generated C code method for decomposing class, and by using C code method for decomposing class to dissect C language realistic model and monitor, implementation procedure is simple.Method provided by the invention has filled up the blank of current domestic C language realistic model anatomy and monitoring technique, and the grammatical file content write is complete, goes for anatomy and the monitoring requirement of most of C language realistic model.
Accompanying drawing explanation
In order to be illustrated more clearly in the embodiment of the present invention or technical scheme of the prior art, be briefly described to the accompanying drawing used required in embodiment or description of the prior art below, apparently, accompanying drawing in the following describes is only embodiments of the invention, for those of ordinary skill in the art, under the prerequisite not paying creative work, other accompanying drawing can also be obtained according to the accompanying drawing provided.
The process flow diagram of the method for decomposing of the C language realistic model that Fig. 1 provides for the embodiment of the present invention one;
The compiling procedure figure of the grammatical file that Fig. 2 provides for the embodiment of the present invention one;
The process flow diagram of the method for supervising of the C language realistic model that Fig. 3 provides for the embodiment of the present invention two.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, be clearly and completely described the technical scheme in the embodiment of the present invention, obviously, described embodiment is only the present invention's part embodiment, instead of whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art, not making the every other embodiment obtained under creative work prerequisite, belong to the scope of protection of the invention.
Embodiment one
The embodiment of the present invention one provides a kind of method for decomposing of C language realistic model, before carrying out the method, in advance by grammatical file generated C code method for decomposing class, C code method for decomposing class comprises syntax Analysis Module, Lexical Analysis Module and syntax tree generation module, the process flow diagram of the method for decomposing that Fig. 1 provides for the embodiment of the present invention, the method comprises:
S11: the lexical content of Lexical Analysis Module to the C language realistic model imported called in C code method for decomposing class dissects, and forms mark stream;
S12: call the syntax Analysis Module in C code method for decomposing class, according to mark stream, dissects the syntactic structure of the C language realistic model imported;
S13: the syntax tree generation module called in C code method for decomposing class generates corresponding syntax tree according to analyzing the syntactic structure obtained;
S14: extract variable information sum functions information from syntax tree, and the variable information sum functions information of extraction is saved in model information file.
Wherein, grammatical file by developer's hand-coding, generates after C code method for decomposing class compiles grammatical file by speech recognition instrument under speech recognition too development environment.In the present embodiment, speech recognition instrument is the speech recognition instrument ANTLR that increases income.
In the present embodiment, the compiling procedure of grammatical file as described in Figure 2, comprising:
S21: the integral frame determining grammatical file, by the division of teaching contents of grammatical file be: head module header, option mod options, syntax analyzer generic module parser and lexical analyzer generic module lexer, wherein, head module header and option mod options, for defining the essential information of grammatical file, syntax analyzer generic module parser, for defining the grammatical analysis content that grammatical file comprises, lexical analyzer generic module lexer, for the lexical analysis content comprised due to grammatical file;
S22: define the grammatical analysis content that grammatical file comprises, comprises data type mark (as void type, char type, float type etc.), structure or community identification, data structure variable list mark, enumeration type mark, variable data mark, pointer mark, parameter list mark, identifier list mark.Wherein, in data type mark, the type also comprising that simulink is distinctive, do not have in standard C, as int8_T, cuint16_T etc., after identifying, the type_specifier position of grammatical file is programmed according to ANTLR grammar rule, such as, literary style during definition data type is: key word (type_specifier), line feed put in a colon (:), after add data type identification (mark adds single quotation marks), if want the multiple data type of link definition, then line feed add " | " connect afterwards again data type mark, as follows:
type_specifier
:′void′
|′char′
|′short′
|′int′
|′long′
|′float′
|′double′
……
S23: define the lexical analysis content that grammatical file should comprise, comprise: character type marking variable, n the special character such as t mark, 16 systems marks, 10 systems marks, 8 systems marks, floating number mark, block annotation form mark, row annotation mark, identify out, the relevant position of grammatical file is programmed in by ANTLR grammar rule, such as, 16 system marks are defined as follows:
HEX_LITERAL:′0′(′x′|′X′)HexDigit+IntegerTypeSuffix?
S24: add distinctive Jave class methods, namely add ANTLR life not become, but the distinctive Java method of carrying out required for the anatomy of C code, as the method for decomposing of constructed fuction part, addition manner adds self-defining special member function code by key word@member, by key word@lexer::header, add self-defining java class, as:
@lexer::header{
package com.hirain.hisim.redundancy.parse.antlr;
}
In the present embodiment, the grammatical file after having write is compiled, generate C code method for decomposing java class, certainly also can generate C code method for decomposing C++ class, C# class.Wherein, C code method for decomposing java class comprises Lexer class (morphology class) and Parser class (syntactic class) two class files.Under this C code method for decomposing java class being copied to emulation host computer respective path, for the software transfer of host computer simulation management, host computer simulation management software is according to lexical analysis, the corresponding module that the sequence call C code method for decomposing class that grammatical analysis and generative grammar are set provides, then from content comprehensive syntax tree tree structure, required content is extracted, and the content of extraction is saved in model information file .hisim, wherein, function name is comprised in tree structure, parametric variable name, variable number, all information such as global variable, cover all information of grammatical file defined.
When emulating an importing C language realistic model on host computer, host computer simulation management software meeting Automatically invoked C code method for decomposing java class, the C language realistic model imported is dissected, generation model message file, thus realize the anatomy object to C language realistic model.
The method for decomposing of the C language realistic model provided by the embodiment of the present invention, when dissecting C language realistic model, it again will not be built into MATLAB/Simulink model and dissect, therefore, implementation procedure is simple.
Embodiment two
The embodiment of the present invention two provides a kind of method for supervising of C language realistic model, the process flow diagram of the method for supervising that Fig. 3 provides for the embodiment of the present invention, and the method comprises:
S31: host computer simulation management software transfer C language compiler compiles the C language realistic model imported, compiling generates executable application program;
S32: host computer simulation management software adopts the method for decomposing of the C language realistic model in embodiment one to dissect the C language realistic model imported;
S33: executable application program is downloaded to emulation slave computer by host computer simulation management software, carries out the real-time resolving of model;
S34: the variable information in the model information file that the method for decomposing by embodiment one obtains by host computer simulation management software by showing interface to emulation personnel, and from the variable information model information file, extract the model variable that will carry out monitoring, the model parameter that will monitor sends to emulation slave computer, emulation slave computer is according to variable name, the data of corresponding variable name are extracted from internal memory, return to host computer simulation management software to show, if will modify to variable, the variable name then directly will revised and the data of correspondence thereof send to emulation slave computer, the data that the variable name that will revise of emulation slave computer is corresponding are write in internal memory corresponding to the variable name that will revise.
The method for supervising of the C language realistic model that the embodiment of the present invention provides has filled up the blank of domestic C code anatomy and monitoring technique, make C language realistic model in real-time emulation system, realize on-line monitoring and become possibility, simultaneously, use the anatomy of speech recognition instrument ANTLE realization to C language realistic model of increasing income, implementation procedure is simple, reliable.In addition, the grammatical file content that the embodiment of the present invention is write is complete, goes for most of C language realistic model and dissects the requirement used.
To the above-mentioned explanation of the disclosed embodiments, professional and technical personnel in the field are realized or uses the present invention.To be apparent for those skilled in the art to the multiple amendment of these embodiments, General Principle as defined herein can without departing from the spirit or scope of the present invention, realize in other embodiments.Therefore, the present invention can not be restricted to these embodiments shown in this article, but will meet the widest scope consistent with principle disclosed herein and features of novelty.