예제 #1
0
yylex()  /*****************Lexical analizer routine******************/
{int t,i;
 int c;
 symbol *s;
lex:
 SkipBlanks();

 if (!compfl && c != '#') { /*Ignore this line */
ignline:
   if ((int)c == EOF) return E_O_F;
   if (!GetString(symb,sizeof(symb))) {
     Error("Unclosed conditional bracket at EOF");
     return E_O_F;
   };
#if BUFFERED
   f_char= ' '; /*any char. diff. from the '\n' */
#endif
   c= '\n';
 };

 if (c == '#' && !compfl) {
   SkipBlanks();
   if (c=='i' || c=='I') goto ignline;
   UnGetChar(c);
   c= '#';
   compfl= -1;
 };

 if (c=='%') goto ignline;      /* %comment line */

 if (c=='/') {
   if ((c=GetChar())=='*') { /*Comment */
comm:
     while ((int)(c=GetChar()) != EOF && c != '*');
     if ((int)c==EOF) return E_O_F;
     while ((c=GetChar()) == '*');
     if (c != '/') goto comm;
     goto lex;     /*get the next symbol */
   };
   UnGetChar(c);
   c= '/';
 };

 if (c=='\'') {
   yylval.Num= GetChar();
   if ((c=GetChar()) != '\'') Error("' expected");
   return NUM;
 };

 if (isdigit(c)) {      /*Number */
   if (c=='0') {
     c= GetChar();
     if (c=='x' || c=='X') {    /*0xHEXALNUMBER */
       GetHexNum(&yylval.Num);
       return NUM;
     };
     if (isdigit(c)) { /*Octal number */
       UnGetChar(c);
       GetOctalNum(&yylval.Num);
       return NUM;
     };
   };
   UnGetChar(c);
   if (!isdigit(c))
     yylval.Num= 0;
   else
     GetNum(&yylval.Num);
   return NUM;
 };

 if (c=='_' || isalpha(c)) {      /*Identifier */
   register symbol *blk= blkptr;
   i= 0;
   while (c=='_' || isalnum(c)) {
     symb[i++]= c;
     c= GetChar();
   };
   UnGetChar(c);
   symb[i++]= 0;

   do {
     s= LookUp(symb,blk);
     if (!blk) break;
     blk= blk->Block;
   } while (!s);
   if (!s) {
     s= Insert(symb,SYM,0);
     if (!s) {
       Error("Symbol table is overflowed, symbol:%s",symb);
       return E_O_F;
     };
     s->Block= blkptr;
   };

   idnptr= s;
   yylval.Sym= s;
   if (s->Type == NUM) return SYM;
/**********
     yylval.Num= s->Val;
     return NUM;
   };
**********/
   return s->Type;
 };

 if ((int)c == EOF) return E_O_F;
 t= (int)c;
 if (c=='=' || c=='<' || c=='>') {
   i= GetChar();
   if (c==i)
     t= (c=='<'? SHL:
	 c=='>'? SHR: EQ);
   else
     UnGetChar(i);
 };
 yylval.Num= t;    /*Delimiter */
 return t;
}
예제 #2
0
/********************************************************************************
Update the camera
********************************************************************************/
void TPCamera::Update(double dt)
{
	// WASD movement
	if (myKeys['w'] == true)
	{
		Walk(dt);
	}
	else
	{
		MoveVel_W = 0.0f;
	}
	if (myKeys['s'] == true)
	{
		Walk(-dt);
	}
	else
	{
		MoveVel_S = 0.0f;
	}
	if (myKeys['a'] == true)
	{
		Strafe(-dt);
	}
	else
	{
		MoveVel_A = 0.0f;
	}
	if (myKeys['d'] == true)
	{
		Strafe(dt);
	}
	else
	{
		MoveVel_D = 0.0f;
	}

	// Rotation
	if (myKeys[VK_UP] == true)
	{
		LookUp(dt);
	}
	if (myKeys[VK_DOWN] == true)
	{
		LookUp(-dt);
	}
	if (myKeys[VK_LEFT] == true)
	{
		TurnLeft(-dt);
	}
	if (myKeys[VK_RIGHT] == true)
	{
		TurnRight(dt);
	}

	// Jump
	if (myKeys[32] == true)
	{
		Jump(dt);
		myKeys[32] = false;
	}
	UpdateJump(dt);

	//Update the camera direction based on mouse move
	// left-right rotate
	/*if (Application::camera_yaw != 0)
		Yaw(dt);
	if (Application::camera_pitch != 0)
		Pitch(dt);

	if (Application::IsKeyPressed('R'))
	{
		Reset();
	}*/
}
예제 #3
0
파일: regex2dfa.c 프로젝트: cran/rcqp
/** the regex parser proper: private function */
int
Parse(void)
{
  Lexical L; 
  Symbol ID = NULL; 
  int RHS; 
  
  int ignore_value;             /* ignore value of POP() macro */

  SP = Stack;
 LHS:
  /* get next symbol from the lexer */
  L = LEX();
  if (L == IdenT) 
    {
      ID = LookUp(LastW); 
      L = LEX();
      if (L == EqualT) 
        {
          PUSH(EQU, -1);
          L = LEX();
        } 
      else 
        {
          PUSH(RULE, -1);
          RHS = MakeExp(-1, SymX, ID); 
          goto END;
        }
    } 
  else 
    PUSH(RULE, -1);
 EXP:
  switch (L)   {
  case LParT:
    PUSH(PAR, -1);
    L = LEX();
    goto EXP;
  case LBrT:
    PUSH(OPT, -1);
    L = LEX();
    goto EXP;
  case ZeroT:
    RHS = MakeExp(-1, ZeroX);
    L = LEX();
    goto END;
  case OneT:
    RHS = MakeExp(-1, OneX);
    L = LEX();
    goto END;
  case IdenT:
    RHS = MakeExp(-1, SymX, LookUp(LastW));
    L = LEX();
    goto END;
  default:
    REGEX2DFA_ERROR("Corrupt expression.");
    return -1;
  }
  
 END:
  switch (Action[TOP][L])  {
  case 'A':
    REGEX2DFA_ERROR("Extra ','");
    rcqp_receive_error(1);
  case 'B':
    REGEX2DFA_ERROR("Unmatched ).");
    L = LEX();
    goto END;
  case 'C':
    REGEX2DFA_ERROR("Unmatched ].");
    L = LEX();
    goto END;
  case 'D':
    REGEX2DFA_ERROR("Unmatched (.");
    ignore_value = POP();
    goto END;
  case 'E':
    REGEX2DFA_ERROR("Unmatched [.");
    goto MakeOpt;
  case 'F':
    REGEX2DFA_ERROR("( ... ].");
    ignore_value = POP();
    L = LEX();
    goto END;
  case 'G':
    REGEX2DFA_ERROR("[ ... ).");
    L = LEX();
    goto MakeOpt;
  case 'H':
    REGEX2DFA_ERROR("Left-hand side of '=' must be symbol.");
    rcqp_receive_error(1);
  case 'I':
    REGEX2DFA_ERROR("Missing evaluation.");
    rcqp_receive_error(1);
  case '.':
    ignore_value = POP();
    return RHS;
  case ')':
    ignore_value = POP();
    L = LEX();
    goto END;
  case ']':
    L = LEX();
  MakeOpt:
    ignore_value = POP();
    RHS = MakeExp(-1, OptX, RHS);
    goto END;
  case '=':
    Store(ID, RHS);
    ignore_value = POP();
    goto LHS;
  case 'v':
    RHS = MakeExp(-1, OrX, POP(), RHS);
    goto END;
  case 'x':
    RHS = MakeExp(-1, AndX, POP(), RHS);
    goto END;
  case '*':
    RHS = MakeExp(-1, StarX, RHS);
    L = LEX();
    goto END;
  case '+':
    RHS = MakeExp(-1, PlusX, RHS);
    L = LEX();
    goto END;
  case '|':
    PUSH(OR, RHS); L = LEX();
    goto EXP;
  case '&':
    PUSH(AND, RHS);
    goto EXP;
  }

  assert(0 && "Not reached");
  return 0;
}
예제 #4
0
void ASECharacter::LookUpAtRate(float Rate)
{
   LookUp(Rate * BaseLookUpRate * GetWorld()->GetDeltaSeconds());
}
bool CFunctionCollection::EvaluatesToBinaryNumber(CString function_name) {
  COHScriptObject *p_function = LookUp(function_name);
  if (p_function == NULL) return false;
  return p_function->EvaluatesToBinaryNumber();
}
예제 #6
0
const YacasParamMatcherBase* YacasPatternPredicateBase::MakeParamMatcher(LispEnvironment& aEnvironment, LispObject* aPattern)
{
    if (!aPattern)
        return nullptr;

    if (aPattern->Number(aEnvironment.Precision()))
        return new MatchNumber(aPattern->Number(aEnvironment.Precision()));

    // Deal with atoms
    if (aPattern->String())
        return new MatchAtom(aPattern->String());

    // Else it must be a sublist
    if (aPattern->SubList())
    {
        // See if it is a variable template:
        LispPtr* sublist = aPattern->SubList();
        assert(sublist);

        LispInt num = InternalListLength(*sublist);

        // variable matcher here...
        if (num>1)
        {
            LispObject* head = (*sublist);
            if (head->String() == aEnvironment.HashTable().LookUp("_"))
            {
                LispObject* second = head->Nixed();
                if (second->String())
                {
                    LispInt index = LookUp(second->String());

                    // Make a predicate for the type, if needed
                    if (num>2)
                    {
                        LispPtr third;

                        LispObject* predicate = second->Nixed();
                        if (predicate->SubList())
                        {
                            InternalFlatCopy(third, *predicate->SubList());
                        }
                        else
                        {
                            third = (second->Nixed()->Copy());
                        }

                        LispObject* last = third;
                        while (!!last->Nixed())
                            last = last->Nixed();

                        last->Nixed() = LispAtom::New(aEnvironment, *second->String());

                        iPredicates.push_back(LispPtr(LispSubList::New(third)));
                    }
                    return new MatchVariable(index);
                }
            }
        }

        std::vector<const YacasParamMatcherBase*> matchers;
        matchers.reserve(num);
        LispIterator iter(*sublist);
        for (LispInt i = 0; i < num; ++i, ++iter) {
            matchers.push_back(MakeParamMatcher(aEnvironment,iter.getObj()));
            assert(matchers[i]);
        }
        return new MatchSubList(std::move(matchers));
    }

    return nullptr;
}
예제 #7
0
int main()
{
    int num;
    char c,Eword[30],Chinese[30];
    WORDNODE* head,*p=NULL;
	head = Create();
	p = head;
	for(num=0;p!=NULL;num++)
    {
        p = p->next;
    }
	printf("this is IDict, please input h for help\n");
	printf("please input your command here\n");
    while(1)
    {   c=getchar();
        while(getchar()!='\n');
		if(c=='H' || c=='h')
		{
			printf("a for add a word\n");
			printf("d for delete a word\n");
			printf("c for change a word\n");
			printf("s for search a word\n");
			printf("q for quit the programme\n");
		}
		else if(c=='Q' || c=='q')
		{
			break;
		}
		else if(c=='A' || c=='a')
		{
			printf("please input word\n");
			scanf("%s",Eword);
			printf("please input Chinese\n");
			scanf("%s",Chinese);
			Add(head,Eword,Chinese);
		}
		else if(c=='C' || c=='c')
		{
		    printf("please input the word you want to change\n");
		    scanf("%s",Eword);
		    Delete(head,Eword);
			printf("please input word\n");
			scanf("%s",Eword);
			printf("please input Chinese\n");
			scanf("%s",Chinese);
			Add(head,Eword,Chinese);
		}
		else if(c=='D' || c=='d')
		{
			printf("please input word\n");
			scanf("%s",Eword);
			Delete(head,Eword);
		}
		else if(c=='S' || c=='s')
		{
			printf("please input search word pattern\n");
			scanf("%s",Eword);
			LookUp(head,Eword);
		}
		else if(c=='W' || c=='w')
        {
            MemWord(head,num);
        }
        else if(c=='R' || c=='r')
        {
            Review();
        }
		else
		{
			printf("error command, please type h for help\n");
		}
	}
	return 0;
}