2598 lines (2371 with data), 82.8 kB
%{
/*
(c) Copyright 2013-2014 Kallup Software.
All rights reserved.
Written by Jens Kallup <jkallup@web.de>,
This file is subject to the terms and conditions of the MIT License:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdarg.h>
#include <signal.h>
#define run_parse(x) (run_parse_mode == (x))
#define false 0
#define true 1
extern int yylex();
extern int run_parse_mode;
extern char *strlwr(char *c);
extern char *ConvertMenuString(char *dat);
extern char *ConvertMenuClass (char *dat);
extern void DisplayMessage(char*);
extern void DisplayErrorMessage(int,char*);
extern void yyrestart(FILE *);
extern void yyerror(char *msg);
extern FILE* yyin;
extern int lineno;
FILE *file_header = NULL;
FILE *file_main = NULL;
char temp_with [2048*3];
char temp_with1[2048*3];
char temp_with2[2048*3];
char expr_buffer[2048*3];
char printcon_buffer[2048*3];
char menuFile[2048];
char temp_str[2048*3];
char temp_object[2048];
char class_temp[2048];
char ttc_name[2048*3];
char *tmp_id;
char *class_object;
char *class_methode_code;
char *class_name;
char *class_type;
char *class_local;
char *class_datalink;
char *class_element;
int run_parse_mode;
int no_expr = 0;
int app_flag = 0;
int last_token = 0;
int class_counter = 0;
int function_counter = 0;
int in_while_loop = 0;
int in_array_cnt = 0;
int ifop = 0;
int program_exec_mode = 0;
int expr2inc = 2;
int twisted = 0;
int errors = 0;
int lineno = 1;
typedef unsigned short bool;
extern void check_list(char *name);
bool has_object = false;
bool in_methode = false;
bool in_main_function = false;
bool compiler_flag = true;
bool print_number = false;
bool expr2str = false;
bool not_is_true = false;
bool in_store_block = false;
bool in_array_def = false;
bool inStrinUpper = false;
#define TOK_VARIABLE 1
#define TOK_FUNCTION 2
extern void check_list(char *name);
extern char * stringReplace(char*, char*, char*);
void check_added_symbol(char*, int);
void add_dll_func(char*,char*,char*);
void write_dll_includes(void);
void write_dll_free(void);
void print_code(char* str, ... );
void add_symbol(char* str, int type);
int get_symbol(char* str);
extern int errors;
%}
%union {
int type;
float val;
char* id;
char* path;
char* text;
int trfa;
}
%start program
%token _NUM_ _ID_ _ASSIGN_ _PLUS_ _MINUS_ _DIV_ _MUL_ _MOD_ _POW_ _OBR_ _CBR_
%token _NEW_ _CLASS_ _OF_ _ENDCLASS_ _WITH_ _ENDWITH_ _LOCAL_ _COMMA_ _POINT_
%token _STRING_ _FUNCTION_ _RETURN_ _DBPOINT_ _MSGBOX_ _EQUAL_ _PARAMETER_
%token _IF_ _ELSE_ _ENDIF_ _NOT_ _TRUE_ _FALSE_ _OBR2_ _CBR2_ _MENUBAR_
%token _FOR_ _ENDFOR_ _TO_ _ARRAY_ _PRINT_TEXT_ _GETLINE_ _SELECT_ _SET_ _PATH_
%token _USE_ _PATHID_ _LEN_ _DO_ _WHILE_ _ENDDO_ _EOF_ _TIME_ _DATE_ _STORE_
%token _COUNT_ _INT_ _AUSRUF_ _DOLLAR_SIGN_
%token _CLI_PROGRAM_ _SHARP_ _EXTERN_ _FROM_ _CSTRING_
%token _CLEAR_ _UPPER_
%type <val> _NUM_
%type <id> _ID_ _DATE_ _TIME_
%type <path> _PATHID_
%type <trfa> false_true_expr
%type <text> _STRING_ string_expr with_objects function_parameters2 function_parameters
%type <text> dimension id_expr2 function_inc
%%
program : {
if run_parse(2)
{
print_code("s",
"#define __MAIN_RUN__\n"
"#include \"first.h\"\n"
"\n"
);
}
} program_stmts ;
program_stmts
:
{
strcpy(class_type,"my_cutom");
if run_parse(3)
{
//run_parse_mode = 1;
print_code("s",
"\n#ifndef __PROGRAM_MENU__\n"
"#define __PROGRAM_MENU__\n"
""
);
//run_parse_mode = 3;
}
else if run_parse(1) {
print_code("s",
"// ---------------------------------\n"
"// kbase 1.0 (c) 2012 by Jens Kallup\n"
"// ---------------------------------\n"
"#ifndef __PROGRAM_HEADER__\n"
"#define __PROGRAM_HEADER__\n\n"
"#include \"all.h\"\n"
"#ifdef __MAIN_RUN__\n"
"QVector<MyQLineEdit> edit_datasources;\n"
"#else\n"
"extern QVector<MyQLineEdit> edit_datasources;\n"
"#endif\n"
);
}
else if run_parse(2)
{
in_main_function = true;
print_code("s",
"int main(int argc, char **argv)\n{\n");
if (program_exec_mode == 1)
{
print_code(
"s",
"\tQApplication app(argc,argv);\n\n"
"\tQTranslator translator;\n"
"\ttranslator.load(\"qt_de\", \"./translations\");\n"
"\tapp.installTranslator(&translator);\n\n");
write_dll_includes();
if (class_counter > 0)
//if (strcmp(class_type,"my_cutom"))
{
/*
print_code("s",
"My ypes form;\n"
"f_types.push_back(form);\n"
);
*/
char buffer0[2048*3];
sprintf(buffer0,"my_%s *my%s_obj = new my_%s();\n",
class_name,class_name,class_name);
strcat(buffer0,"\tmy");
strcat(buffer0,class_name);
strcat(buffer0,"_obj->my_init_");
strcat(buffer0,class_name);
strcat(buffer0,"();\n");
print_code("sss","\t",buffer0,"\n"
"\n"
//"f_types[0].form = myform1_obj;\n"
//"f_types[0].form->show();\n"
"\n"
);
}
}
else if (program_exec_mode == 0)
{
if run_parse(2)
{
print_code("s",
"\tinitscr();\n"
);
}
}
}
} stmt_seq {
if (run_parse(1) || run_parse(3))
{
print_code("s","#endif\n");
}
else if run_parse(2)
{
if (program_exec_mode == 1)
{
if (app_flag == 0)
{
if (class_counter < 0)
{
print_code("ssssss",
"\tint r = app.exec();\n\n",
"\tQList<MyQDataBrowser*> allDataBrowsers =\n",
"\t",
class_name,
"_obj->findChildren<MyQDataBrowser*>();\n\n",
//"\tif (allDataBrowsers.count() > 0)\n",
//"\t\tsave_all_browsers(allDataBrowsers);\n",
"\n\treturn r;\n}\n"
);
app_flag = 1;
}
else if (class_counter == 0)
{
print_code("s", "\tint r = app.exec();\n\n");
write_dll_free();
print_code("s", "\n\treturn r;\n}\n");
}
}
}
else if (program_exec_mode == 0)
{
print_code("s",
"\tendwin();\n"
"\treturn 0;\n}\n"
);
}
}
}
;
stmt_seq
: stmt_seq stmt { }
| stmt
;
stmt : { /* empty */ }
| define_macro
| function_includes
| parameter_stmt
| print_text
| id_stmt
| num_id_stmt
| do_while_stmt
| get_line_stmt
| array_stmt
| if_stmt
| for_stmt
| func_out_stmts
| local_show
| local_stmt
| function_global
| xbase_stmts
| class_stmt
;
function_inc
: _EXTERN_ _ID_ _ID_ _OBR_ {
if run_parse(1)
print_code("sss",
"typedef QString ",
$3,
"_dll("
);
$$ = $3;
}
;
function_includes
: function_inc cpara_inc _CBR_ _ID_ {
if run_parse(1)
{
add_dll_func($1,$4,$1);
print_code("s",");\n");
}
}
| function_inc cpara_inc _CBR_ _ID_ _FROM_ string_expr {
if run_parse(1)
{
add_dll_func($1,$4,$6);
print_code("s",");\n");
}
}
;
cpara_inc
: _CSTRING_ { if run_parse(1) print_code("s", "QString"); }
| cpara_inc _COMMA_ { if run_parse(1) print_code("s", ", "); } cpara_inc
;
define_macro
: _SHARP_ _ID_ _ID_ _ID_ {
if run_parse(1)
{
if (!strcmp(strlwr($2),"define"))
if (!strcmp(strlwr($3),"app_mode"))
{
if (!strcmp(strlwr($4),"cli"))
{
printf("CLI mode\n");
program_exec_mode = 0;
}
else if (!strcmp(strlwr($4),"gui"))
{
printf("GUI mode\n");
program_exec_mode = 1;
}
}
}
}
| _SHARP_ _ID_ _ID_ { expr2inc = 1;
if run_parse(1)
{
print_code("sss",
"# define ",
$3,
" "
);
}
} expr2 {
if run_parse(1)
{
print_code("s",
"\n"
);
}
expr2inc = 2; // #define ausdrz. 0.00
}
;
get_line_stmt
: _GETLINE_ { if run_parse(2) print_code("s","\tconsole_get_line();\n"); }
;
do_while_stmt
: _DO_ _WHILE_ {
if run_parse(2)
{
print_code("s",
"while ("
);
in_while_loop = 1;
}
} do_expr stmt _ENDDO_ {
if run_parse(2)
{
print_code("s",
"}\n"
);
}
}
;
do_expr : not_expr _ID_ if_oprel
{
if run_parse(2)
{
if (ifop == 0)
{
if (not_is_true)
print_code("ss",
$2,
" != "
);
else
print_code("ss",
$2,
" == "
);
}
}
} expr2 {
if run_parse(2)
{
if (ifop == 0)
{
print_code("s",
")\n{\n"
);
}
in_while_loop = 0;
not_is_true = false;
}
}
;
not_expr: { }
| _NOT_ { not_is_true = true; }
;
if_oprel: _EQUAL_ { ifop = 0; }
;
xbase_stmts
: define_macro
| _SELECT_ {
if run_parse(2)
{
print_code("s","\txbase_select(static_cast<int>(");
}
} expr2 {
if run_parse(2)
{
print_code("s","));\n");
}
}
| _USE_ _ID_ {
if run_parse(2)
print_code("sss",
"\txbase_open_dbf(\"",
$2,
"\");\n"
);
}
| _COUNT_ _FOR_ _ID_ _ASSIGN_ string_expr {
if run_parse(2)
{
print_code("ssssss",
"\tprint_console(QString(\"count records: %1\")",
".arg(xbase_count_records(\"",
$3,
"\",",
$5,
"),10,10,QChar('0')));\n"
);
}
}
| _STORE_ {
in_store_block = true;
expr2str = true;
strcpy(expr_buffer,"");
} expr2 { expr2str = false; } _TO_ store_idents
| _STORE_ _AUSRUF_ _OBR_ string_expr _CBR_ _TO_ _ID_ {
if run_parse(1)
check_added_symbol($7,1);
if run_parse(2)
print_code("sssss",
"\t",
$7,
" = QString(",
$4,
").toUpper();\n");
}
| _STORE_ { in_store_block = true; } string_expr _TO_ _ID_ {
if run_parse(1)
check_added_symbol($5,1);
if run_parse(2)
{
print_code("sssss",
"\t",
$5,
" = QString(",
$3,
");\n"
);
}
}
| _SET_ _PATH_ _TO_ xbase_path
| _SET_ _TIME_ _TO_ string_expr {
if run_parse(2)
{
print_code("sss",
"my_set_time(QString(",
$4,
"));\n"
);
}
}
;
store_idents
: _ID_ {
if run_parse(1)
check_added_symbol($1,0);
if run_parse(2)
{
print_code("sssss",
"\t",
$1,
" = ",
expr_buffer,
";\n"
);
}
}
| store_idents _COMMA_ store_idents
;
xbase_path
: _STRING_ {
if run_parse(2)
{
print_code("sss",
"\txbase_add_path(",
stringReplace("\\","\\\\",$1),
");\n"
);
}
}
| _PATHID_ {
if run_parse(2)
{
print_code("sss",
"\txbase_add_path(\"",
stringReplace("\\","\\\\",$1),
"\");\n"
);
}
}
| xbase_path _COMMA_ xbase_path
;
print_text
: _PRINT_TEXT_ {
if run_parse(2)
{
print_code("s","\tprint_console(");
print_number = true;
}
} texter_print {
if run_parse(2)
{
print_code("s",");\n");
}
} stmt
;
texter_print
: string_expr {
if run_parse(2)
{
print_code("s",$1);
}
}
| _UPPER_ _OBR_ string_expr _CBR_ {
if run_parse(2)
{
print_code("sss",
"MyQVariant(QString(",
$3,
").toUpper())"
);
}
}
| _ID_ {
if run_parse(2)
{
print_code("ss",
"ARRAYTYPE_",
$1
);
}
} array_assign {
if run_parse(2)
{
// print_code("s",".tmp_dbl");
}
}
| print_class_var _OBR_ _CBR_ {
if run_parse(2)
print_code("sssssss",
"&my",
class_name,
"_obj->my",
class_name,
"_func_",
printcon_buffer,
"()\n"
);
}
| expr2
| _ID_ _OBR_ _CBR_ {
if run_parse(2)
{
print_code("sss",
"my_func_",
$1,
"()"
);
}
}
;
print_class_var
: _ID_ {
if run_parse(2) {
static int f = 0;
if (f == 1)
strcat(printcon_buffer,$1); else f = 1;
}
}
| print_class_var _POINT_ {
if run_parse(2) {
static int f = 0;
if (f == 1)
strcat(printcon_buffer,"->"); else f = 1;
}
} print_class_var
;
array_stmt
: _ID_ _ASSIGN_ _NEW_ _ARRAY_ {
if run_parse(2)
{
print_code("sssss",
"\ttypedef boost::multi_array<MyQVariant, __COMPILER_DIM_ARRAY_",
$1,
"> ARRAY_",
$1,
";\n"
);
in_array_cnt = 0;
in_array_def = true;
}
} _OBR_ {
strcpy(expr_buffer,"");
if run_parse(2)
{
print_code("sssss",
"\tARRAY_",
$1,
" ARRAYTYPE_",
$1,
"(boost::extents"
);
in_array_def = true;
}
} dimension _CBR_ {
if run_parse(1)
{
print_code("sssis",
"#define __COMPILER_DIM_ARRAY_",
$1,
" ",
in_array_cnt,
"\n"
);
in_array_cnt = 0;
}
if run_parse(2)
{
in_array_def = false;
print_code("ssssis",
");\n",
"\t//setArraySize(ARRAYTYPE_",
$1,
",",
in_array_cnt,
");\n\n"
);
in_array_cnt = 0;
}
} stmt
| array_def expr2 {
if run_parse(2)
{
print_code("s",";\n");
}
} stmt
| array_def string_expr {
if run_parse(2)
{
print_code("sss",
"QString(",
$2,
");\n"
);
}
} stmt
| array_def _ID_ {
if run_parse(2)
{
print_code("ss","ARRAYTYPE_",$2);
}
} array_assign {
if run_parse(2)
{
print_code("s",";\n");
}
} stmt
;
array_def
: _ID_ {
if run_parse(2)
{
print_code("ss",
"\tARRAYTYPE_",
$1
);
}
} array_assign _ASSIGN_ {
if run_parse(2)
{
print_code("s"," = ");
}
}
;
array_assign
: _OBR2_ {
in_array_def = true;
} dimension _CBR2_ {
in_array_def = false;
}
;
dimension
: expr2 {
in_array_cnt++;
}
| dimension _COMMA_ dimension
;
parameter_stmt
: { /* empty */ }
| _PARAMETER_ stack_parameter_list { }
;
stack_parameter_list
: _ID_ {
if run_parse(2)
{
print_code("sss","bool ",$1,";\n");
}
else if run_parse(3)
{
//print_code("sss","QWidget *",$1,";\n");
}
}
| stack_parameter_list _COMMA_ stack_parameter_list
;
for_body
: _FOR_ _ID_ _ASSIGN_ _ID_ {
if run_parse(2)
{
print_code("ssss",
"for (int ",
$2,
" = static_cast<int>(ARRAYTYPE_",
$4
);
}
} array_assign _TO_ {
if run_parse(2)
{
print_code("sss",
".tmp_dbl); ",
$2,
" < static_cast<int>("
);
}
} expr2 {
if run_parse(2)
{
print_code("sss",
"); ",
$2,
"++)\n{\n"
);
}
}
| _FOR_ _ID_ _ASSIGN_ {
if run_parse(2)
{
print_code("sss",
"for (int ",
$2,
" = static_cast<int>("
);
}
}
expr2 {
if run_parse(2)
{
print_code("s","); ");
}
}
_TO_ {
if run_parse(2)
{
print_code("ss",
$2,
" < static_cast<int>("
);
}
}
expr2 {
if run_parse(2)
{
print_code("sss",
"); ",
$2,
"++)\n{\n"
);
}
}
;
for_stmt
: for_body _ENDFOR_ { if run_parse(2) print_code("s","}\n"); }
| for_body stmt_seq _ENDFOR_ { if run_parse(2) print_code("s","}\n"); }
;
if_stmt : _IF_ _OBR_ {
if run_parse(2) print_code("s","\tif (");
} if_stmt2
;
if_stmt3: expr2 _EQUAL_ { if run_parse(2) print_code("s"," == "); } expr2 _CBR_ { if run_parse(2) print_code("s",")\n\t{\n"); } stmt_seq { }
;
if_stmt2
: if_stmt3 _ENDIF_ { if run_parse(2) print_code("s","\t}\n"); }
| if_stmt3 _ELSE_ { if run_parse(2) print_code("s","\t} else {\n"); } stmt_seq _ENDIF_ { if run_parse(2) print_code("s","\t}\n"); }
| if_not_stmt expr2 _CBR_ {
if run_parse(2)
{
print_code("s",")\n\t{\n\t");
}
} if_bool_stmt
;
if_not_stmt
:
| _NOT_ { if run_parse(2) print_code("s","!"); }
;
if_bool_stmt
: stmt_seq _ENDIF_ { if run_parse(2) print_code("s","\t}\n"); }
| stmt_seq _ELSE_ { if run_parse(2) print_code("s","\t}\nelse {\n"); } stmt_seq _ENDIF_ { if run_parse(2) print_code("s","\t}\n"); }
;
local_show
: _ID_ _POINT_ _ID_ _OBR_ _CBR_
{
if (last_token == _ENDCLASS_)
if run_parse(2)
{
print_code("sssss","\t",$1,".widget->",$3,"();\n\n");
}
}
;
id_stmt
: _ID_ _ASSIGN_ string_expr {
check_list($1);
if run_parse(2)
{
print_code("sssss",
"\t",
$1,
" = QString(",
$3,
");\n"
);
}
}
| _ID_ _ASSIGN_ _UPPER_ _OBR_ string_expr _CBR_ {
check_list($1);
if run_parse(2)
{
print_code("sssssss",
"\t",
$1,
" = ",
$5,
";\n\t",
$1,
".toUpper();\n");
}
}
| _ID_ _ASSIGN_ _DOLLAR_SIGN_ _OBR_ {
if run_parse(1)
check_added_symbol($1,1);
if run_parse(2)
{
print_code("sss",
"\t",
$1,
" = QString(string_format(");
}
} string_expr {
if run_parse(2)
{
print_code("ss",$6,", ");
}
} _COMMA_ expr2 _COMMA_ {
if run_parse(2)
{
print_code("s",", ");
}
} expr2 _CBR_ {
if run_parse(2)
{
print_code("s","));\n");
}
}
| _ID_ _ASSIGN_ _AUSRUF_ _OBR_ {
if run_parse(1)
check_added_symbol($1,1);
if run_parse(2)
print_code("sss","\t",$1," = QString(");
} string_expr _CBR_ {
if run_parse(2)
print_code("ss",$6,").toUpper();\n");
}
| _ID_ _ASSIGN_ _INT_ _OBR_
{
if run_parse(2)
{
print_code("sss",
"\t",
$1,
" = floor("
);
}
} expr2 _CBR_ {
if run_parse(2)
{
print_code("s",");\n");
}
}
| _ID_ _ASSIGN_ _NEW_ _ID_ _OBR_ _CBR_
{
if run_parse(2)
{
char buffer[2048];
sprintf(buffer,"my%s_obj",class_name);
if (strcmp(class_type,"my_custom"))
print_code("sssss",
"\t",
$1,
".widget = ",
buffer,
";\n\n"
);
}
}
| nested_id _ASSIGN_ {
if run_parse(2)
{
print_code("s"," = ");
}
} expr2 {
if run_parse(2)
{
print_code("s",";\n");
}
}
;
nested_id
: _ID_ _POINT_ _ID_ {
if run_parse(2)
{
static int f = 0;
if (f == 0)
{
print_code("sss",
"\tmy",
class_name,
"_obj->"
);
f = 1;
}
print_code("s",
$3
);
}
}
| _ID_ {
if run_parse(2)
{
static int f = 0;
if (f == 1) print_code("s",$1);
else f = 1;
}
}
| _POINT_ nested_id
;
local_stmt
: _LOCAL_
{
if run_parse(2)
{
print_code("s","\n\tstatic struct MyObjectTypes ");
}
}
local_stmts {
if run_parse(2)
{
print_code("s",";\n\n");
}
}
;
local_stmts
: _ID_ { if run_parse(2) print_code("s",$1); }
| local_stmts _COMMA_ { if run_parse(2) print_code("s",", "); } local_stmts
;
class_stmt
: _CLASS_ _ID_ _OF_ _ID_ _ENDCLASS_ { }
| _CLASS_ _ID_ _ENDCLASS_ {
if run_parse(1)
{
strcpy(class_name,strlwr($2));
char buf[2048];
sprintf(buf,"my_custom");
char buffer2[2048];
sprintf(buffer2,"\tvoid my_init_%s(void) { }\n",strlwr($2));
print_code("ssssss",
"\nclass my_",
$2,
" : public QObject",
"\n{\n\tQ_OBJECT\npublic:\n",
buffer2,
"};\n"
);
strcpy(class_type,buf);
class_counter++;
}
else if run_parse(2)
{
print_code("s","\treturn app.exec();\n}");
}
}
| _CLASS_ _ID_ {
if run_parse(1)
{
strcpy(class_name,strlwr($2));
char buf[2048];
sprintf(buf,"my_custom");
char buffer2[2048];
sprintf(buffer2,"\tvoid my_init_%s(void);\n",strlwr($2));
print_code("sssss",
"\nclass my_",
$2,
" : public QObject",
"\n{\n\tQ_OBJECT\npublic:\n",
buffer2
);
strcpy(class_type,buf);
class_counter++;
}
else if run_parse(2)
{
char buffer2[2048];
sprintf(buffer2,"\n"
"\treturn app.exec();\n}"
"\nvoid my_%s::my_init_%s(void)\n{\n",
class_name,
strlwr($2));
print_code("s",
buffer2
);
}
} class_stmts _ENDCLASS_ {
if (run_parse(1) || run_parse(3))
print_code("s","\n};\n"); else
print_code("s","\n}\n");
}
| _CLASS_ _ID_ _OF_ _ID_ {
if run_parse(2)
{
if (in_main_function)
{
char buffer[2048];
sprintf(buffer,"my%s_obj",class_name);
print_code("sssssss","\t",buffer,"->resize(static_cast<int>(",buffer,"->width), static_cast<int>(",buffer,"->height));\n");
print_code("sssssss","\t",buffer,"->move (static_cast<int>(",buffer,"->left), static_cast<int>(",buffer,"->top));\n");
static int f = 0;
if (f == 0)
{
print_code("sssssss",
"\tint r = app.exec();\n\n",
"\tQList<MyQDataBrowser*> allDataBrowsers =\n\tmy",
class_name,
"_obj->findChildren<MyQDataBrowser*>();\n\n",
"\tif (allDataBrowsers.count() > 0)\n",
"\t\tsave_all_browsers(allDataBrowsers);\n",
"\n\treturn r;\n}\n"
);
++f;
}
in_main_function = false;
}
print_code("sssss",
"\nvoid my_",
strlwr($2),
"::my_init_",
strlwr($2),
"(void)\n{\n"
);
print_code("sss","\tmy_init_",strlwr($4),"();\n");
}
else if run_parse(1)
{
strcpy(class_name,strlwr($2));
char buf[2048];
char puf[2048];
if (!strcmp(strlwr($4),"form"))
sprintf(puf,"\tvoid my_init_form(void) { };\n");
else sprintf(puf,"");
if (!strcmp(strlwr($4),"form")) sprintf(buf,"%s","QWidget"); else
if (!strcmp(strlwr($4),"pushbutton")) sprintf(buf,"%s","MyQPushButton"); else
if (!strcmp(strlwr($4),"query")) sprintf(buf,"%s","MyQQuery"); else
sprintf(buf,"my_%s",strlwr($4));
char buffer2[2048];
sprintf(buffer2,"\tvoid my_init_%s(void);\n",strlwr($2));
print_code("ssssssssss",
"\nclass my_",$2," : public ",buf,"\n{\n\tQ_OBJECT\npublic:\n",
buffer2,
puf,
"\tmy_",$2,"(void) {\n"
"\t\ttop = 100.00;\n"
"\t\tleft = 100.00;\n"
"\t\twidth = 100.00;\n"
"\t\theight = 100.00;\n"
"\t}\n\t"
"QString view;\n\t"
"void msgbox(QString tstr, QString mstr)\n"
"\t{\n"
"\t\tQMessageBox* msgBox = new QMessageBox();\n"
"\t\tmsgBox->setWindowTitle(tstr);\n"
"\t\tmsgBox->setText(mstr);\n"
"\t\tmsgBox->exec();\n\t}\n");
strcpy(class_type,buf);
class_counter++;
if (!strcmp($4,"form"))
{
print_code("s","public:\n");
print_code("s","\tdouble top, left, width, height;\n");
}
}
} class_stmts _ENDCLASS_ {
if (run_parse(1) || run_parse(3))
print_code("s","\n};\n"); else
print_code("s","\n}\n");
last_token = _ENDCLASS_;
}
| _CLASS_ _ID_ _OBR_ _ID_ _COMMA_ _ID_ _CBR_ _OF_ _MENUBAR_ _OBR_ _ID_ _COMMA_ _ID_ _CBR_ {
if (run_parse_mode == 3)
{
print_code("sssss",
"class my_menu_",
$2,
" : public QMenuBar\n{\n\tQ_OBJECT\npublic:\n\tmy_menu_",
$2,
"(QWidget *parent = 0);\n"
);
}
} class_stmts _ENDCLASS_ {
if (run_parse(1) || run_parse(3))
print_code("s","\n};\n"); else
print_code("s","\n}\n");
}
;
object_stmt
: _ID_ _POINT_ _ID_ _ASSIGN_ {
if run_parse(1)
{
print_code("sss",
"\tMyQVariant ",
$3,
";\n"
);
} else if run_parse(2)
{
print_code("sss",
"\tthis->",
$3,
" = "
);
}
} expr2 {
if run_parse(2)
{
print_code("s",";\n");
}
}
| _ID_ _POINT_ _ID_ _ASSIGN_ _NEW_ _ID_ _OBR_ _ID_ _CBR_
{
strcpy(class_element,$6);
strcpy(class_temp ,$3);
strcpy(class_object ,$6);
if (run_parse(1) || run_parse(3))
{
char buffer[2038];
sprintf(buffer,"%s",$3);
strcpy (class_temp ,$3);
compiler_flag = true;
if (!strcmp(strlwr($6),"menu"))
{
print_code("sss",
"\tQMenu *",
$3,
";\n");
compiler_flag = false;
}
else if (!strcmp(strlwr($6),"session"))
{
print_code("sss",
"\tMyQSession *",
$3,
";\n");
compiler_flag = false;
}
else if (!strcmp(strlwr($6),"database"))
{
print_code("sss",
"\tMyQDataBase *",
$3,
";\n");
compiler_flag = true;
}
// ninit
if (compiler_flag == true)
{
if (!strcmp(strlwr($6),"browse")) print_code("sss","\tMyQDataBrowser *",$3,";\n"); else
if (!strcmp(strlwr($6),"pushbutton")) print_code("sss","\tMyQPushButton *",$3,";\n"); else
if (!strcmp(strlwr($6),"entryfield")) print_code("sss","\tMyQLineEdit *",$3,";\n"); else
if (!strcmp(strlwr($6),"query")) print_code("sss","\tMyQQuery *",$3,";\n"); else
if (!strcmp(strlwr($6),"container" )) print_code("sss","\tQFrame *",$3,";\n");
print_code("ssssssssssssssssssssssssssssssssssssssss",
"\tvoid init_",buffer,"(void)\n\t{\n",
"\t\t",buffer,"_top = 0.00;\n",
"\t\t",buffer,"_left = 0.00;\n",
"\t\t",buffer,"_height = 35.00;\n",
"\t\t",buffer,"_width = 90.00;\n",
"\t\t",buffer,"_visible = true;\n",
"\t\t",buffer,"_text = QString(\"\");\n",
"\t}\n",
"\tQString ",buffer,"_text;\n",
"\tdouble ",buffer,"_top;\n",
"\tdouble ",buffer,"_left;\n",
"\tdouble ",buffer,"_width;\n",
"\tdouble ",buffer,"_height;\n",
"\tbool ",buffer,"_visible;\n"
);
}
}
else if (run_parse(2) || run_parse(4))
{
//if (!strcmp($8,"this"))
{
if (!strcmp(strlwr($6),"menu"))
{
print_code("sss",
"\n\t",
$3,
" = new QMenu(this);\n"
);} else
if (!strcmp(strlwr($6),"browse"))
print_code("ssssss",
"\n\t",
$3,
" = new MyQDataBrowser(this,dbfview);\n",
"\tinit_",
class_temp,
"();\n"
); else
if (!strcmp(strlwr($6),"session"))
print_code("sss",
"\n\t",
$3,
" = new MyQSession();\n"
); /*else
if (!strcmp(strlwr($6),"database"))
print_code("sss",
"\n\t",
$3,
" = new MyQDataBase();\n"
); */ else
if (!strcmp(strlwr($6),"pushbutton"))
print_code("sssssss",
"\n\t",
$3,
" = new MyQPushButton(\"PushButton\",this",
");\n",
"\tinit_",
class_temp,
"();\n"
); else
if (!strcmp(strlwr($6),"entryfield"))
print_code("ssssss",
"\n\t",
$3,
" = new MyQLineEdit(this);\n",
"\tinit_",
class_temp,
"();\n"
); else
if (!strcmp(strlwr($6),"database"))
print_code("ssssss",
"\n\t",
$3,
" = new MyQDataBase(this);\n",
"\tinit_",
class_temp,
"();\n"
); else
if (!strcmp(strlwr($6),"query"))
print_code("ssssss",
"\n\t",
$3,
" = new MyQQuery(this);\n",
"\tinit_",
class_temp,
"();\n"
); else
if (!strcmp(strlwr($6),"container"))
print_code("ssssssssssss",
"\n\t",$3," = new QFrame(this);\n",
"\t" ,$3,"->setFrameStyle(QFrame::Box | QFrame::Sunken);\n",
"\t" ,$3,"->setLineWidth(2);\n",
"\tinit_",
class_temp,
"();\n"
);
}
}
}
| with_objects_col _ASSIGN_ _NEW_ _ID_ _OBR_ with_objects { strcpy(temp_with2,temp_with); } _CBR_ {
if (run_parse(1) || run_parse(3))
{
if (!strcmp(strlwr($4),"browse")) print_code("sss","\tMyQDataBrowser *", temp_with1, ";\n"); else
if (!strcmp(strlwr($4),"pushbutton")) print_code("sss","\tMyQPushButton *" , temp_with1, ";\n"); else
if (!strcmp(strlwr($4),"entryfield")) print_code("sss","\tMyQLineEdit *" , temp_with1, ";\n"); else
if (!strcmp(strlwr($4),"query")) print_code("sss","\tMyQQuery *" , temp_with1, ";\n"); else
if (!strcmp(strlwr($4),"container" )) print_code("sss","\tQFrame *" , temp_with1, ";\n"); else
if (!strcmp(strlwr($4),"menu" )) print_code("sss","\tQMenu *" , temp_with1, ";\n");
print_code("ssssssssssssssssssssssssssssssssssssssss",
"\tvoid init_",temp_with1,"(void)\n\t{\n",
"\t\t",temp_with1,"_top = 0.00;\n",
"\t\t",temp_with1,"_left = 0.00;\n",
"\t\t",temp_with1,"_height = 35.00;\n",
"\t\t",temp_with1,"_width = 90.00;\n",
"\t\t",temp_with1,"_visible = true;\n",
"\t\t",temp_with1,"_text = QString(\"\");\n",
"\t}\n",
"\tQString ",temp_with1,"_text;\n",
"\tdouble " ,temp_with1,"_top;\n",
"\tdouble " ,temp_with1,"_left;\n",
"\tdouble " ,temp_with1,"_width;\n",
"\tdouble " ,temp_with1,"_height;\n",
"\tbool " ,temp_with1,"_visible;\n"
);
//if (!strcmp(strlwr($4),"browse"))
//print_code("sss","\tQString ", temp_with1, "_alias;\n");
strcpy(class_element,$4);
}
else if (run_parse(2) || run_parse(4))
{
//if (!strcmp(,"this"))
{
strcpy(class_object,$4);
if (!strcmp(strlwr($4),"menu"))
{
DisplayErrorMessage(1,"Sorry 1111");
print_code("ssssssss",
"\n\t",
temp_with1,
" = new QMenu(",
temp_with2,
");\n",
"\tinit_",
temp_with1,
"();\n"
);} else
if (!strcmp(strlwr($4),"browse"))
print_code("ssssssss",
"\n\t",
temp_with1,
" = new MyQDataBrowser(",
temp_with2,
");\n",
"\tinit_",
temp_with1,
"();\n"
); else
if (!strcmp(strlwr($4),"pushbutton"))
print_code("ssssssss",
"\n\t",
temp_with1,
" = new MyQPushButton(\"PushButton\",",
temp_with2,
");\n",
"\tinit_",
temp_with1,
"();\n"
); else
if (!strcmp(strlwr($4),"entryfield"))
print_code("ssssssss",
"\n\t",
temp_with1,
" = new MyQLineEdit(",
temp_with2,
");\n",
"\tinit_",
temp_with1,
"();\n"
); else
if (!strcmp(strlwr($4),"query"))
print_code("ssssssss",
"\n\t",
temp_with1,
" = new MyQQuery(",
temp_with2,
");\n",
"\tinit_",
temp_with1,
"();\n"
); else
if (!strcmp(strlwr($4),"container"))
print_code("sssssssssss",
"\n\t",
temp_with1,
" = new QFrame(",
temp_with2,
");\n\t",
temp_with1,
"->setFrameStyle(QFrame::Box | QFrame::Sunken);\n\t",
temp_with1,
"->setLineWidth(1);\n\tinit_",
temp_with1,
"();\n"
);
}
}
strcpy(temp_str,temp_with1);
strcpy(temp_with1,"");
strcpy(temp_with2,"");
}
;
with_objects_col
: with_objects { strcpy(temp_with1,temp_with); }
;
function_parameters
: { $$ = ""; }
| _OBR_ _CBR_ { $$ = ""; }
| _OBR_ function_parameters2 _CBR_ { $$ = $2; }
;
function_parameters2
: _ID_ _ID_ {
if run_parse(1)
{
if (!strcmp($1,"int"))
$1 = "double";
strcat($$," ");
strcat($$, $2);
}
}
| function_parameters2 _COMMA_ function_parameters2 {
if run_parse(1)
{
strcat($$,", ");
strcat($$,$3);
}
}
;
class_stmts
:
| _WITH_ _OBR_ _ID_ _CBR_
{
if run_parse(2)
{
if (!strcmp($3,"this"))
{
//strcpy(class_object,$3);
}
else {
char buffer[50];
errors++;
sprintf(buffer,"ID %s unbekannt.",$3);
yyerror(buffer);
}
}
} with_stmts _ENDWITH_ class_stmts
| _WITH_ _OBR_ with_objects_col _CBR_
{
strcpy(class_temp,temp_with1);
has_object = true;
} with_stmts _ENDWITH_
{
has_object = false;
if run_parse(4)
{
if (!strcmp(strlwr(class_element),"menu"))
print_code("sss",
"\taddMenu(",
class_temp,
");\n"
);
}
else if run_parse(2)
{
char buffer2[2056];
sprintf(buffer2,"static_cast<int>(%s",class_temp);
compiler_flag = true;
if (!strcmp(strlwr(class_object),"session" )) compiler_flag = false; else
if (!strcmp(strlwr(class_object),"database")) compiler_flag = false; else
if (!strcmp(strlwr(class_object),"query")) compiler_flag = false; else
if (!strcmp(strlwr(class_object),"hrowse")) compiler_flag = true;
if (compiler_flag == true)
{
print_code("sssssss","\t",class_temp,"->resize(",buffer2,"_width), ",buffer2,"_height));\n");
print_code("sssssss","\t",class_temp,"->move (",buffer2,"_left) , ",buffer2,"_top));\n\n" );
if (!strcmp(strlwr(class_object),"container")) compiler_flag = false;
if (!strcmp(strlwr(class_object),"query")) compiler_flag = false;
if (!strcmp(strlwr(class_object),"browse")) compiler_flag = false;
if (compiler_flag == true)
{
print_code("sssss","\t",class_temp,"->setText(",class_temp,"_text);\n");
print_code("sssss","\t",class_temp,"->setDataField(",class_datalink,");\n\n");
}
print_code("sssssss",
"\tif (",
class_temp,
"_visible) ",
class_temp,
"->show();\n\telse ",
class_temp,
"->hide();\n\n"
);
}
}
strcpy(temp_str,temp_with1);
strcpy(temp_with1,"");
strcpy(temp_with2,"");
} class_stmts
| object_stmt class_stmts
| function_decl _RETURN_ { if run_parse(1) print_code("s","\t\tqv = "); } expr1 {
if run_parse(1)
{
print_code("s",";\n\t\treturn qv;\n\t}\n");
}
} class_stmts
| function_decl function_stmts _RETURN_ _ID_ {
if run_parse(1)
{
strcat(ttc_name, $4);
if (get_symbol($4) == TOK_FUNCTION)
strcat(ttc_name,"()");
print_code("sss","\t\treturn ", ttc_name, ";\n\t}\n");
}
} class_stmts
| function_decl function_stmts _RETURN_ {
if run_parse(1)
print_code("s","\t\tqv = ");
} _STRING_ {
if run_parse(1)
{
print_code("s","\t\treturn qv.StdString();\n\t}\n");
}
} class_stmts
| function_decl function_stmts _RETURN_ {
if run_parse(1)
print_code("s","\t\tqv = ");
} expr1 {
if run_parse(1)
{
print_code("s",";\n\t\treturn qv;\n\t}\n");
}
} class_stmts
;
function_decl
: _FUNCTION_ _ID_ function_parameters {
if run_parse(1)
{
strcpy(ttc_name,"my");
strcat(ttc_name,class_name);
strcat(ttc_name,"_func_");
if (get_symbol($2) == TOK_VARIABLE) strcpy(ttc_name,"");
else
add_symbol($2,TOK_FUNCTION);
print_code(
"sssssss",
"\n\tMyQVariant my",
class_name,
"_func_",
$2,
"(",
$3,
")\n\t{\n\t"
"\tMyQVariant qv;\n"
);
}
}
;
function_global
: _FUNCTION_ _ID_ {
if run_parse(2)
{
if (function_counter <= 0)
{
print_code("s",
"\treturn app.exec();\n}\n\n");
function_counter = 1;
}
print_code("sss",
"MyQVariant my_func_",
$2,
"("
);
run_parse_mode = 1;
print_code("sss",
"extern MyQVariant my_func_",
$2,
"("
);
run_parse_mode = 2;
}
} function_parameters {
if run_parse(2)
{
print_code("s",
")\n{\n\tMyQVariant qv;\n"
);
run_parse_mode = 1; print_code("s",");\n");
run_parse_mode = 2;
}
} func_out_stmts _RETURN_ {
if run_parse(2)
{
print_code("s",
"\tqv = ");
}
} expr2 {
if run_parse(2)
{
print_code("s",
";\n\treturn qv;\n}\n");
}
}
;
func_out_stmts
: { /* empty */ }
| msgbox_function { }
;
msgbox_function
: _MSGBOX_ _OBR_ _STRING_ _COMMA_ _STRING_ _CBR_ {
if run_parse(2)
{
print_code("sssss",
"\tmsgbox(QString(",
$3,
"),QString(",
$5,
"));\n"
);
}
}
;
function_stmts
: { /* empty */ }
| msgbox_function_class { }
;
msgbox_function_class
: _MSGBOX_ _OBR_ _STRING_ _COMMA_ _STRING_ _CBR_ {
if run_parse(1)
{
print_code("sssss",
"\t\tmsgbox(QString(",$3,"), QString(",$5,"));\n"
);
}
}
;
with_objects
: _ID_ _POINT_ _ID_ {
strcpy(temp_with,$3);
}
| _ID_ _POINT_ _ID_ _POINT_ _ID_ {
strcpy(temp_with,$3); strcat(temp_with,"_");
strcat(temp_with,$5);
}
| _ID_ _POINT_ _ID_ _POINT_ _ID_ _POINT_ _ID_ {
strcpy(temp_with,$3); strcat(temp_with,"_");
strcat(temp_with,$5); strcat(temp_with,"_");
strcat(temp_with,$7);
}
| _ID_ _POINT_ _ID_ _POINT_ _ID_ _POINT_ _ID_ _POINT_ _ID_ {
strcpy(temp_with,$3); strcat(temp_with,"_");
strcat(temp_with,$5); strcat(temp_with,"_");
strcat(temp_with,$7); strcat(temp_with,"_");
strcat(temp_with,$9 );
}
| _ID_ _POINT_ _ID_ _POINT_ _ID_ _POINT_ _ID_ _POINT_ _ID_ _POINT_ _ID_ {
strcpy(temp_with,$3); strcat(temp_with,"_");
strcat(temp_with,$5); strcat(temp_with,"_");
strcat(temp_with,$7); strcat(temp_with,"_");
strcat(temp_with,$9); strcat(temp_with,"_");
strcat(temp_with,$11);
}
;
with_stmts
:
| _ID_ _ASSIGN_ _ID_ _POINT_ _ID_ _POINT_ _ID_ _POINT_ _ID_ _OBR2_ _STRING_ _CBR2_ {
if run_parse(2)
{
if (!strcmp(strlwr($1),"datalink"))
{
print_code("sssssss",
"\t",
class_temp,
"->setDataLink(",
$5,
",",
$11,
");\n"
);
}
}
} with_stmts
| _ID_ _ASSIGN_ _CLASS_ _DBPOINT_ _ID_ {
if run_parse(1)
{
if (!strcmp(strlwr($1),"onclick"))
print_code("ssssssssss",
"public slots:\n\t",
"void ",class_temp,"_OnClick()\n\t{\n\t\t",
"my",class_name,"_func_",class_temp,"_OnClick();\n\t}\n",
"public:\n"
); else
if (!strcmp(strlwr($1),"ontimer"))
print_code("ssssssssss",
"public slots:\n\t",
"void ",
class_temp,
"_OnTimer()\n\t{\n\t\t",
"my",
class_name,
"_func_",
class_temp,
"_OnTimer();\n\t}\n",
"public:\n"
);
} else
if run_parse(2)
{
// todo: ...
if (!strcmp(strlwr($1),"onclick"))
print_code("sssss",
"\n\tQObject::connect(",
class_temp ,
", SIGNAL(clicked()), this, SLOT(",
class_temp,
"_OnClick()));\n\n"
); else
if (!strcmp(strlwr($1),"ontimer"))
print_code("sssss",
"\n\tQObject::connect(",
class_temp,
"->timer, SIGNAL(timeout()), this, SLOT(",
class_temp,
"_OnTimer()));\n\n"
);
}
} with_stmts
| _ID_ _ASSIGN_ _ID_ _POINT_ _ID_ {
if run_parse(2)
{
if (!strcmp(strlwr(class_element),"database"))
{
if (!strcmp(strlwr($1),"session"))
print_code("sssss",
"\t",
class_temp,
"->session = ",
$5,
";\n"
);
}
}
} with_stmts
| _ID_ _ASSIGN_ {
if run_parse(2)
{
strcpy(temp_object,"");
if (has_object == true)
{
if (!strcmp(strlwr(class_element),"session"))
{
if (!strcmp(strlwr($1),"timeout"))
print_code("sss","\t",class_temp,"->timeout = static_cast<int>(");
else if (!strcmp(strlwr($1),"port"))
print_code("sss","\t",class_temp,"->port = static_cast<int>(");
}
else
print_code("sssss","\t",class_temp,"_",$1," = ");
}
else {
print_code("sss" ,"\t",$1," = ");
add_symbol($1,TOK_VARIABLE);
}
}
} expr2 {
if run_parse(2)
{
if (!strcmp(strlwr($1),"timeout")) print_code("s",")"); else
if (!strcmp(strlwr($1),"port")) print_code("s",")");
print_code("s",";\n");
}
} with_stmts
| _ID_ _ASSIGN_ false_true_expr {
if run_parse(2)
{
if (!strcmp(strlwr(class_element),"session"))
{
if (!strcmp(strlwr($1),"active"))
{
if ($3 == 0) print_code("sss","\t",class_temp,"->stop();\n"); else
if ($3 == 1) print_code("sss","\t",class_temp,"->start();\n");
}
}
else if (!strcmp(strlwr(class_element),"database"))
{
if (!strcmp(strlwr($1),"active"))
{
if ($3 == 0) print_code("sss","\t",class_temp,"->close();\n"); else
if ($3 == 1) print_code("sss","\t",class_temp,"->open();\n" );
}
}
}
} with_stmts
| _ID_ _ASSIGN_ string_expr
{
if run_parse(4)
{
if (!strcmp(strlwr(class_element),"menu"))
{
if (!strcmp(strlwr($1),"text")) print_code("sssss","\t",class_temp,"->setTitle(QString(",$3,"));\n");
}
}
else if run_parse(2)
{
compiler_flag = true;
if (!strcmp(strlwr($1),"view"))
{
print_code("sss","\tQString dbfview = QString(",$3,");\n");
}
else if (!strcmp(strlwr($1),"menufile"))
{
strcpy(menuFile,$3);
print_code("sssssss",
"\tmy_menu_",
ConvertMenuClass(menuFile),
"MENU *my_menu_",
ConvertMenuClass(menuFile),
"= new my_menu_",
ConvertMenuClass(menuFile),
"MENU(this);\n"
);
compiler_flag = false;
}
else if (!strcmp(strlwr(class_element),"browse"))
{
if (!strcmp(strlwr($1),"alias")) print_code("sssss","\t",class_temp,"->setAlias(QString(",$3,"));\n");
}
else if (!strcmp(strlwr(class_element),"session"))
{
if (!strcmp(strlwr($1),"host")) print_code("sssss","\t",class_temp,"->host = QString(",$3,");\n"); else
if (!strcmp(strlwr($1),"user")) print_code("sssss","\t",class_temp,"->user = QString(",$3,");\n"); else
if (!strcmp(strlwr($1),"pass")) print_code("sssss","\t",class_temp,"->pass = QString(",$3,");\n");
}
else if (!strcmp(strlwr(class_element),"database"))
{
if (!strcmp(strlwr($1),"databasename")) print_code("sssss","\t",class_temp,"->databaseName = QString(",$3,");\n");
}
else
if (compiler_flag == true)
print_code("sssss","\t",class_temp,"_text = QString(",$3,");\n");
}
} with_stmts
;
false_true_expr
: _ID_ {
if run_parse(2)
{
if (!strcmp(strlwr($1),"false")) $$ = 0;
if (!strcmp(strlwr($1),"true")) $$ = 1;
}
}
| _FALSE_ { if run_parse(2) $$ = 0; }
| _TRUE_ { if run_parse(2) $$ = 1; }
;
string_expr
: _STRING_
{
if (!$$)
$$ = (char*) malloc(strlen($1)+1);
$$ = yylval.text;
}
| _ID_ {
char *buffer = (char*) malloc(strlen($1)+1);
if (inStrinUpper == true)
{
if run_parse(2)
{
strcpy(buffer, "upperString(");
strcat(buffer, $1);
strcat(buffer, ")");
}
inStrinUpper = false;
}
else {
if run_parse(2)
strcpy(buffer, $1);
}
if run_parse(2)
$$ = buffer;
}
| _DATE_ _OBR_ _CBR_ {
char *buffer = (char*) malloc(500);
if (!$$)
$$ = (char*) malloc(500);
strcpy(buffer,"my_date_now()");
$$ = buffer;
}
| _TIME_ _OBR_ _CBR_ {
char *buffer = (char*) malloc(500);
if (!$$)
$$ = (char*) malloc(500);
strcpy(buffer,"my_time_now()");
$$ = buffer;
}
| string_expr _PLUS_ string_expr
{
char *buffer = (char*) malloc(4096);
if (!$$)
$$ = (char*) malloc(strlen($1)+strlen($3)+5);
strcpy(buffer,"QString(");
strcat(buffer,$1);
strcat(buffer,") + (");
strcat(buffer,$3);
strcat(buffer,")");
$$ = buffer;
}
;
num_id_stmt
: _ID_ _ASSIGN_ { check_list($1); if run_parse(2) print_code("sss","\t",$1," = " ); } expr2 { if run_parse(2) print_code("s",";\n"); } stmt
| _ID_ _PLUS_ _ASSIGN_ { check_list($1); if run_parse(2) print_code("sss","\t",$1," += "); } expr2 { if run_parse(2) print_code("s",";\n"); } stmt
| _ID_ _MINUS_ _ASSIGN_ { check_list($1); if run_parse(2) print_code("sss","\t",$1," -= "); } expr2 { if run_parse(2) print_code("s",";\n"); } stmt
| _ID_ _DIV_ _ASSIGN_ { check_list($1); if run_parse(2) print_code("sss","\t",$1," /= "); } expr2 { if run_parse(2) print_code("s",";\n"); } stmt
| _ID_ _MUL_ _ASSIGN_ { check_list($1); if run_parse(2) print_code("sss","\t",$1," *= "); } expr2 { if run_parse(2) print_code("s",";\n"); } stmt
| _ID_ _MOD_ _ASSIGN_ { check_list($1); if run_parse(2) print_code("sss","\t",$1," %= "); } expr2 { if run_parse(2) print_code("s",";\n"); } stmt
| _ID_ _POW_ _ASSIGN_ { check_list($1); if run_parse(2) print_code("sss","\t",$1," ^= "); } expr2 { if run_parse(2) print_code("s",";\n"); } stmt
;
expr2 : {
if run_parse(2)
{
if (in_while_loop)
{
print_code("s",
"static_cast<int>("
);
}
}
}
| expr0 {
if (in_while_loop)
{
in_while_loop = 0;
}
}
;
expr0 : expr3 _PLUS_ { if run_parse(expr2inc) { strcat(expr_buffer," + "); if (!expr2str) print_code("s"," + "); } } expr2
| expr3 _MINUS_ { if run_parse(expr2inc) { strcat(expr_buffer," - "); if (!expr2str) print_code("s"," - "); } } expr2
| expr3 _MUL_ { if run_parse(expr2inc) { strcat(expr_buffer," * "); if (!expr2str) print_code("s"," * "); } } expr2
| expr3 _DIV_ { if run_parse(expr2inc) { strcat(expr_buffer," / "); if (!expr2str) print_code("s"," / "); } } expr2
| expr3 _MOD_ { if run_parse(expr2inc) { strcat(expr_buffer," & "); if (!expr2str) print_code("s"," % "); } } expr2
| expr3 _POW_ { if run_parse(expr2inc) { strcat(expr_buffer," ^ "); if (!expr2str) print_code("s"," ^ "); } } expr2
| expr3
;
expr3: _NUM_ {
if run_parse(expr2inc)
{
char buffer[2048];
sprintf(buffer,"%f",$1);
if (in_array_def == true)
sprintf(buffer,"[%f]",$1);
strcat(expr_buffer,buffer);
if (!expr2str)
print_code("s",buffer);
}
}
| id_expr2 {
if run_parse(1)
{
if (in_store_block)
// print_code("ss","---->",$1);
in_store_block = false;
}
else if run_parse(expr2inc)
{
char buffer[2048];
sprintf(buffer,"%s",$1);
if (in_array_def == true)
sprintf(buffer,"[%s]",buffer);
if (!expr2str)
//strcat(buffer,$1);
print_code("s",buffer);
}
}
| _OBR_ { if run_parse(2) { strcat(expr_buffer,"("); print_code("s","("); } } expr2 _CBR_ { if run_parse(2) { strcat(expr_buffer,")"); print_code("s",")"); } }
| _LEN_ _OBR_ string_expr _CBR_ {
if run_parse(2)
{
print_code("sss",
"my_strlen(",
$3,
")");
}
}
| math_ops2
;
id_expr2
: _ID_ { $$ = $1; }
| _ID_ _PLUS_ { if run_parse(2) print_code("s","MyQVariant("); } expr2 { if run_parse(2) print_code("s",") + "); $$ = $1; }
| _ID_ _MINUS_ { if run_parse(2) print_code("s","MyQVariant("); } expr2 { if run_parse(2) print_code("s",") - "); $$ = $1; }
| _ID_ _MUL_ { if run_parse(2) print_code("s","MyQVariant("); } expr2 { if run_parse(2) print_code("s",") * "); $$ = $1; }
| _ID_ _DIV_ { if run_parse(2) print_code("s","MyQVariant("); } expr2 { if run_parse(2) print_code("s",") / "); $$ = $1; }
| _ID_ _MOD_ { if run_parse(2) print_code("s","MyQVariant("); } expr2 { if run_parse(2) print_code("s",") % "); $$ = $1; }
| _ID_ _POW_ { if run_parse(2) print_code("s","MyQVariant("); } expr2 { if run_parse(2) print_code("s",") ^ "); $$ = $1; }
;
expr1 : expr4 _PLUS_ { if run_parse(1) print_code("s"," + "); } expr1
| expr4 _MINUS_ { if run_parse(1) print_code("s"," - "); } expr1
| expr4 _MUL_ { if run_parse(1) print_code("s"," * "); } expr1
| expr4 _DIV_ { if run_parse(1) print_code("s"," / "); } expr1
| expr4 _MOD_ { if run_parse(1) print_code("s"," % "); } expr1
| expr4 _POW_ { if run_parse(1) print_code("s"," ^ "); } expr1
| expr4
;
expr4: _NUM_ { if run_parse(1) print_code("f",$1);
}
| _ID_ { if run_parse(1) print_code("s",$1); }
| _ID_ _POINT_ _ID_ {
if run_parse(1) {
print_code("sss",
"this->",
$3,
".tmp_dbl"
);
}
}
| _OBR_ { if run_parse(1) print_code("s","("); } expr1 _CBR_ { if run_parse(1) print_code("s",")"); }
| math_ops2
;
math_ops2
: _ID_ _OBR_ {
if (!strcmp(strlwr($1),"sin")
|| !strcmp(strlwr($1),"cos")
|| !strcmp(strlwr($1),"tan")
|| !strcmp(strlwr($1),"asin")
|| !strcmp(strlwr($1),"acos")
|| !strcmp(strlwr($1),"atan")
) {
if run_parse(expr2inc)
{
strcat(expr_buffer,strlwr($1));
print_code("sss",
"double(",
strlwr($1),
"("
);
}
}
} expr2 _CBR_ {
if run_parse(expr2inc)
{
strcat(expr_buffer,$1);
print_code("s","))");
}
}
;
%%
void print_code(char* str, ... )
{
va_list vl;
int i;
va_start(vl, str);
// Step through the list.
for( i = 0; str[i] != '\0'; ++i )
{
union Printable_t {
int i;
float f;
char c;
char *s;
} Printable;
// Type to expect ...
switch( str[i] )
{
case 'i':
Printable.i = va_arg( vl, int );
if run_parse(1)
fprintf(file_header,"%i", Printable.i); else
fprintf(file_main ,"%i", Printable.i);
break;
case 'f':
Printable.f = va_arg( vl, double);
if run_parse(1)
fprintf(file_header,"%f", Printable.f); else
fprintf(file_main ,"%f", Printable.f);
break;
case 'c':
Printable.c = va_arg( vl, int );
if run_parse(1)
fprintf(file_header,"%c", Printable.c); else
fprintf(file_main ,"%c", Printable.c);
break;
case 's':
Printable.s = va_arg( vl, char *);
if (run_parse_mode == 3) fprintf(file_header,"%s", Printable.s); else
if (run_parse_mode == 1) fprintf(file_header,"%s", Printable.s); else
fprintf(file_main ,"%s", Printable.s);
break;
default:
break;
}
}
va_end( vl );
}
void reset_values(void)
{
lineno = 1;
strcpy(menuFile,"");
//class_counter = 0;
function_counter = 0;
}
struct used_symbol_list
{
char *name;
int type;
};
struct used_symbol_list symbol_list[4096*10];
static int symbol_list_counter = 0;
void add_symbol(char *str, int type)
{
int i;
bool found = false;
for (i = 0; i < symbol_list_counter; i++)
{
if (!strcmp(symbol_list[i].name,str))
{
found = true;
break;
}
}
if (found == false)
{
i = symbol_list_counter++;
symbol_list[i].name = (char*) malloc(strlen(str)+1);
strcpy(symbol_list[i].name,str);
symbol_list[i].type = type;
}
}
int get_symbol(char *str)
{
int i;
for (i = 0; i < symbol_list_counter; i++)
{
if (!strcmp(symbol_list[i].name,str))
return symbol_list[i].type;
} return 0;
}
extern void create_main_window(int argc, char **argv);
extern void displayEnvError(void);
int main(int argc, char **argv)
{
create_main_window(argc,argv);
return 0;
}
extern void DisplayFileError(char *msg);
extern void compile_program(void);
void start_parser(void)
{
if (run_parse(1) || run_parse(2))
yyparse();
if (run_parse(2) && strlen(menuFile) > 2)
{
char *mfile = ConvertMenuString(menuFile);
fclose(yyin);
yyin = fopen(mfile,"r");
if (!yyin)
{
DisplayFileError(mfile);
return;
}
run_parse_mode = 4;
print_code("sssss",
"my_menu_",
ConvertMenuClass(menuFile),
"MENU::my_menu_",
ConvertMenuClass(menuFile),
"MENU(QWidget *parent) : QMenuBar(parent)\n{\n"
);
run_parse_mode = 3;
fseek(yyin,0,0);
yyparse();
run_parse_mode = 4;
fseek(yyin,0,0);
reset_values();
yyrestart(yyin);
yyparse();
}
}
void restart_parser(FILE *yf)
{
yyrestart(yf);
}
void check_added_symbol(char *str, int type)
{
int i;
bool found = false;
for (i = 0; i < symbol_list_counter; i++)
{
if (!strcmp(symbol_list[i].name,str))
{
found = true;
break;
}
}
if (found == false)
{
i = symbol_list_counter++;
symbol_list[i].name = (char*) malloc(strlen(str)+1);
strcpy(symbol_list[i].name,str);
symbol_list[i].type = type;
if run_parse(1)
{
if (type == 0)
print_code("sssss",
"#ifdef __MAIN_RUN__\n",
"MyQVariant ",
str,
";\n",
"#endif\n"
);
else
print_code("sssss",
"#ifdef __MAIN_RUN__\n",
"MyQVariant ",
str,
";\n",
"#endif\n"
);
}
}
}
struct dll_func_list
{
char *name;
char *func;
char * dll;
char *fvar;
};
struct dll_func_list dll_list[4096*100];
static int dll_list_counter = 0;
void add_dll_func(char *id, char *dll, char *func)
{
int i;
bool found = false;
for (i = 0; i < dll_list_counter; i++)
{
if (!strcmp(dll_list[i].name,id))
{
found = true;
break;
}
}
if (found == false)
{
i = dll_list_counter++;
dll_list[i].name = (char*) malloc(strlen(id) + 1 );
dll_list[i].fvar = (char*) malloc(strlen(func) + 10 );
dll_list[i].func = (char*) malloc(strlen(id) + 1 );
dll_list[i].dll = (char*) malloc(strlen(id) + 1 );
strcpy(dll_list[i].name,id);
strcpy(dll_list[i].fvar,id);
strcat(dll_list[i].fvar,"Func");
strcpy(dll_list[i].dll ,dll);
if (strlen(func) > 0)
strcpy(dll_list[i].func,func); else
strcpy(dll_list[i].func,id);
}
}
struct dll_func_list_name
{
char *name;
};
struct dll_func_list_name dll_name_list[4096*10];
static int dll_name_list_counter = 0;
bool check_dll_name(char *id)
{
int i;
bool found = false;
for (i = 0; i < dll_name_list_counter; i++)
{
if (!strcmp(dll_name_list[i].name,id))
{
found = true;
return found;
}
}
if (found == false)
{
i = dll_name_list_counter++;
dll_name_list[i].name = (char*) malloc(strlen(id) + 1 );
strcpy(dll_name_list[i].name,id);
return false;
}
}
void write_dll_free(void)
{
if run_parse(2)
{
int i;
#ifdef WIN32
for (i = 0; i < dll_name_list_counter-1; i++)
{
print_code("sss",
"\tFreeLibrary(inc_",
dll_name_list[i].name,
");\n"
);
}
#endif
}
}
void write_dll_includes(void)
{
if run_parse(2)
{
int i;
#ifdef WIN32
for (i = 0; i < dll_list_counter; i++)
{
if (!check_dll_name(dll_list[i].dll))
{
print_code("sssss",
"\tHINSTANCE inc_",
dll_list[i].dll,
" = LoadLibrary(\"",
dll_list[i].dll,
".dll\");\n"
);
++dll_name_list_counter;
}
}
for (i = 0; i < dll_list_counter; i++)
{
print_code("sssssss",
"\t",
dll_list[i].name,
"_dll* ",
dll_list[i].name,
" = ",
"GetProcAddress(inc_",
dll_list[i].dll
);
if (dll_list[i].func[0] == '\"')
print_code("sss",
", ",
dll_list[i].func,
");\n"
); else
print_code("sss",
", \"",
dll_list[i].func,
"\");\n"
);
}
#endif
}
}