コード例 #1
0
ファイル: Expression.cpp プロジェクト: BlackYoup/medusa
int Expression::parse( const char * pParse )
{
	release();

	const char * pStart = pParse;
	const char * pEnd = pStart + strlen( pParse );
	while( *pParse && pParse < pEnd )
	{
		// skip whitespaces
		if( *pParse && isspace( *pParse ) )
		{ 
			pParse++;
			continue;
		}
		
		Token token;
		token.nType = TOKEN_ERROR;

		char ch = *pParse++;
		if ( IsSymbol( ch ) )
		{
			token.nType = TOKEN_SYMBOL;
			token.sToken += ch;

			while( IsSymbol( *pParse ) )
				token.sToken += *pParse++;
		}
		else 
		{
			for(unsigned int i=0;i<sizeof(TOKENS)/sizeof(TOKENS[0]);i++)
			{
				if ( TOKENS[i].cBegin == ch )
				{
					token.nType = TOKENS[i].nType;
					if ( TOKENS[i].cEnd != 0 )
						pParse = CopyToken( pParse, TOKENS[i].cEnd, token );
					break;
				}
			}
		}

		// push the new token
		m_Tokens.push( token );
	}

	return (int)m_Tokens.size();
}
コード例 #2
0
ファイル: commline.c プロジェクト: guitarpoet/php-clips
const char *GetCommandCompletionString(
  void *theEnv,
  const char *theString,
  size_t maxPosition)
  {
   struct token lastToken;
   struct token theToken;
   char lastChar;
   const char *rs;
   size_t length;

   /*=========================*/
   /* Get the command string. */
   /*=========================*/

   if (theString == NULL) return("");

   /*=========================================================================*/
   /* If the last character in the command string is a space, character       */
   /* return, or quotation mark, then the command completion can be anything. */
   /*=========================================================================*/

   lastChar = theString[maxPosition - 1];
   if ((lastChar == ' ') || (lastChar == '"') ||
       (lastChar == '\t') || (lastChar == '\f') ||
       (lastChar == '\n') || (lastChar == '\r'))
     { return(""); }

   /*============================================*/
   /* Find the last token in the command string. */
   /*============================================*/

   OpenTextSource(theEnv,"CommandCompletion",theString,0,maxPosition);
   ScannerData(theEnv)->IgnoreCompletionErrors = true;
   GetToken(theEnv,"CommandCompletion",&theToken);
   CopyToken(&lastToken,&theToken);
   while (theToken.type != STOP)
     {
      CopyToken(&lastToken,&theToken);
      GetToken(theEnv,"CommandCompletion",&theToken);
     }
   CloseStringSource(theEnv,"CommandCompletion");
   ScannerData(theEnv)->IgnoreCompletionErrors = false;

   /*===============================================*/
   /* Determine if the last token can be completed. */
   /*===============================================*/

   if (lastToken.type == SYMBOL)
     {
      rs = ValueToString(lastToken.value);
      if (rs[0] == '[') return (&rs[1]);
      return(ValueToString(lastToken.value));
     }
   else if (lastToken.type == SF_VARIABLE)
     { return(ValueToString(lastToken.value)); }
   else if (lastToken.type == MF_VARIABLE)
     { return(ValueToString(lastToken.value)); }
   else if ((lastToken.type == GBL_VARIABLE) || (lastToken.type == MF_GBL_VARIABLE) ||
            (lastToken.type == INSTANCE_NAME))
     { return(NULL); }
   else if (lastToken.type == STRING)
     {
      length = strlen(ValueToString(lastToken.value));
      return(GetCommandCompletionString(theEnv,ValueToString(lastToken.value),length));
     }
   else if ((lastToken.type == FLOAT) || (lastToken.type == INTEGER))
     { return(NULL); }

   return("");
  }
