📄 lg.y
字号:
rettype[++kkembtype] = $2->right(); routineinblock[kkembtype] = currentblock; $<routine>5=new Routine($1,$2->right(),$3,$5,currentblock); // routineinblock[kkembtype]->Add($3,"(",$<routine>5); //pas recursif pour l'instanat test FH 27 dec 2008 // cout << " \n after new routine \n " << endl; } '{' instructions'}' { currentblock=$<routine>5->Set($9); currentblock->Add($3,"(",$<routine>5); //pas recursif pour l'instant test FH 27 dec 2008 kkembtype--; $$=0; } | FUNCTION ID '(' list_of_id_args ')' {Block::open(currentblock); $1->SetArgs($4);} '=' no_comma_expr ';' { $<cinst>$=currentblock->close(currentblock); $$=currentblock->NewID($1,$2,$8,*$4); delete $4; // FH 23032005 } ; begin: '{' { Block::open(currentblock)};end: '}' { $$=currentblock->close(currentblock)};for_loop: FOR {ffassert(inloopcount<sizeStackOfLoop); // modif FH july 2005 StackOfLoop[inloopcount++]=currentblock;};while_loop: WHILE {ffassert(inloopcount<sizeStackOfLoop); StackOfLoop[inloopcount++]=currentblock;}; // modif FH july 2005 declaration_for: type_of_dcl {dcltype=$1; Block::open(currentblock); } list_of_dcls {$$=$3};try: TRY { Block::open(currentblock) };instruction: ';' {$$=0;} | INCLUDE STRING {zzzfff->input($2);$$= 0; } | LOAD STRING {load($2);$$= 0; } | try '{' instructions '}' catchs {$$=Try($3,$5,currentblock->close(currentblock));} | Expr ';' {$$=$1} | declaration {$$=$1} | for_loop '(' Expr ';' Expr ';' Expr ')' instruction {inloopcount--; $$=For($3,$5,$7,$9)} | for_loop '(' declaration_for ';' Expr ';' Expr ')' instruction {inloopcount--; $$=C_F0(For($3,$5,$7,$9),currentblock->close(currentblock))} | while_loop '(' Expr ')' instruction {inloopcount--;$$=While($3,$5)} | IF '(' Expr ')' instruction {$$=FIf($3,$5)} | IF '(' Expr ')' instruction ELSE instruction {$$=FIf($3,$5,$7)} | begin instructions end { $$=C_F0(new E_block($2,$3),atype<void>()) } | BORDER ID border_expr { $$=0;currentblock->NewID(atype<const E_Border *>(),$2,C_F0(TheOperators,"[border]",$3))} | BORDER ID '[' array ']' ';' { $$=0;currentblock->NewID(atype<const E_Border *>(),$2,C_F0(TheOperators,"[border]",$4))} | BREAK ';' { if(inloopcount) $$= C_F0(new E_throw(E_exception::e_break),atype<void>()); else lgerror("break not in loop") } | CONTINUE ';' { if(inloopcount) $$= C_F0(new E_throw(E_exception::e_continue),atype<void>()) ; else lgerror("continue not in loop")} | RETURN Expr ';' { if (kkembtype>=0) $$= C_F0(new E_throw(E_exception::e_return,rettype[kkembtype]->CastTo($2)) ,atype<void>()); else lgerror(" return not in routine ") };catchs: CATCH '(' '.' '.' '.' ')' instruction {$$ = $7; };bornes: '(' ID '=' Expr ',' Expr ')' { Block::open(currentblock); $$ = currentblock->NewVar<LocalVariable>($2,atype<double*>()); $$+= $4; $$+= $6 };border_expr: bornes instruction { $$ = ($1 += $2); currentblock->close(currentblock)} ;Expr: no_comma_expr | Expr ',' Expr {$$=C_F0(TheOperators,$2,$1,$3);}; unop: '-' | '+' | '!' | PLUSPLUS | MOINSMOINS ;no_comma_expr: no_set_expr | no_set_expr '=' no_comma_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_set_expr PLUSEQ no_comma_expr {$$=C_F0(TheOperators,"+=",$1,$3)} | no_set_expr MOINSEQ no_comma_expr {$$=C_F0(TheOperators,"-=",$1,$3)} | no_set_expr MULEQ no_comma_expr {$$=C_F0(TheOperators,"*=",$1,$3)} | no_set_expr DIVEQ no_comma_expr {$$=C_F0(TheOperators,"/=",$1,$3)};no_set_expr: no_ternary_expr | no_ternary_expr '?' no_set_expr ':' no_set_expr {$$=C_F0(TheOperators,"?:",$1,$3,$5)};no_ternary_expr: unary_expr | no_ternary_expr '*' no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr DOTSTAR no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr DOTSLASH no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr '/' no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr '%' no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr '+' no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr '-' no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr LTLT no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr GTGT no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr '&' no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr AND no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr '|' no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr OR no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr '<' no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr LE no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr '>' no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr GE no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr EQ no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | no_ternary_expr NE no_ternary_expr {$$=C_F0(TheOperators,$2,$1,$3)} ;sub_script_expr: no_set_expr {$$=$1} | ':' {$$=C_F0(TheOperators,":")} | no_set_expr ':' no_set_expr {$$=C_F0(TheOperators,":",$1,$3)} | no_set_expr ':' no_set_expr ':' no_set_expr {$$=C_F0(TheOperators,":",$1,$3,$5)} ; parameters: {$$=0} | FESPACE {$$=Find($1)} | FESPACE1 {$$=Find($1)} | FESPACE3 {$$=Find($1)} | id '=' no_set_expr { $$=make_pair<const char *,const C_F0>($1,$3)} | sub_script_expr {$$=$1} | parameters ',' FESPACE { $$ = ($1 += Find($3)) } | parameters ',' FESPACE1 { $$ = ($1 += Find($3)) } | parameters ',' FESPACE3 { $$ = ($1 += Find($3)) } | parameters ',' sub_script_expr { $$ = ($1 += $3) } | parameters ',' id '=' no_set_expr { $$= ($1+= make_pair<const char *,const C_F0>($3,$5)) } ; array: no_comma_expr {$$=$1} | array ',' no_comma_expr {$$ = ($1 += $3) }; unary_expr: pow_expr | unop pow_expr %prec UNARY {$$=C_F0(TheOperators,$1,$2)} ; pow_expr: primary | primary '^' unary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | primary '_' unary_expr {$$=C_F0(TheOperators,$2,$1,$3)} | primary '\'' {$$=C_F0(TheOperators,$2,$1)} ;primary: ID {$$=Find($1);} | LNUM {$$= CConstant($1)} | DNUM {$$= CConstant($1)} | CNUM {$$= CConstant(complex<double>(0,$1))} | STRING {$$= CConstant<const char *>($1)} | primary '(' parameters ')' {$$=C_F0($1,$2,$3);} | primary '[' sub_script_expr ']' {$$=C_F0($1,$2,$3)} | primary '[' sub_script_expr ',' sub_script_expr ']' {$$=C_F0($1,$2,$3,$5)} | primary '[' ']' {$$=C_F0($1,"[]")} | primary '.' ID { $$=C_F0($1,$3) ;} | FESPACE '.' ID { $$=C_F0(Find($1),$3) ;} | FESPACE '(' parameters ')' { $$=C_F0(Find($1),$2,$3) ;} | FESPACE1 '.' ID { $$=C_F0(Find($1),$3) ;} | FESPACE1 '(' parameters ')' { $$=C_F0(Find($1),$2,$3) ;} | FESPACE3 '.' ID { $$=C_F0(Find($1),$3) ;} | FESPACE3 '(' parameters ')' { $$=C_F0(Find($1),$2,$3) ;} | primary PLUSPLUS {$$=C_F0(TheRightOperators,$2,$1)} | primary MOINSMOINS {$$=C_F0(TheRightOperators,$2,$1)} | TYPE '(' Expr ')' { if ($1->right()->CastingFrom($3.left()) ) $$=$1->right()->CastTo($3) ; else { $$=$1->right()->Find("<--",basicAC_F0_wa($3)); if (!$$.left()) { cerr << " no wait to change " << $3.left()->right()->name() << " in " << $1->right()->name() << endl; CompileError(" Error in type(exp) "); } } } | '(' Expr ')' {$$=$2} | '[' array ']' { $$=C_F0(TheOperators,"[]",$2)} ;%% #include <fstream>using namespace std;// bool lgdebug;// bool lexdebug;void ForDebug();void ForDebug(){ int i=0; i++;}//extern void ShowAlloc(const char *s, size_t lg);//extern void ShowNbAlloc(const char *s);void init_lgfem() ;void init_lgmesh() ;void init_lgmesh3() ;void init_algo();bool withrgraphique = false;//string StrVersionNumber();int Compile(){ extern YYSTYPE *plglval; // modif FH plglval = &lglval; int retvalue=0; // int ok; currentblock=0; Block::open(currentblock); try { retvalue=yyparse(); // compile if(retvalue==0) if(currentblock) {retvalue=1; if(!mpirank) cerr << "Error:a block is not close" << endl; } else { if( verbosity ) { cerr << " CodeAlloc : nb ptr "<< CodeAlloc::nb << ", size :" << CodeAlloc::lg << " mpirank: " <<mpirank << endl; if(!mpirank) cerr << "Bien: On a fini Normalement" << endl; } } } catch (Error & e) { retvalue=e.errcode(); cerr << "error " << e.what() << "\n code = "<< retvalue << " mpirank: " <<mpirank << endl; } catch(std::ios_base::failure & e) { cerr << "std catch io failure \n what : " << e.what() << endl;; cerr << " at exec line " << TheCurrentLine << " mpirank: " <<mpirank << endl; } catch(std::exception & e) { cerr << "std catch exception \n what : " << e.what() << endl;; cerr << " at exec line " << TheCurrentLine << " mpirank: " <<mpirank << endl; } catch(...) { cerr << "Strange catch exception ???\n"; cerr << " at exec line " << TheCurrentLine << " mpirank: " <<mpirank << endl; } return retvalue; }static void SetcppIo(){#ifdef _WIN32XXXX freopen("conin$", "r", stdin); freopen("conout$", "w", stdout); using namespace __gnu_cxx; // stdio_filebuf<char> * ccout = new stdio_filebuf<char>(stdout, std::ios_base::out); static stdio_filebuf<char> ccout(stdout, std::ios_base::out); static stdio_filebuf<char> ccin(stdin, std::ios_base::in); //stdio_filebuf<char> *ccin= new stdio_filebuf<char>(stdin, std::ios_base::in); cout.rdbuf(&ccout); cin.rdbuf(&ccin); cerr.rdbuf(&ccout); cout << " -- SetcppIo --" << endl; #endif ios::sync_with_stdio();}// pour l'environement.extern const char * prognamearg;int mainff (int argc, char **argv){ if(argc) prognamearg=argv[0]; int vvold=verbosity; if(mpirank !=0) verbosity=0; SetcppIo(); GetEnvironment(); vvold=verbosity; if(mpirank !=0) verbosity=0; // size_t lg000; // ShowAlloc("begin main ",lg000); int retvalue=0;#ifdef PARALLELE initparallele(argc,argv);#endif CPUcompileInit= CPUtime(); withrgraphique = false; atexit(ForDebug);// AllFunctions::maptype xlocal;// local=&xlocal; lexdebug = false; lgdebug = false; char * cc= new char [1024]; // istream * ccin=0; if ( ! (getprog(cc,argc,argv)>0) ) return 1; if(verbosity) { cout << "-- FreeFem++ v" << StrVersionNumber() << endl; if(verbosity>1) cout << " file :" << cc << " " << " verbosity= " << verbosity << endl; } zzzfff = Newlex(cout); /* ccin= new ifstream(cc); if (argc >1 && (ccin!=0) ) ccin= new ifstream(argv[1]),throwassert(ccin); if (ccin!=0) zzzfff = new mylex(*ccin,cout) ; else zzzfff = new mylex(cin,cout) ;*/ // les motsclefs zzzfff->Add("include",INCLUDE); zzzfff->Add("load",LOAD); zzzfff->Add("while",WHILE); zzzfff->Add("for",FOR); zzzfff->Add("if",IF); zzzfff->Add("else",ELSE); zzzfff->Add("end",ENDOFFILE); zzzfff->Add("break",BREAK); zzzfff->Add("continue",CONTINUE); zzzfff->Add("return",RETURN); zzzfff->Add("border",BORDER); zzzfff->Add("fespace",FESPACEID); zzzfff->Add("try",TRY); zzzfff->Add("catch",CATCH); zzzfff->Add("throw",THROW); Init_map_type(); if(verbosity) cout << " Load: "; init_lgfem() ; init_lgmesh() ; init_lgmesh3() ; init_algo(); #ifdef HAVE_LIBARPACK init_eigenvalue();#endif #ifdef PARALLELE init_lgparallele(); #endif //#ifdef HAVE_LIBUMFPACK //if(verbosity) cout << " UMFPACK "; // #endif // callInitsFunct(); Pb opimisation if(verbosity) cout << endl; zzzfff->input(cc); EnvironmentLoad(); // just before compile verbosity=vvold; retvalue= Compile(); #ifdef PARALLELE end_parallele();#endif // currentblock->close(currentblock).eval(thestack); fingraphique(); if(ThePlotStream) {pclose(ThePlotStream); ThePlotStream=0;} Destroylex( zzzfff); // ClearMem(); return retvalue;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -