manpagez: man pages & more
info mathgl
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.1 mglParse class

Class for parsing and executing MGL script. This class is defined in #include <mgl/mgl_parse.h>.

Class mglParse is the interpreter for MGL scripts (see section MGL language). The main function of mglParse class is Parse(). Exactly this function parses and executes the script string-by-string. Also there are two subservient functions for the finding and creation of a variable. These functions can be useful for displaying values of variables (arrays) in some external program (in window, for example). The variable DataList contains full list of variables in script. Flag AllowSetSize allows one to prevent changing the size of the picture inside the script (forbids the MGL command setsize).

Note an important feature – if user defines function func in variable then it will be called before the destroying of this variable (see section mglVar class).

Method on mglParse (C++, Python): mglParse (bool setsize=false)
C function: HMPR mgl_create_parser ()

Constructor initializes all values with zero and set AllowSetSize value.

Method on mglParse (C++, Python): ~mglParse ()
C function: void mgl_delete_parser (HMPR p)

Destructor delete parser

Method on mglParse (C++, Python): int Parse (mglGraph *gr, const char *str, long pos=0)
Method on mglParse (C++): int Parse (mglGraph *gr, const wchar_t *str, long pos=0)
C function: int mgl_parse (HMGL gr, HMPR p, const char *str, int pos)
C function: int mgl_parsew (HMGL gr, HMPR p, const wchar_t *str, int pos)

Main function in the class. It parses the string str and executes it by using gr as a graphics plotter. Returns the value depending on an error presence in the string str: 0 – no error, 1 – wrong command argument(s), 2 – unknown command, 3 – string is too long. Optional argument pos allows to save the string position in the document (or file) for using for|next command.

Method on mglParse (C++): int Export (wchar_t cpp_out[1024], mglGraph *gr, const wchar_t *str)

Function parses the string str, executes it by using gr as a graphics plotter and exports it to C++ code. Returns the value depending on an error presence in the string str: 0 – no error, 1 – wrong command argument(s), 2 – unknown command, 3 – string is too long. Output C++ text will be placed in out variable. If string str have options (defined after ’;’ symbol) then the corresponding C++ texts are placed in variables op1, op2.

Method on mglParse (C++): void Execute (mglGraph *gr, FILE *fp, bool print=false)

Function parse and execute line-by-line MGL script in file fp. If print=true then all warnings and information will be printed in stdout. Also this function support the for|next MGL commands.

Method on mglParse (C++): void Execute (mglGraph *gr, int num, const wchar_t **text, void (* error )(int line, int kind)=NULL)

Function parse and execute line-by-line MGL script in array text. If error is not NULL then this function will be called for all warnings, information and other messages. Also this function support the for|next MGL commands.

Method on mglParse (C++, Python): void Execute (mglGraph *gr, const char *text, void (* error )(int line, int kind)=NULL)
Method on mglParse (C++): void Execute (mglGraph *gr, const wchar_t *text, void (* error )(int line, int kind)=NULL)
C function: void mgl_parse_text (HMGL gr, HMPR p, const char *text)
C function: void mgl_parsew_text (HMGL gr, HMPR p, const wchar_t *text)

Function parse and execute line-by-line MGL script in string text. Lines are separated by ‘\n’ symbol as usual. If error is not NULL then this function will be called for all warnings, information and other messages. Also this function support the for|next MGL commands.

Method on mglParse (C++, Python): bool AddParam (int n, const char *str, bool isstr=true)
Method on mglParse (C++): bool AddParam (int n, const wchar_t *str, bool isstr=true)
C function: void mgl_add_param (HMPR p, int id, const char *val)
C function: void mgl_add_paramw (HMPR p, int id, const wchar_t *val)

Function set the value of n-th parameter as string str (n=0, 1 ... 9). It return true for success.

Method on mglParse (C++, Python): mglVar * FindVar (const char *name)
Method on mglParse (C++): mglVar * FindVar (const wchar_t *name)
C function: const HMDT mgl_find_var (HMPR p, const char *name)

Function returns the pointer to variable with name name or zero if variable is absent. Use this function to put external data array to the script or get the data from the script.

Method on mglParse (C++, Python): mglVar * AddVar (const char *name)
Method on mglParse (C++): mglVar * AddVar (const wchar_t *name)
C function: const HMDT mgl_add_var (HMPR p, const char *name)

Function returns the pointer to variable with name name. If variable is absent then new variable is created with name name. Use this function to put external data array to the script or get the data from the script.

Method on mglParse (C++): void DeleteVar (mglVar *v)
Method on mglParse (C++): void DeleteVar (const char *name)
Method on mglParse (C++): void DeleteVar (const wchar_t *name)

Function delete the variable specified by its name or by its pointer.

Method on mglParse (C++, Python): inline void RestoreOnce ()
C function: void mgl_restore_once (HMPR p)

Restore Once flag.

Method on mglParse (Python): void AllowSetSize (bool a)
C function: void mgl_parser_allow_setsize (HMPR p, int a)

Allow to parse ’setsize’ command or not.

Method on mglParse (C++): void AddCommand (mglCommand *cmd, int num=0)

Add num commands cmd to the defined MGL commands list. Parameter cmd is array of mglCommand structures. If parameter num=0 then it will be determined automatically. At this, array cmd must have last element with name=L""

Option of mglParse: mglVar * DataList

List of variables defined in script.

Option of mglParse: bool AllowSetSize

Flag which allows/forbids the command setsize in scripts.

Option of mglParse: bool Stop

Flag which interrupt script execution.

Option of mglParse: mglCommand * Cmd

Table (array) of recognizable MGL commands (can be changed by user). Items in the table MUST be sorted by name field !!! Last items must have empty name (i.e. L"").

Option of mglParse: wchar_t * op1

These strings contain command options and should be placed before the command. These variables are used for MGL->C++ (or other language) conversion.

Option of mglParse: wchar_t * op2

These strings contain command options and should be placed after the command. These variables are used for MGL->C++ (or other language) conversion.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.