コード例 #3
0
ファイル: rulelhs.c プロジェクト: RobotJustina/JUSTINA
static struct lhsParseNode *LHSPattern(
  void *theEnv,
  char *readSource,
  int terminator,
  char *terminatorString,
  int *error,
  int allowDeclaration,
  struct token *firstToken,
  char *ruleName)
  {
   struct token theToken;
   struct lhsParseNode *theNode;

   /*=========================================================*/
   /* Check to see if the first token has already been read.  */
   /* This should only occur for the first pattern in a rule. */
   /*=========================================================*/

   if (firstToken == NULL) GetToken(theEnv,readSource,&theToken);
   else CopyToken(&theToken,firstToken);

   /*=====================================================*/
   /* A left parenthesis begins all CEs and declarations. */
   /*=====================================================*/

   if (theToken.type == LPAREN)
     {
      /*================================================*/
      /* The first field of a pattern must be a symbol. */
      /*================================================*/

      GetToken(theEnv,readSource,&theToken);
      if (theToken.type != SYMBOL)
        {
         SyntaxErrorMessage(theEnv,"the first field of a pattern");
         *error = TRUE;
         return(NULL);
        }

      /*====================================*/
      /* If this is the first CE of a rule, */
      /* then a declare statement is valid. */
      /*====================================*/

      if (allowDeclaration &&
          (strcmp(ValueToString(theToken.value),"declare") == 0))
        {
         if (ruleName == NULL) SystemError(theEnv,"RULELHS",1);
         DeclarationParse(theEnv,readSource,ruleName,error);
         theNode = NULL;
        }

      /*==================================*/
      /* Otherwise check for a *test* CE. */
      /*==================================*/

      else if (strcmp(ValueToString(theToken.value),"test") == 0)
        { theNode = TestPattern(theEnv,readSource,error); }

      /*============================================*/
      /* Otherwise check for an *and*, *or*, *not*, */
      /* *logical*, *exists*, or *forall* CE.       */
      /*============================================*/

      else if ((strcmp(ValueToString(theToken.value),"and") == 0) ||
               (strcmp(ValueToString(theToken.value),"logical") == 0) ||
               (strcmp(ValueToString(theToken.value),"not") == 0) ||
               (strcmp(ValueToString(theToken.value),"exists") == 0) ||
               (strcmp(ValueToString(theToken.value),"forall") == 0) ||
               (strcmp(ValueToString(theToken.value),"or") == 0))
        { theNode = ConnectedPatternParse(theEnv,readSource,&theToken,error); }

      /*=================================*/
      /* Otherwise parse a *pattern* CE. */
      /*=================================*/

      else
        { theNode = SimplePatternParse(theEnv,readSource,&theToken,error); }
     }

   /*=======================================*/
   /* Check for a pattern address variable. */
   /*=======================================*/

   else if (theToken.type == SF_VARIABLE)
     { theNode = AssignmentParse(theEnv,readSource,(SYMBOL_HN *) theToken.value,error); }

   /*=================================================*/
   /* Check for the group terminator (either a "=>"   */
   /* separating the LHS from the RHS or a ")" ending */
   /* a CE containing other CEs such as an *and* CE). */
   /*=================================================*/

   else if ((theToken.type == terminator) ?
            (strcmp(theToken.printForm,terminatorString) == 0) : FALSE)
     { return(NULL);  }

   /*====================================*/
   /* Otherwise invalid syntax was used. */
   /*====================================*/

   else
     {
      SyntaxErrorMessage(theEnv,"defrule");
      *error = TRUE;
      return(NULL);
     }

   /*================================*/
   /* If an error occurred, free any */
   /* allocated data structures.     */
   /*================================*/

   if (*error == TRUE)
     {
      ReturnLHSParseNodes(theEnv,theNode);
      return(NULL);
     }

   /*=========================*/
   /* Return the LHS pattern. */
   /*=========================*/

   return(theNode);
  }
