📄 lg.y
字号:
%{ // -*- Mode : c++ -*- // // SUMMARY : // USAGE : // ORG : // AUTHOR : Frederic Hecht // E-MAIL : hecht@ann.jussieu.fr // /* This file is part of Freefem++ Freefem++ is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. Freefem++ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Freefem++; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "config-wrapper.h"#define eflval yylval #include <iostream>#include <complex>#include <string> // for reset cout,cin in windows dll#ifdef _WIN32#include <ext/stdio_filebuf.h>#include <iostream>#include <cstdio>#endif#include "error.hpp"class Iden;#include "strversionnumber.hpp"#ifdef __MWERKS__#ifdef __INTEL__#include <malloc.h>#else#include <alloca.h>#endif#endif#include "AFunction.hpp"// to reserve space to graphical pointer function#include "rgraph.hpp"#include "RNM.hpp"#include "fem.hpp"#include "FESpacen.hpp" #include "FESpace.hpp" #include "MeshPoint.hpp"#include "lgfem.hpp" #include "lex.hpp"#include "environment.hpp" extern FILE *ThePlotStream; class Routine;bool load(string s); template <class R,int d> class FE; template <class R,int d,int i> class FE_;extern mylex *zzzfff;#ifdef PARALLELE void initparallele(int &, char **&); void init_lgparallele(); void end_parallele();#endif#ifdef HAVE_LIBARPACK void init_eigenvalue();#endif aType dcltype;const int nbembtype=10;aType rettype[nbembtype];Block * routineinblock[nbembtype]; // Add FH july 2005 pb clean on return int kkembtype=-1;int inloopcount=0;Block *currentblock;// Add FH july 2005 // problem clean variable after break,continue and return.const int sizeStackOfLoop=100; Block * StackOfLoop[sizeStackOfLoop];// end ADDdouble CPUcompileInit =0;//class pfes;C_F0 fespacetype;bool fespacecomplex;int fespacedim;int ShowAlloc(const char *s,size_t &);inline int yylex() {return zzzfff->scan();}inline int lineno() {return zzzfff->lineno();}extern bool withrgraphique;inline void fingraphique() { if(withrgraphique) { withrgraphique=false; rattente(1); closegraphique(); }}void lgerror (const char* s) ;%}%union{ double dnum; long lnum; char * str; char oper[8]; CC_F0 cexp; Routine *routine; AC_F0 args; aType type; CListOfInst cinst; Block * block; ListOfId *clist_id;/* ListCatch * clist_Catchs;*/}/* BISON Declarations */%type <cinst> input%type <cinst> instructions%type <cexp> instruction%type <cexp> try%type <cexp> catchs/* %type <cexp> throw */%type <cexp> declaration %type <cexp> declaration_for%type <cexp> list_of_dcls%type <cexp> fespace_def%type <cexp> fespace_def_list%type <cexp> Expr%type <cexp> no_comma_expr%type <cexp> sub_script_expr%type <cexp> no_ternary_expr%type <cexp> no_set_expr%type <cexp> unary_expr%type <cexp> pow_expr%type <cexp> primary%type <oper> unop%type <args> parameters%type <args> array %type <args> parameters_list%type <cexp> begin%type <cexp> end%type <clist_id> list_of_id_args%type <clist_id> list_of_id1%type <cexp> spaceIDs%type <cexp> spaceIDa%type <cexp> spaceIDb%type <cexp> ID_space%type <cexp> ID_array_space%type <args> bornes;%type <args> border_expr;%type <type> type_of_dcl;%type <str> id;%type <str> fespace123;/* Add precedence rules to solve dangling else s/r conflict */%nonassoc IF%nonassoc ELSE%left <oper> ','%right <oper> '=' SET%left <oper> LTLT GTGT%left <oper> OR '|' %left <oper> AND '&' %left <oper> EQ NE%left <oper> '<' '>' LE GE %left <oper> '+' '-'%left <oper> '*' '/' '%' DOTSTAR DOTSLASH%right <oper> UNARY PLUSPLUS MOINSMOINS '!'%right <oper> '^' '\''%right <oper> '_' %left <oper> '(' '[' '.'%token <oper> ')' ']' %token <lnum> LNUM%token <dnum> DNUM%token <dnum> CNUM%token <str> ID%token <str> FESPACEID%token <str> IDPARAM%token <str> STRING%token ENDOFFILE%token INCLUDE%token LOAD%token BIDON %token FOR%token WHILE%token IF%token ELSE%token BREAK%token CONTINUE%token RETURN%token TRY%token CATCH%token THROW%token <type> TYPE%token <type> FUNCTION%token <str> FESPACE%token <str> FESPACE1%token <str> FESPACE3%token DOTSTAR%token DOTSLASH%token AND%token OR%token EQ%token NE%token LE%token GE%token PLUSPLUS%token MOINSMOINS%token SET%token LTLT%token PLUSEQ%token MOINSEQ%token MULEQ%token DIVEQ%token GTGT%token ARROW%token BORDER%token CURVE%token SOLVE%% start: input ENDOFFILE { const char * magicffglut="#!ffglutdata2..\n"; if(ThePlotStream) fwrite(magicffglut,strlen(magicffglut),1,ThePlotStream); size_t sizestack = currentblock->size()+1024 ; // before close $1+=currentblock->close(currentblock); if(verbosity) cout << " sizestack + 1024 =" << sizestack << " ( " << sizestack-1024 <<" )\n" ; size_t lg0,lg1; int NbPtr = ShowAlloc("init execution ",lg0); // number of un delele ptr if(verbosity) cout << endl; { Stack stack = newStack(sizestack); double CPUcompile= CPUtime(); try { $1.eval(stack);} catch ( E_exception & e) { cerr << e.what() << " , mpirank " << mpirank << endl; return 1; } catch( Error & err) { cerr << err.what() << endl; cerr << " err code " << err.errcode() << " , mpirank " << mpirank << endl; return err.errcode(); } catch( ...) { cerr << "Strange catch exception ???\n"; cerr << " at exec line " << TheCurrentLine << " , mpirank " << mpirank << endl; return 1; } if(verbosity) cout << "times: compile "<< CPUcompile-CPUcompileInit <<"s, execution " << CPUtime()-CPUcompile <<"s, mpirank:" << mpirank << endl; deleteStack(stack); //debugstack.clear() } fingraphique(); if(ThePlotStream) {pclose(ThePlotStream); ThePlotStream=0;} NbPtr = ShowAlloc("end execution -- ",lg1) - NbPtr; if (NbPtr) { cout << " ######## We forget of deleting " << NbPtr << " Nb pointer, " << lg1-lg0 << "Bytes " << " , mpirank " << mpirank <<endl;} return 0;};input: instructions ; instructions: instruction {$$=$1;;;} | instructions instruction { $$= ($1+=$2) } ;list_of_id_args: { $$=new ListOfId();} | id { $$ = new ListOfId(); $$->push_back(UnId($1))} | id '=' no_comma_expr { $$ = new ListOfId(); $$->push_back(UnId($1,$3)) } | FESPACE id { $$ = new ListOfId(); $$->push_back(UnId($2,Find($1),atype<FE<double,2> **>()))} | FESPACE '&' id { $$ = new ListOfId(); $$->push_back(UnId($3,Find($1),atype<FE<double,2> **>(),true))} | FESPACE3 id { $$ = new ListOfId(); $$->push_back(UnId($2,Find($1),atype<FE<double,3> **>()))} | FESPACE3 '&' id { $$ = new ListOfId(); $$->push_back(UnId($3,Find($1),atype<FE<double,3> **>(),true))} | type_of_dcl id { $$ = new ListOfId(); $$->push_back(UnId($2,C_F0(),$1->right())) } | type_of_dcl '&' id { $$ = new ListOfId(); $$->push_back(UnId($3,C_F0(),$1,true)) } | '[' list_of_id_args ']' { $$ = new ListOfId(); $$->push_back(UnId($2)) } | list_of_id_args ',' id { $$ = $1; $$->push_back(UnId($3)) } | list_of_id_args ',''[' list_of_id_args ']' { $$ = $1; $$->push_back(UnId($4)) } | list_of_id_args ',' id '=' no_comma_expr { $$ = $1; $$->push_back(UnId($3,$5)) } | list_of_id_args ',' FESPACE id { $$ = $1; $$->push_back(UnId($4,Find($3),atype<FE<double,2> **>())) } | list_of_id_args ',' FESPACE '&' id { $$ = $1; $$->push_back(UnId($5,Find($3),atype<FE<double,2> **>(),true)) } | list_of_id_args ',' FESPACE3 id { $$ = $1; $$->push_back(UnId($4,Find($3),atype<FE<double,3> **>())) } | list_of_id_args ',' FESPACE3 '&' id { $$ = $1; $$->push_back(UnId($5,Find($3),atype<FE<double,3> **>(),true)) } | list_of_id_args ',' type_of_dcl id { $$ = $1; $$->push_back(UnId($4,C_F0(),$3->right())) } | list_of_id_args ',' type_of_dcl '&' id { $$ = $1; $$->push_back(UnId($5,C_F0(),$3,true)) };list_of_id1: id { $$ = new ListOfId(); $$->push_back(UnId($1)); } | list_of_id1 ',' id { $$=$1 ; $$->push_back(UnId($3)); }; id: ID | FESPACE|FESPACE3|FESPACE1; list_of_dcls: ID {$$=currentblock->NewVar<LocalVariable>($1,dcltype)} | ID '=' no_comma_expr {$$=currentblock->NewVar<LocalVariable>($1,dcltype,$3)} | ID '(' parameters_list ')' {$$=currentblock->NewVar<LocalVariable>($1,dcltype,$3); $3.destroy()} | list_of_dcls ',' list_of_dcls {$$=C_F0($1,$3)} ;parameters_list: no_set_expr {$$=$1} | FESPACE ID {$$=Find($1)} | FESPACE1 ID {$$=Find($1)} | FESPACE3 ID {$$=Find($1)} | ID '=' no_set_expr { $$=make_pair<const char *,const C_F0>($1,$3)} | parameters_list ',' no_set_expr { $$ = ($1 += $3) } | parameters_list ',' id '=' no_set_expr { $$= ($1+= make_pair<const char *,const C_F0>($3,$5))}; type_of_dcl: TYPE | TYPE '[' TYPE ']' {$$=TypeArray($1,$3)} | TYPE '[' TYPE ',' TYPE ']' {$$=TypeArray($1,$3,$5)} | TYPE '<' TYPE '>' {$$=TypeTemplate($1,$3)} ;ID_space:ID { $$ = NewFEvariable($1,currentblock,fespacetype,fespacecomplex,fespacedim); } | ID '[' no_set_expr ']' { $$ = NewFEarray($1,currentblock,fespacetype,$3,fespacecomplex,fespacedim); } | ID '=' no_set_expr { $$ = NewFEvariable($1,currentblock,fespacetype,$3,fespacecomplex,fespacedim) } | '[' list_of_id1 ']' { $$ = NewFEvariable($2,currentblock,fespacetype,fespacecomplex,fespacedim) } | '[' list_of_id1 ']' '[' no_set_expr ']' { $$ = NewFEarray($2,currentblock,fespacetype,$5,fespacecomplex,fespacedim) } | '[' list_of_id1 ']' '=' no_set_expr { $$ = NewFEvariable($2,currentblock,fespacetype,$5,fespacecomplex,fespacedim) }; ID_array_space: ID '(' no_set_expr ')' { $$ = NewFEarray($1,currentblock,fespacetype,$3,fespacecomplex,fespacedim); } | '[' list_of_id1 ']' '(' no_set_expr ')' { $$ = NewFEarray($2,currentblock,fespacetype,$5,fespacecomplex,fespacedim) };fespace123: FESPACE { fespacedim=2} |FESPACE1 { fespacedim=1} | FESPACE3 { fespacedim=3};fespace: fespace123 {fespacecomplex=false; fespacetype = Find($1);} | fespace123 '<' TYPE '>' { if ($3 != typevarreal && $3 != typevarcomplex) yyerror(" type of finite element <real> or <complex>"); fespacecomplex=($3==typevarcomplex); fespacetype = Find($1);}; spaceIDa : ID_array_space { $$ = $1 } | spaceIDa ',' ID_array_space { $$=C_F0($1,$3);} ; spaceIDb : ID_space { $$ = $1 } | spaceIDb ',' ID_space { $$=C_F0($1,$3);} ;spaceIDs : fespace spaceIDb { $$=0; $$ = $2} | fespace '[' TYPE ']' spaceIDa { $$=0; $$ = $5};fespace_def: ID '(' parameters_list ')' {$$=currentblock->NewVar<LocalVariableFES,size_t>($1,typeFESpace($3),$3,dimFESpaceImage($3)); $3.destroy(); }; fespace_def_list: fespace_def | fespace_def_list ',' fespace_def {$$=C_F0($1,$3)}; declaration: type_of_dcl {dcltype=$1} list_of_dcls ';' {$$=$3} | FESPACEID fespace_def_list ';' {$$=$2} | spaceIDs ';'{ $$=$1} | FUNCTION ID '=' Expr ';' {$$=currentblock->NewID($1,$2,$4);} | FUNCTION type_of_dcl ID '(' list_of_id_args ')' { /* use the stack to store the prev return type*/ assert(kkembtype+1<nbembtype);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -