예제 #1
0
SCRIPTCALL Script::op_makeArray()
{
	word base_index = fetchAdvance();

	MemorySegment *segment;
	if (base_index == CODE_BASEVARIABLE_FIRST) {
		segment = memory->s_Core;
	}
	else {
		segment = memory->getCurrentSegment();
	}

	base_index = (base_index - CODE_BASEVARIABLE_FIRST) * 2;
	word base = memory->b_BaseVariable->queryWord(base_index);
	word array_index = readExpression();
	array_index = base + (array_index * 2);

	MemoryBlock *memory_block = segment->get(&array_index);

	while (true) {
		word element = readExpression();
		memory_block->writeWord(array_index, element);

		byte code = fetch();
		if (code == CODE_CONTINUE) {
			array_index += 2;
			advance();
		}
		else {
			break;
		}
	}

	return RETURN_NORMAL;
}
예제 #2
0
파일: calc.c 프로젝트: Anupam02/YaleC
int readExpression(void) {
    int e1;         /* value of first sub-expression */
    int e2;         /* value of second sub-expression */
    int c;
    int op;         /* operation '+' or '*' */

    c = peekchar();
    if (c == '(') {
        c = getchar();

        e1 = readExpression();
        op = getchar();
        e2 = readExpression();

        c = getchar();  /* this had better be ')' */
        if (c != ')') return EXPRESSION_ERROR;

        /* else */
        switch(op) {
            case '*':
                return e1*e2;
                break;
            case '+':
                return e1+e2;
                break;
            default:
                return EXPRESSION_ERROR;
                break;
        }
    } else if (isdigit(c)) {
        return readNumber();
    } else {
        return EXPRESSION_ERROR;
    }
}
예제 #3
0
파일: Parser.cpp 프로젝트: pyropeter/mare
Statement* Parser::readValue()
{
  switch(currentToken.id)
  {
  case Token::not_:
    {
      UnaryStatement* statement = new UnaryStatement(*includeFile);
      statement->operation = currentToken.id;
      nextToken();
      statement->operand = readValue();
      return statement;
    }
  case Token::leftParenthesis:
    {
      nextToken();
      Statement* statement = readExpression();
      expectToken(Token::rightParenthesis);
      return statement;
    }
  case Token::leftBrace:
    {
      nextToken();
      BlockStatement* statements = new BlockStatement(*includeFile);
      while(currentToken.id != Token::rightBrace)
      {
        if(currentToken.id == Token::eof)
          expectToken(Token::rightBrace);
        statements->statements.append(readStatement());
      }
      nextToken();
      return statements;
    }
  case Token::string:
    if(currentToken.value == "true")
    {
      nextToken();
      StringStatement* statement = new StringStatement(*includeFile);
      statement->value = "true";
      return statement;
    }
    else if(currentToken.value == "false")
    {
      nextToken();
      return new StringStatement(*includeFile);
    }
    else
    {
      ReferenceStatement* statement = new ReferenceStatement(*includeFile);
      readString(statement->variable);
      return statement;
    }
  default: // quotedString
    {
      StringStatement* statement = new StringStatement(*includeFile);
      readString(statement->value);
      return statement;
    }
  }
}
예제 #4
0
파일: Parser.cpp 프로젝트: pyropeter/mare
Statement* Parser::readExpression()
{
  Statement* statement = readOrForumla();
  if(currentToken.id == Token::interrogation)
  {
    nextToken();
    IfStatement* ifStatement = new IfStatement(*includeFile);
    ifStatement->condition = statement;
    ifStatement->thenStatements = readExpression();
    if(currentToken.id == Token::colon)
    {
      nextToken();
      ifStatement->elseStatements = readExpression();
    }
    return ifStatement;
  }
  return statement;
}
예제 #5
0
파일: calc.c 프로젝트: Omer80/wimps
double userFuncNumI(double x)
{ double *r;
  double rr;
  X=x;
  r = (double *)readExpression(userFuncTxt,rd_num_int,act_num,NULL); 
  rr=*r;
  free(r);
  return rr;
}  
예제 #6
0
SCRIPTCALL Script::op_saveExpression()
{
	word index = readExpression();
	while (true) {
		word data = readExpression();
		memory->saveVariable(index, data);

		byte code = fetch();
		if (code == CODE_CONTINUE) {
			advance();
			index++;
		}
		else {
			break;
		}
	}

	return RETURN_NORMAL;
}
예제 #7
0
파일: calc.c 프로젝트: Omer80/wimps
double userFuncNumC(void)
{ double *r;
  double rr;
  r = (double *)readExpression(userFuncTxt,rd_num,act_num,NULL); 
  if(!rderrcode)
  { rr=*r;
    free(r);
    return rr;
  }else return 0;  
}  
예제 #8
0
파일: main.c 프로젝트: KovaxG/aut-eng-2014
int main()
{
    char *values;
    int size;
    readExpression(&values, &size);

    initStack(size);
    createTree(values, size);
    printTree("tree.txt");

    return EXIT_SUCCESS;
}
예제 #9
0
ScriptParameter* Script::getParameter()
{
	//assert(parameter == NULL);
	deleteParameter();

	ScriptParameter *parameter = new ScriptParameter(memory);

	byte code;
	while (true) {
		code = fetch();
		if (code == CODE_PARAMETER_STRING) {
			parameter->add(PARAMETER_TYPE_STRING, getOffset());

			advance();
			while (fetchAdvance() != CODE_PARAMETER_STRING) {
				;
			}
		}
		else if (code == CODE_PARAMETER_BLOCK) {
			parameter->add(PARAMETER_TYPE_BLOCK, getOffset());

			skipScriptBlock();
		}
		else {
			if ((code == CODE_CONSTANT_1OP) || (code == CODE_CONSTANT_2OP) || (code == CODE_CONSTANT_3OP) || ((code >= CODE_CONSTANT_RE_FIRST) && (code <= CODE_BASEVARIABLE_LAST))) {
				parameter->add(PARAMETER_TYPE_CONSTANT, readExpression());
			}
			else {
				break;
			}
		}

		code = fetch();
		if (code == CODE_CONTINUE) {
			advance();
			continue;
		}
		else {
			break;
		}
	}

	return parameter;
}
예제 #10
0
파일: Parser.cpp 프로젝트: pyropeter/mare
Statement* Parser::readStatement()
{
  Statement* statement;
  if(currentToken.id == Token::string && currentToken.value == "if")
  {
    nextToken();
    IfStatement* ifStatement = new IfStatement(*includeFile);
    ifStatement->condition = readExpression();
    ifStatement->thenStatements = readStatements();
    if(currentToken.id == Token::string && currentToken.value == "else")
    {
      nextToken();
      ifStatement->elseStatements = readStatements();
    }
    statement = ifStatement;
  }
  else if(currentToken.id == Token::string && currentToken.value == "include")
  {
    nextToken();

    String fileName;
    readString(fileName);
    if(!File::isPathAbsolute(fileName))
    {
      String parentDir = includeFile->fileDir;
      if(parentDir != ".")
        fileName = parentDir + "/" + fileName;
    }

    Parser parser(engine);
    WrapperStatement* statement = new WrapperStatement(*includeFile);
    statement->statement = parser.parse(fileName, errorHandler, errorHandlerUserData);
    if(!statement->statement)
      throw false;
    return statement;
  }
  else
    statement = readAssignment();
  while(currentToken.id == Token::comma)
    nextToken();
  return statement;
}
예제 #11
0
파일: reader0.c 프로젝트: Omer80/wimps
char* parseVertex(int v, int forReduce)
{ 
  int j;
  int sgn=1;
  char *pstr, *pstr2;

  for (j = 0; j < MAX(1,vcs.valence[v]); j++)
  {
      momsubst[j]=vcs.vertlist[v][vertexes[v].subst[j]-1].moment;
      indsubst[j]=vcs.vertlist[v][vertexes[v].subst[j]-1].lorentz;
  }
  r_reading0=vertexes[v].r_vert;

  forR_code=forReduce;                                        
  pstr = (char *) readExpression(vertexes[v].lgrnptr->description,
                                  rd_rcode, act_rcode, free);
  if(rderrcode)
  {  if(forReduce) outFileClose();
     finish();  
     sortie(60);
  }
  
  if (vcs.valence[v] == 3 &&
          prtclbase1[vcs.vertlist[v][0].partcl].cdim == 8 &&
          prtclbase1[vcs.vertlist[v][1].partcl].cdim == 8 &&
          prtclbase1[vcs.vertlist[v][2].partcl].cdim == 8)
  {
         if (vertexes[v].subst[0] > vertexes[v].subst[1]) sgn = -sgn;
         if (vertexes[v].subst[1] > vertexes[v].subst[2]) sgn = -sgn;
         if (vertexes[v].subst[0] > vertexes[v].subst[2]) sgn = -sgn;
  }
   
  if(sgn==1) 
  {  pstr2=m_alloc(strlen(pstr));
     strcpy(pstr2,pstr+2);
  } else
  { pstr2=m_alloc(strlen(pstr)+8);   
    sprintf(pstr2,"(-1)*(%s)",pstr+2);
  }                                                                                                                       
  free(pstr);
  return pstr2;                                                                                                                         
}
예제 #12
0
static void  writesubroutineinit(void)
{
   int         l;
   char        *ss;
   
   ext_h=NULL;   
   writeF("double (*aWidth_ext)(char*)=NULL;\n"); 
   writeF("static int calcFunc_stat(void)\n{\n");
   writeF(" REAL * V=va_ext;\n");
   writeF(" FError=0;\n");
   for(l=nCommonVars+1;l<=nmodelvar;l++)
   {
      if(vararr[l].used && ((modelvars[l].func && modelvars[l].pub==0) || modelvars[l].pwidth) )
      {  int num;
         checkNaN=0;
         if(modelvars[l].pwidth)
         {  writeF("   %s=aWidth_ext(\"%s\");\n",vararr[l].alias,
             prtclbase1[modelvars[l].pwidth].name); 
             checkNaN=1;
         } else
         {
           ss=(char *)readExpression(modelvars[l].func,rd_c,act_c,free);
/*	   writeF("   %s=%s;\n",vararr[l].alias,ss+3);*/
	   fprintf(outFile,"   %s=%s;\n",vararr[l].alias,ss+3);
	   free(ss);
	 }
	 if(checkNaN)
	 {
	 sscanf(vararr[l].alias,"V[%d]",&num); 
/*
if(!modelvars[l].pwidth)	 
           fprintf(outFile,"printf(\"%s= %%50.50s\\n\",\"%s\");\n",modelvars[l].varname,  modelvars[l].func);
writeF("printf(\"%s=%%E\\n\",%s);\n",vararr[l].alias,vararr[l].alias);
*/	
         writeF("   if(!isfinite(%s) || FError){ return %d;}\n",vararr[l].alias,num);
         }
      }
   }

   writeF("return 0;\n}\n"); 
}
예제 #13
0
static void  writesubroutineinit(void)
{
   int         l;
   char        *ss;
   
   if(!flag_12) writeF("#include\"extern.h\"\n");
   ext_h=fopen("results/extern.h","w");   
   fprintf(ext_h,"extern double width2_ext(char*,long );\n");
   writeF("static int calcFunc_stat(void)\n{\n");
   writeF(" double * V=va_ext;\n");
   writeF(" FError=0;\n");
   for(l=1;l<=nmodelvar;l++)
   {
      if (vararr[l].used &&  (modelvars[l].func||modelvars[l].pwidth))
      {  int num;
         checkNaN=0;
         if(modelvars[l].pwidth)
         {  writeF("   %s=width2_ext(\"%s\",%d);\n",vararr[l].alias,
             prtclbase1[modelvars[l].pwidth].name, prtclbase1[modelvars[l].pwidth].N); 
             checkNaN=1;
         } else
         {
           ss=(char *)readExpression(modelvars[l].func,rd_c,act_c,free);
/*	   writeF("   %s=%s;\n",vararr[l].alias,ss+3);*/
	   fprintf(outFile,"   %s=%s;\n",vararr[l].alias,ss+3);
	   free(ss);
	 }
	 if(checkNaN)
	 {
	 sscanf(vararr[l].alias,"V[%d]",&num); 
         writeF("   if(!finite(%s) || FError) return %d;\n",vararr[l].alias,num);
         }
      }
   }

   writeF("return 0;\n}\n"); 
   fclose(ext_h); 
}
예제 #14
0
int initScales(char*sF,char*sR,char * mess)
{  char *ch;
   char *command;
    
   if(scaleLib) dlclose(scaleLib); 
   scaleCC_=NULL;
   
   fout=fopen("scale.c","w");
   if(!fout){ if(mess) sprintf(mess,"can't open file scale.c for writing");  return -1;}
   int pos;
   NX=0;
   fprintf(fout,"#include<math.h>\n");  
   fprintf(fout,"#include\"%s/include/nType.h\"\n",rootDir);
   fprintf(fout,"#define min(x,y) (x<y? x:y)\n");
   fprintf(fout,"#define max(x,y) (x>y? x:y)\n"); 
   fprintf(fout,"extern void ScaleCC(REAL*, double (*calcPV)(char,char*,double*), double*,double*,double*);\n");
   fprintf(fout,"void ScaleCC(REAL*modelVal, double (*calcPV)(char,char*,double*), double *pvect,double *QF,double *QR)\n");
   fprintf(fout,"{ double ");
   pos=ftell(fout);
   fprintf(fout,"         \n");
   fprintf(fout," double Qfactorization;\n");   
   ch=readExpression(sF,rd_num_,act_num_,free);
   if(!ch) 
   { fclose(fout); 
     if(mess)
     { 
       sprintf(mess,"Error in Qfact scale definition: position %d :\n%s", 
                    rderrpos, errmesstxt(rderrcode));
     }
     return rderrpos;    
   } 
   fprintf(fout," *QF= %s;\n",ch);
   fprintf(fout," Qfactorization=%s;\n",ch);  
   ch=readExpression(sR,rd_num_R,act_num_,free);
   
   if(!ch) 
   { fclose(fout); 
     fout=NULL;
     if(mess)
     { 
       sprintf(mess,"Error in Qren scale definition: position %d :\n%s", 
                    rderrpos, errmesstxt(rderrcode));
     }
     return rderrpos;    
   } 
   fprintf(fout," *QR= %s;\n",ch);
      
   fprintf(fout,"}\n");
   fseek(fout,pos,SEEK_SET);
   fprintf(fout,"X[%d];",NX+1);
   fclose(fout);
   free(ch);
   
    command=malloc(strlen(rootDir)+100);
    sprintf(command,". %s/FlagsForSh; $CC $CFLAGS $SHARED -o scale.so scale.c",rootDir);
    system(command);
    free(command);
    scaleLib=dlopen("./scale.so",RTLD_NOW);
    if(!scaleLib)
    {
       if(mess) sprintf(mess,"Can't load shared library for QCD scale"); 
       return -3;
    } 
    scaleCC_=dlsym(scaleLib,"ScaleCC");
    if(!scaleCC_)
    {  
       if(mess) sprintf(mess,"Problem in library scale.so ");
       return -4;
    }
    return 0;
}
예제 #15
0
int main(int argv, char**argc)
{
  char fname[200];
  int i,nLn,L;
  FILE*f;  
  int nVar=0,nFunc=0,first; 
  char path[200];
  
  if(argv!=3) { printf("Arguments expected: 1)path to model files; 2) model number.\n"); return 1;}

  sscanf(argc[1],"%s",path);
  if(sscanf(argc[2],"%d",&L)!=1) { printf("Second argument should be a number\n"); return 1;}
  readModelFiles(path,L);
  
  if(!loadModel(0,1)) {printf("Error in model\n"); return 3;}
  f=fopen("VandP.c","w");  
  fprintf(f,"#include <stdio.h>\n");
  fprintf(f,"#include <math.h>\n");
  fprintf(f,"#include \"V_and_P.h\"\n");
  fprintf(f,"extern int  FError;\n");  


  for(nLn=0,i=0;i<nparticles;i++)
     if(!strchr("*cCtTf",prtclbase[i].hlp)&&i+1<=prtclbase[i].anti)nLn++;

  fprintf(f,"int nModelParticles=%d;\n",nLn);
  fprintf(f,"ModelPrtclsStr ModelPrtcls[%d]=\n{\n",nLn);

  for(nLn=0,i=0;i<nparticles;i++) if(!strchr("*fcCtT",prtclbase[i].hlp))
  { int anti=prtclbase[i].anti; 
    if(i+1>anti)  continue;
    if(nLn)fprintf(f,","); else fprintf(f," "); nLn++; 
      fprintf(f," {\"%s\",",prtclbase[i].name);
      if(i+1==anti)   fprintf(f,"\"%s\", ",prtclbase[i].name);
           else       fprintf(f,"\"%s\", ",prtclbase[anti-1].name);
     fprintf(f,"%ld, \"%s\",\"%s\",%d,%d,%d}\n",
       prtclbase[i].N,  prtclbase[i].massidnt, prtclbase[i].imassidnt,  
       prtclbase[i].spin, prtclbase[i].cdim,prtclbase[i].q3);
  }
  fprintf(f,"};\n");

  if (vararr) free(vararr);
  vararr = (singlevardescription*)m_alloc((nCommonVars+1)
                                            * sizeof(singlevardescription));

  for(i=0;i<=nCommonVars;i++)
  {  if(i==0 || strcmp(modelvars[i].varname,"i")==0) 
     { sprintf(vararr[i].alias,"XXX");
       vararr[i].tmpvalue=0;
       vararr[i].num=0;
       vararr[i].used = 0;
     }else
     { sprintf(vararr[i].alias,"V[%d]",nVar+nFunc);
       vararr[i].tmpvalue=modelvars[i].varvalue;
       vararr[i].num=nVar+nFunc;
       vararr[i].used = 1;
       if(modelvars[i].func) nFunc++; else nVar++;
     }
  }

  fprintf(f,"int nModelVars=%d;\n",nVar);
  fprintf(f,"int nModelFunc=%d;\n",nFunc);
  fprintf(f,"char*varNames[%d]={\n ", nVar+nFunc);
 
  for(first=1,i=0;i<=nCommonVars;i++) if(vararr[i].used) 
  { if(first)  first=0;else fprintf(f,",");
    fprintf(f,"\"%s\"\n",modelvars[i].varname);
  }
  fprintf(f,"};\n");
  fprintf(f,"double varValues[%d]={\n ", nVar+nFunc);
  for(first=1,i=0;i<=nCommonVars;i++) if(vararr[i].used) 
  { if(first)  first=0;else fprintf(f,",");
    fprintf(f,"%E\n",modelvars[i].varvalue);
  }
  fprintf(f,"};\n");

/*static void  writesubroutineinit(void) */

  fprintf(f,"#include\"extern.h\"\n");
  ext_h=fopen("extern.h","w");
  readEXTFunc(ext_h);
  fprintf(f,"int calcMainFunc(void)\n{\n");
  fprintf(f," FError=0;\n");
  fprintf(f," double *V=varValues;\n");
  for(i=1;i<=nCommonVars;i++)
  {
  
     if (vararr[i].used &&  modelvars[i].func)
     { checkNaN=0;
        { char * ss=(char *)readExpression(modelvars[i].func,rd_c,act_c,free);
           fprintf(f,"   %s=%s;\n",vararr[i].alias,ss+3);
           free(ss);
        }        
        if(checkNaN)
        fprintf(f,"   if(!finite(%s) || FError) return %d;\n",vararr[i].alias,vararr[i].num); 
     }     
  }

  fprintf(f,"return 0;\n}\n");
  fclose(ext_h);

  fclose(f);
  return 0;
}
예제 #16
0
int main(int argv, char**argc)
{
  int i,i10,nv,nLn,L;
  FILE*f,*fExt;  
  int nVar=0,nFunc=0,first; 
  char path[200];
  char * CalcHEP=NULL;
  
  if(argv!=3) { printf("Arguments expected: 1)path to model files; 2) model number.\n"); return 1;}

  L=strlen(argc[0]);
  CalcHEP=malloc(L+10);
  strcpy(CalcHEP,argc[0]);
  CalcHEP[L-15]=0;
  sscanf(argc[1],"%s",path);
  if(sscanf(argc[2],"%d",&L)!=1) { printf("Second argument should be a number\n"); return 1;}

  readModelFiles(path,L);
  if(!loadModel(0,1)) {printf("Error in model\n"); return 3;}


  f=fopen("VandP.c","w");
  fprintf(f,"#include <stdio.h>\n");
  fprintf(f,"#include <stdlib.h>\n");
  fprintf(f,"#include <string.h>\n");
  fprintf(f,"#include \"%s/include/extern.h\"\n", CalcHEP);
  fprintf(f,"#include \"%s/include/V_and_P.h\"\n",CalcHEP);
  fprintf(f,"#include \"autoprot.h\"\n");
  fprintf(f,"extern int  FError;\n");  

  if(EXTFunc) free(EXTFunc);
  EXTFunc=malloc(2); EXTFunc[0]=' '; EXTFunc[1]=0;
  sprintf(CalcHEP+strlen(CalcHEP),"/include/extern.h");  
  fExt=fopen(CalcHEP,"r");
  readEXTFunc(fExt);
  fclose(fExt);
  readModelFunc(f);
  ext_h=fopen("autoprot.h","w");

  for(nLn=0,i=0;i<nparticles;i++)
     if(!strchr("*fcCtT",prtclbase[i].hlp)&&i+1<=prtclbase[i].anti)nLn++;

  fprintf(f,"int nModelParticles=%d;\n",nLn);
  fprintf(f,"ModelPrtclsStr ModelPrtcls[%d]=\n{\n",nLn);

  for(nLn=0,i=0;i<nparticles;i++) if(!strchr("*fcCtT",prtclbase[i].hlp))
  { int anti=prtclbase[i].anti; 
    if(i+1>anti)  continue;
    if(nLn)fprintf(f,","); else fprintf(f," "); nLn++; 
      fprintf(f," {\"%s\",",prtclbase[i].name);
      if(i+1==anti)   fprintf(f,"\"%s\", ",prtclbase[i].name);
           else       fprintf(f,"\"%s\", ",prtclbase[anti-1].name);
     fprintf(f,"%ld, \"%s\",\"%s\",%d,%d,%d}\n",
       prtclbase[i].N,  prtclbase[i].massidnt, prtclbase[i].imassidnt,  
       prtclbase[i].spin, prtclbase[i].cdim,prtclbase[i].q3);
    
  }
  fprintf(f,"};\n");

  if (vararr) free(vararr);
  vararr = (singlevardescription*)m_alloc((nCommonVars+1)
                                            * sizeof(singlevardescription));

  sprintf(vararr[0].alias,"XXX");
  vararr[0].tmpvalue=vararr[0].num=vararr[0].used = 0;

  for(i=1;i<=nCommonVars;i++)
  {  if(strcmp(modelvars[i].varname,"i")==0) 
     { sprintf(vararr[i].alias,"I");
       vararr[i].tmpvalue=0;
       vararr[i].num=0;
       vararr[i].used = 0;
     }else
     { sprintf(vararr[i].alias,"V[%d]",nVar+nFunc);
       vararr[i].tmpvalue=modelvars[i].varvalue;
       vararr[i].num=nVar+nFunc;
       vararr[i].used = 1;
       if(modelvars[i].func) nFunc++; else nVar++;
     }
  }

  fprintf(f,"int nModelVars=%d;\n",nVar);
  fprintf(f,"int nModelFunc=%d;\n",nFunc);
  fprintf(f,"int LastVar=%d;\n",nVar);
  fprintf(f,"char*varNames[%d]={\n ", nVar+nFunc);
 
  for(first=1,i10=0, i=0;i<=nCommonVars;i++) if(vararr[i].used) 
  { if(first)  first=0; else fprintf(f,",");
    fprintf(f,"\"%s\"",modelvars[i].varname);
    if(++i10==10) {fprintf(f,"\n"); i10=0;}
  }
  fprintf(f,"};\n");
  fprintf(f,"double varValues[%d]={\n ", nVar+nFunc);
  for(first=1,nv=0,i10=0,i=0 ;i<=nCommonVars;i++) if(vararr[i].used) 
  { if(first)  first=0;else fprintf(f,",");
    fprintf(f,"%14.6E",modelvars[i].varvalue);
    if(++i10==10) { fprintf(f,"\n"); i10=0; }
    if(++nv==nVar) break;
  }
  fprintf(f,"};\n");
  

  fprintf(f,"int calcMainFunc(void)\n{\n");
  fprintf(f,"   int i;\n");
  fprintf(f,"   static double * VV=NULL;\n");
  fprintf(f,"   static int iQ=-1;\n");
  fprintf(f,"   static int cErr=0;\n");
  fprintf(f,"   double *V=varValues;\n");
  fprintf(f,"   FError=0;\n");
  fprintf(f,"   if(VV&&!cErr)\n"); 
  fprintf(f,"   { for(i=0;i<nModelVars;i++) if(i!=iQ && VV[i]!=V[i]) break;\n");
  fprintf(f,"     if(i==nModelVars) ");

  if(depQ1<=nCommonVars)
  { 
    fprintf(f,"     {if(iQ>=0 && VV[iQ]!=V[iQ]) goto FirstQ; else return 0;} \n");
  } else fprintf(f,"    return 0;\n");
  
  fprintf(f,"   }\n");
  
/*  fprintf(f," printf(\" callMainFunc\\n\");\n");  */

  fprintf(f,"  cErr=1;\n");
  for(i=1;i<=nCommonVars;i++)
  {
     if (vararr[i].used &&  modelvars[i].func)
     { checkNaN=0;
if(i==depQ1) fprintf(f," FirstQ:\n  cErr=1;\n");     
        {  char * ss=(char *)readExpression(modelvars[i].func,rd_c,act_c,free);
           fprintf(f,"   %s=%s;\n",vararr[i].alias,ss+3);
           free(ss);
           fprintf(f," LastVar=%d; ",vararr[i].num);
        }
        if(checkNaN)
        fprintf(f,"   if(!finite(%s) || FError) return %d;\n",vararr[i].alias,vararr[i].num);
        else fprintf(f,"\n");
     }
  }

  fprintf(f,"   if(VV==NULL) \n");
  fprintf(f,"   {  VV=malloc(sizeof(double)*nModelVars);\n");
  fprintf(f,"      for(i=0;i<nModelVars;i++) if(strcmp(varNames[i],\"Q\")==0) iQ=i;\n");
  fprintf(f,"   }\n");
  fprintf(f,"   for(i=0;i<nModelVars;i++) VV[i]=V[i];\n");
  fprintf(f,"   cErr=0;\n");
  fprintf(f,"return 0;\n}\n");


  fclose(f);
  fclose(ext_h);
  return 0;
}
예제 #17
0
파일: calc.c 프로젝트: Anupam02/YaleC
int main()
{
    int ans = readExpression();
    printf("%d\n",ans);
    return 0;
}
예제 #18
0
void *  read_rmonom(char* txt)
{ return  readExpression(txt,rd_rat, act_rat, NULL);}
예제 #19
0
void  diagramsrfactors(hlpcsptr gst,s_listptr* s,rmptr* totf)
{s_listptr    s1, s2, ss, dl;
 vcsect       vcs_copy;
 int          i;
 rmptr        rcoef, rrcoef;
 rmptr        r;
 s_monom      stmp, stmp2; 
 int      first; 


   s1 = NULL; 
   s2 = NULL; 

   first = 1; 
   vcs_copy = vcs; 
   while (gst != NULL) 
   { 
      ss = (s_listptr) m_alloc(sizeof(struct s_listrec));
      ss->next = s1; s1 = ss; 
      ss = (s_listptr) m_alloc(sizeof(struct s_listrec));
      ss->next = s2; s2 = ss; 
      coloringvcs(gst); 
      attachvertexes(); 
      rcoef = (rmptr) readExpression(vertexes[0].lgrnptr->comcoef,
                                 rd_rat,act_rat,NULL); 
      for (i = 2; i <= vcs.sizet; i++) 
      { 
         rrcoef = (rmptr) readExpression(vertexes[i-1].lgrnptr->comcoef,
                                     rd_rat,act_rat,NULL); 
         mult_rptr(&rcoef,&rrcoef); 
      } 
      if (first) 
      { 
         r = rcoef; 
         s1->monom.c = 1; 
         s1->monom.v = NULL; 
         s2->monom.c = 1; 
         s2->monom.v = NULL; 
         first = 0; 
      } 
      else 
      { 
         copysmonom(r->n,&s1->monom); 
         s2->monom = rcoef->n; 
         reduce_s(&s1->monom,&s2->monom); 
         copysmonom(s1->monom,&stmp); 
         reduce_s(&r->n,&stmp); 
         mult_s(&r->n,&stmp);   /*  for case Stmp = -1  */ 
         copysmonom(r->d,&stmp); 
         reduce_s(&stmp,&rcoef->d); 
         copysmonom(rcoef->d,&stmp2); 
         mult_s(&s1->monom,&rcoef->d); 
         mult_s(&s2->monom,&stmp); 
         mult_s(&r->d,&stmp2); 
         free(rcoef); 
      } 
      vcs = vcs_copy; 
      gst = gst->next; 
   } 

   vcs = vcs_copy; 
   ss = s2; 
   stmp.v = NULL; 
   stmp.c = 1; 
   while (s2 != NULL) 
   { 
      copysmonom(stmp,&stmp2); 
      mult_s(&s2->monom,&stmp2); 
      mult_s(&stmp,&s1->monom); 
      dl = s1; 
      s1 = s1->next; 
      free(dl); 
      s2 = s2->next; 
   } 
   clrvm(stmp.v); 
   revers((void **)&ss); 
   *s = ss; 
   *totf = r; 
   
} 
예제 #20
0
static int  readvars(int  check, varrec * recForGG)
{
  char      numtxt[60];
  char      name[60];
  char *    ss, * endstr;
  int       commentShift,funcShift;
  varlist   mvars;
  double    varvalue_tmp;
  linelist  ln;
  int       ggOn=0;
  
  int nv=3; /* Plus 0, i,Sqrt2 */
  recForGG->need=-1;
  ln=vars_tab.strings; while (ln) { ln=ln->next; nv++;} 
  ln=func_tab.strings; while (ln) { ln=ln->next; nv++;} 
  ln=prtcls_tab.strings; while (ln)
  { char imassname[20];
    char *p=ln->line; 
    int i;
    for(i=0;i<6;i++) p=strchr(p,'|')+1;  
    sscanf(p,"%[^|]", imassname);
    trim(imassname);
    if(imassname[0]=='!') nv++; 
    ln=ln->next;
  }  

  if(nv>SHRT_MAX){errorMessage("Name","too many parameters"); goto errExi1;}


  tabName=vars_tab.headln;
  commentShift=tabCharPos(vars_tab.format,2);

  if(modelvars) free(modelvars);

   modelvars = m_alloc(nv*sizeof(*modelvars));
   nmodelvar=0;

   strcpy(modelvars[0].varname,"0");
   modelvars[0].varvalue=0.;
   modelvars[0].func=NULL;   
   modelvars[0].need=0;
   modelvars[0].hidden=0;
   modelvars[0].pwidth=0;

   for(nLine=1,ln=vars_tab.strings; ln; nLine++, ln=ln->next)
   {  int need=0;
      ss=ln->line;

      sscanf(ss,"%[^|]%*c%[^|]", name,numtxt);

      trim(name); trim(numtxt);		
      if(name[0]=='*') {need=1; name[0]=' '; trim(name);}
      else if(name[0]=='%') continue;
       
      if (check && (!isVarName(name)) )
      {  errorMessage("Name","incorrect name '%s'",name);
         goto errExi1;
      }


      if (check &&  (! isOriginName(name)) )
      {  errorMessage("Name","duplicate name '%s'",name);   
         goto errExi1;
      }

      varvalue_tmp=strtod(trim(numtxt), &endstr);
      
      if ( ( check )&&( endstr !=numtxt+strlen(numtxt)) )
      {  errorMessage("Value","wrong number '%s'",numtxt);
	 goto errExi1;
      }


      if(strcmp(name,strongconst) == 0)  
      {
         if(ggOn)
         {  errorMessage("Name","duplicate name '%s'",name);
            goto errExi1;
         }
         ggOn=1;
         strcpy(recForGG->varname,strongconst);
         recForGG->func = NULL;
         recForGG->varvalue = varvalue_tmp;
         recForGG->need=need;
         recForGG->hidden=0;
         recForGG->pwidth=0;
         continue; 
      } 
      nmodelvar++;
      mvars=modelvars+nmodelvar; 
      strcpy(mvars->varname,name);
      mvars->varvalue=varvalue_tmp;
      mvars->func= NULL;
      mvars->need=need;
      mvars->hidden=0;
      mvars->pwidth=0;
   }

   nmodelvar++;
   mvars=modelvars+nmodelvar;
   strcpy(mvars->varname,"i");
   mvars->func = NULL;
   mvars->varvalue = 0.;
   mvars->need=0;
   mvars->hidden=0;
   mvars->pwidth=0;

   mvars++; 
   nmodelvar++;
   strcpy(mvars->varname,"Sqrt2");
   mvars->func = Sqrt2FuncTxt;
   mvars->varvalue = sqrt(2.0);
   mvars->need=0;
   mvars->hidden=1;
   mvars->pwidth=0;

   nCommonVars=0; 
  
   tabName=func_tab.headln;
   commentShift=tabCharPos(func_tab.format,2);
   funcShift=tabCharPos(func_tab.format,1);

   for(nLine = 1,ln=func_tab.strings; ln; nLine++,ln=ln->next)
   {  
      int need=0,hidden=0;
      ss=ln->line;
      sscanf(ss,"%[^|]",name);
      trim(name);
      if(name[0]=='*') {name[0]=' '; trim(name); need=1;} 
      else if(name[0]=='#') {name[0]=' '; trim(name); hidden=1;}
      else if(name[0]=='%') { if(strcmp(name,"%Local!")==0) nCommonVars=nmodelvar;  continue;}
      
      if (! isVarName(name))
      {  errorMessage("Name","incorrect name '%s'",name);
	 goto errExi1;
      }

      if ( check && (! isOriginName(name)) )
      {  errorMessage("Name","duplicate name '%s'",name);
			goto errExi1;
      }

      if(readExpression(ln->line+funcShift,rd_33, act_33,NULL)==&String) rderrcode=typemismatch;

      if(rderrcode &&(rderrcode!=unknownfunction))
      {    
	  errorMessage("Expression","*");
	  goto errExi1;
      }
      
      nmodelvar++;
      
      mvars=modelvars+nmodelvar;
      if(rderrcode==unknownfunction) varvalue_tmp=0; 
      mvars->varvalue = varvalue_tmp;
      strcpy(mvars->varname,name);
      mvars->func=ln->line+funcShift;
      mvars->need=need;
      mvars->hidden=hidden;
      mvars->pwidth=0;
   }  
   return 1;

errExi1:
   free (modelvars);
   modelvars=NULL; 
   return 0;
}
예제 #21
0
static int  testLgrgn(algvertptr lgrgn)
{
  preres  m;
  int n;
/*  goto_xy(1,20); print("%d           ",nLine); */
  m = (preres) readExpression(lgrgn->comcoef,rd_pre, act_preF,NULL);
  if (rderrcode )
  {  errorMessage("Factor","*");
    return 0;
  }
  m->free=1;

  if (m->tp >rationtp)
  {  errorMessage("Factor","scalar expected");
    return 0;
  }

  if (m->maxp>0)
  {  errorMessage("Factor","moments p%d are not permitable here",m->maxp);
    return 0;
  }

  for (n = 0; n < vardef->nvar; n++)
  { int err;
    err=findvar(vardef->vars[n].name,NULL,NULL);
    if (err)
    {  errorMessage("Factor","unknown variable '%s'", vardef->vars[n].name);
      return 0;
    }
  }
  
  clearVars(vardef);

   
  m=(preres) readExpression(lgrgn->description,rd_pre,act_pre,NULL);
  if(rderrcode) {  errorMessage("Lorentz part","*"); return 0; }
  m->free=1;
 
  if (m->tp == rationtp)
  {  errorMessage("Lorentz part","division is not permited here");  return 0; }

  if( (m->tp == spintp) &&( prtclbase1[lgrgn->fields[0]].spin&1 !=1) 
                        &&( prtclbase1[lgrgn->fields[1]].spin&1 !=1)
                        &&( prtclbase1[lgrgn->fields[2]].spin&1 !=1) )
  {
    errorMessage("Lorentz part","Dirac gamma matrix not expected");
    return 0;
  }

  if ((m->maxp == 4)&&(lgrgn->fields[3] == 0))
  {  errorMessage("Lorentz part","p4 are not permited here");
    return 0;
  }


  for (n = 0; n < vardef->nvar; n++)
  {  int err;
    err=findvar (vardef->vars[n].name,NULL,NULL);
    if (err)
    {  errorMessage("Lorentz part","unknown variable '%s'",vardef->vars[n].name);
      return 0;
    }
  }

  clearVars(vardef);


  for (n = 0; n <= 3; n++)
  {  int  ind1,ind2,np ;
     
     ind1=0;
     np  = lgrgn->fields[n];
     if ( np != 0 )   switch  (prtclbase[np-1].spin)
     { case 2: 
       case 3: ind1=1; break;
       case 4: ind1=3;
     }     
     
     ind2=0;
     if( (1<<n)& m->indlist)     ind2 += 1;
     if( (1<<(n+4))& m->indlist) ind2 += 2;
     
     if (ind1 != ind2 )
     {  errorMessage("Lorentz part","index 'm%d'  unbalanced",n+1);
        return 0;
     }
  }
  
  return 1;
}
예제 #22
0
파일: c_out.c 프로젝트: restrepo/CalcHEP
int vert_code(polyvars * vardef_ext)
{
   
//   outFile=stdout;
   labl();   
   writeF("#include<stdlib.h>\n");
   writeF("#include<math.h>\n");
   writeF("#include<complex.h>\n");                 
   
   initvararray(0,'c',vardef_ext);

   firstVar=nmodelvar;
   if(!strcmp( modelvars[firstVar].varname,strongconst))  firstVar--;

   calc_nvars_nfunc();

//   geninf(" nvar_ext",nvars);
//   geninf(" nfunc_ext",nfunc);
//   writeF(" static int nvars=%d;\n",nvars);
   
   writeF("static char*varName[%d]={\"zero\"",nvars+nfunc+1);
   sortvars();
   writeF("};\n");   

   writeF(" static double V[%d];\n",nvars+nfunc+1);
   

   writeF("static int vertexCoeff(double * coeff_out)\n{\n");

   int    l;  

        
   for(l=nCommonVars+1;l<=nmodelvar;l++)
   { 
      char *ss;
      if(vararr[l].used && ((modelvars[l].func && modelvars[l].pub==0) || modelvars[l].pwidth) )
      {  int num;
         checkNaN=0;
         if(modelvars[l].pwidth)
         {  writeF("   %s=aWidth_ext(\"%s\");\n",vararr[l].alias,
             prtclbase1[modelvars[l].pwidth].name); 
             checkNaN=1;
         } else
         {
           ss=(char *)readExpression(modelvars[l].func,rd_c,act_c,free);
/*	   writeF("   %s=%s;\n",vararr[l].alias,ss+3);*/
	   fprintf(outFile,"   %s=%s;\n",vararr[l].alias,ss+3);
	   free(ss);
	 }
	 if(checkNaN)
	 {
    	    sscanf(vararr[l].alias,"V[%d]",&num); 
            writeF("   if(!isfinite(%s)){ return %d;}\n",vararr[l].alias,num);
         }
      }
   }
   
   for(l=0;l<vardef_ext->nvar;l++) if(!strchr( vardef_ext->vars[l].name,'.'))  
         strcpy(vardef_ext->vars[l].name,vararr[vardef_ext->vars[l].num].alias);

   return nvars;
}