示例#1
0
void constDefinitions (void) {

	//-------------------------------------------------------
	// Loop to process definitions separated by semicolons...
	while (curToken == TKN_IDENTIFIER) {
		SymTableNodePtr constantIdPtr;
		searchAndEnterLocalSymTable(constantIdPtr);
		constantIdPtr->defn.key = DFN_CONST;
		constantIdPtr->library = CurLibrary;

		getToken();
		ifTokenGetElseError(TKN_EQUAL, ABL_ERR_SYNTAX_MISSING_EQUAL);

		doConst(constantIdPtr);
		analyzeConstDefn(constantIdPtr);

		//---------------------------------
		// Error synchronize: should be a ;
		synchronize(followDeclarationList, declarationStartList, statementStartList);
		if (curToken == TKN_SEMICOLON)
			getToken();
		else if (tokenIn(declarationStartList) || tokenIn(statementStartList))
			syntaxError(ABL_ERR_SYNTAX_MISSING_SEMICOLON);
	}
}
varInst *Mission::checkExpression(missionNode *node,int mode){

  varInst *ret=NULL;
  debug(3,node,mode,"checking expression");
  //  printRuntime();

  switch(node->tag){
  case DTAG_AND_EXPR:
  case DTAG_OR_EXPR:
  case DTAG_NOT_EXPR:
  case DTAG_TEST_EXPR:
    {
    bool res=checkBoolExpr(node,mode);
    ret=newVarInst(VI_TEMP);
    ret->type=VAR_BOOL;
    ret->bool_val=res;
    return ret;
    }
    break;
  case DTAG_CONST:
    {
    ret=doConst(node,mode);
    return ret;
    }
    break;
  case DTAG_VAR_EXPR:
    {
    ret=doVariable(node,mode);
    return ret;
    }
    break;
  case DTAG_FMATH:
    {
    ret=doMath(node,mode);
    return ret;
    }
    break;
  case DTAG_CALL:
    {
    ret=doCall(node,mode);
    return ret;
    }
    break;
  case DTAG_EXEC:
    {
    ret=doExec(node,mode);
    return ret;
    }
    break;
  default:
    fatalError(node,mode,"no such expression");
    assert(0);
    break;
  }
  return ret;
}
int Mission::checkIntExpr(missionNode *node,int mode){
  int res=0;

    if(node->tag==DTAG_VAR_EXPR){
      res=doIntVar(node,mode);
    }
    else if(node->tag==DTAG_FMATH){
      res=doIMath(node,mode);
    }
    else if(node->tag==DTAG_CONST){
      varInst *vi=doConst(node,mode);
      if(vi && vi->type==VAR_INT){
	res=vi->int_val;
      }
      else{
	fatalError(node,mode,"expected a float const, got a different one");
	assert(0);
      }
      deleteVarInst(vi);
    }
    else if(node->tag==DTAG_CALL){
      varInst *vi=doCall(node,mode);
      if(vi->type==VAR_INT){ 
	res=vi->int_val;
      }
      else if(vi->type==VAR_ANY && mode==SCRIPT_PARSE){
	res=vi->int_val;
      }
      else{
	fatalError(node,mode,"expected a int call, got a different one");
	assert(0);
      }
      deleteVarInst(vi);
    }
    else if(node->tag==DTAG_EXEC){
      varInst *vi=doExec(node,mode);
      if(vi==NULL){
	fatalError(node,mode,"doExec returned NULL");
	assert(0);
      }
      else if(node->script.vartype==VAR_INT){
	res=vi->int_val;
      }
      else{
	fatalError(node,mode,"expected a int exec, got a different one");
	assert(0);
      }
      deleteVarInst(vi);
    }
    else{
      fatalError(node,mode,"no such int expression tag");
      assert(0);
    }

    return res;
}
varInst *Mission::checkObjectExpr(missionNode *node,int mode){
  varInst *res=NULL;

  if(node->tag==DTAG_VAR_EXPR){
      res=doObjectVar(node,mode);
    }
    else if(node->tag==DTAG_CALL){
      varInst *vi=doCall(node,mode);
      if(vi->type==VAR_OBJECT){
	res=vi;
      }
      else if(vi->type==VAR_ANY && mode==SCRIPT_PARSE){
	res=vi;
      }
      else{
	fatalError(node,mode,"expected a object call, got a different one");
	assert(0);
      }
    }
    else if(node->tag==DTAG_EXEC){
      varInst *vi=doExec(node,mode);
      if(vi==NULL){
	fatalError(node,mode,"doExec returned NULL");
	assert(0);
      }
      else if(node->script.vartype==VAR_OBJECT){
	res=vi;
      }
      else{
	fatalError(node,mode,"expected a object exec, got a different one");
	assert(0);
      }
    }
    else if(node->tag==DTAG_CONST){
      varInst *vi=doConst(node,mode);
      if(vi->type==VAR_OBJECT && vi->objectname=="string"){
	res=vi;
      }
      else{
	fatalError(node,mode,"expected a string const, got a different one: "+vi->objectname);
	assert(0);
      }
    }
 
    else{
      fatalError(node,mode,"no such object expression tag");
      assert(0);
    }

    return res;

}
bool Mission::checkBoolExpr(missionNode *node,int mode){
  bool ok;

  // no difference between parse/run

    if(node->tag==DTAG_AND_EXPR){
      ok=doAndOr(node,mode);
    }
    else if(node->tag==DTAG_OR_EXPR){
      ok=doAndOr(node,mode);
    }
    else if(node->tag==DTAG_NOT_EXPR){
      ok=doNot(node,mode);
    }
    else if(node->tag==DTAG_TEST_EXPR){
      ok=doTest(node,mode);
    }
    else if(node->tag==DTAG_VAR_EXPR){
      ok=doBooleanVar(node,mode);
    }
    else if(node->tag==DTAG_CONST){
      varInst *vi=doConst(node,mode);
      if(vi->type==VAR_BOOL){
	ok=vi->bool_val;
      }
      else{
	fatalError(node,mode,"expected a bool const, got a different one");
	assert(0);
      }
      deleteVarInst(vi);
    }
    else if(node->tag==DTAG_CALL){
      varInst *vi=doCall(node,mode);
      if(vi->type==VAR_BOOL){
	ok=vi->bool_val;
      }
      else if(vi->type==VAR_ANY && mode==SCRIPT_PARSE){
	ok=vi->bool_val;
      }
      else{
	fatalError(node,mode,"expected a bool call, got a different one");
	assert(0);
      }
      deleteVarInst(vi);
    }

    else if(node->tag==DTAG_EXEC){
      varInst *vi=doExec(node,mode);
      if(vi==NULL){
	fatalError(node,mode,"doExec returned NULL");
	assert(0);
 	// parsing?
      }
      else if(node->script.vartype==VAR_BOOL){
	ok=vi->bool_val;
      }
      else{
	fatalError(node,mode,"expected a bool exec, got a different one");
	assert(0);
      }
      deleteVarInst(vi);
    }


    else{
      fatalError(node,mode,"no such boolean expression tag");
      assert(0);
    }

    return ok;
}