コード例 #4
0
ファイル: rcl.c プロジェクト: mingpen/OpenNT
int LitChar()
{
    static int  fNewLine = TRUE;
    int fIgnore = FALSE;
    int fBackSlash = FALSE;
    int fDot;
    PWCHAR      pch;
    WCHAR buf[ _MAX_PATH ];
    TOKEN token_save;

    for (; ; ) {
        switch (curChar = (WCHAR)FileChar()) {
        case 0:
	    curChar = EOFMARK;
	    goto char_return;

        case 0xFEFF:     // skip Byte Order Mark
            continue;

        case SYMDEFSTART:
        {
            int fNewLineSave = fNewLine;
            GetSymbolDef(TRUE, curChar);
            fNewLine = fNewLineSave;
            break;
        }

        case CHCARRIAGE:
            curChar = CHSPACE;
            if (!fIgnore)
                goto char_return;
            break;

        case CHNEWLINE:
            fNewLine = TRUE;
            curLin++;
            {
                static long lTotalLin = 0;
                if ((lTotalLin++ & RC_COMPILE_UPDATE) == 0)
                    UpdateStatus(2, lTotalLin);
            }

            if (!fIgnore)
                goto char_return;
            break;

            /* skip whitespace before #line - don't clear fNewLine */
        case CHSPACE:
        case CHTAB:
            if (!fIgnore)
                goto char_return;
            break;

        case CHDIRECTIVE:
            if (fNewLine) {
		        TCHAR tch;

                fDot = FALSE;

                /* also, leave fNewLine set, since we read thru \n */

                /* read the 'line' part */
                if ((tch = FileChar()) != L'l') {
		    if (tch == L'p') {
			if (FileChar() != L'r')
			    goto DirectiveError;
			if (FileChar() != L'a')
			    goto DirectiveError;
			if (FileChar() != L'g')
			    goto DirectiveError;
			if (FileChar() != L'm')
			    goto DirectiveError;
			if (FileChar() != L'a')
			    goto DirectiveError;

			/*
			** This is very specific, as any #pragma will
			** be a code_page pragma written by p0prepro.c.
			*/
            CopyToken( &token_save, &token );

			GetToken(FALSE);		/* get #pragma and ignore */
			GetToken(FALSE);		/* get code_page and ignore */
			GetToken(TOKEN_NOEXPRESSION);	/* get codepage value only*/
							/* don't check return value */
			uiCodePage = token.val;		/* assume ok */
			/* read through end of line */
			while (curChar != CHNEWLINE)
			{
			    curChar = (WCHAR)FileChar();
			}
            CopyToken( &token, &token_save );
			continue;
		    }
		    else
			goto DirectiveError;
		}
                if (FileChar() != L'i')
                    goto DirectiveError;
                if (FileChar() != L'n')
                    goto DirectiveError;
                if (FileChar() != L'e')
                    goto DirectiveError;

                /* up to filename, grabbing line number as we go */
                /* note that curChar first contains '#', because */
                /* we don't read a new character into curChar */
                curLin = 0;
                do {
                    if (curChar >= L'0' && curChar <= L'9') {
                        curLin *= 10;
                        curLin += curChar - L'0';
                    }
                    curChar = (WCHAR)FileChar();
                } while (curChar != CHQUOTE && curChar != CHNEWLINE);

                /* don't change curFile or fIgnore if this is just a
                 * #line <lineno>
                 */
                if (curChar == CHNEWLINE)
                    break;

                /* read the filename.  detect the presence of .c or .h */
                pch = buf;
                do {
                    curChar = (WCHAR)FileChar();
                    switch (towlower(curChar)) {

                        /* treat backslash like normal char, set flag. */
                    case L'\\':
                        if (fBackSlash) {
                            fBackSlash = FALSE;
                        }
                        else {
                            fBackSlash = TRUE;
                            fIgnore = FALSE;
                            fDot = FALSE;
                            *pch++ = curChar;
                        }
                        break;

                        /* line format sanity check: no embedded newlines */
                    case CHNEWLINE:
                    case 0:
DirectiveError:
                        LexError1(2101);

                        /* stop reading filename when we hit a quote */
                    case CHQUOTE:
                        break;

                        /* if we see a ., prepare to find extension */
                    case CHEXTENSION:
                        fBackSlash = FALSE;
                        fDot = TRUE;
                        *pch++ = curChar;
                        break;

                        /* if there's a C or H after a '.', its not RCINCLUDE'd */
                    case CHCSOURCE:
                    case CHCHEADER:
                        fBackSlash = FALSE;
                        fIgnore = fDot;
                        fDot = FALSE;
                        *pch++ = curChar;
                        break;

                        /* any other character in a file means the next character
                        won't be after a dot, and the last char up to now
                        wasn't C or H.
                        */

                    default:
                        fIgnore = FALSE;
                        fDot = FALSE;
                        *pch++ = curChar;
                        break;

                    }
                } while (curChar != CHQUOTE);
                *pch = 0;
                WideCharToMultiByte(uiCodePage, 0, buf, -1, curFile, _MAX_PATH, NULL, NULL);

                /* read through end of line */
                do {
                    curChar = (WCHAR)FileChar();
                } while (curChar != CHNEWLINE);

                break;
            }
            /* else, fall through, treat like normal char */

        default:
            fNewLine = FALSE;
            if (!fIgnore)
                goto char_return;
        }
    }

char_return:
    if (bExternParse)
	*((WCHAR*) GetSpace(sizeof(WCHAR))) = curChar;

    return curChar;
}