Example #1
0
static WicErrors scanStr(pTokData tokData)
{
    char charVal;
    WicErrors retVal = ERR_NONE;

    for( ;; ) {
        if (NEXT_CHAR == '\n' || NEXT_CHAR == (char) EOF) {
            retVal = RERR_INV_STRING_CONST;
            break;
        }
        if( NEXT_CHAR == '\"' ) {
            getNextChar();
            break;
        }

        if( NEXT_CHAR == '\\' ) {
            getNextChar();
            charVal = scanESCChar();
        } else {
            charVal = NEXT_CHAR;
            getNextChar();
        }
        pushChar(charVal);
    }

    if (retVal == ERR_NONE) {
        tokData->code = Y_STRING;
        tokData->repr.s.s = wicMalloc(currTokLen);
        memcpy(tokData->repr.s.s, currTok, currTokLen);
        tokData->repr.s.strLen = currTokLen;
    }
    return( retVal );
}
Example #2
0
void CodeCleaner::clean(std::ifstream& inputFile, std::ostream& outputFile)
{
    //Holds the character the push char function returns
    char c;
    
    //Keeps cleaning until the end of the file has been reached
    while(!inputFile.eof())
    {
        //Pushes the character into the buffer
        c = pushChar(inputFile.get());
        
        //If the buffer returned a null terminator don't print it
        if(c != '\0') outputFile << c;
    }
    
    //Determine what to do with the last characters left in the buffer
    if(isSingleLine)
    {
        int index;
        for(index = 0; index < bufferSize; index++)
            if(charBuffer[index] == '\n') break;
        
        while(index < bufferSize)
            outputFile << charBuffer[index];
    }
}
Example #3
0
static String	norme_string(t_char *cur, int pos, String output)
{
  int		ite;

  ite = 0;
  while (cur != NULL && cur->next != NULL && ite < pos)
    {
      cur = cur->next;
      ite++;
    }
  if (cur == NULL)
    {
      if ((output->data = pushChar(output->data, '\0')) == NULL)
	return (NULL);
      return (output);
    }
  while (cur != NULL)
    {
      if ((output->data = pushChar(output->data, cur->c)) == NULL)
	return (NULL);
      cur = cur->next;
    }
  return (output);
}
Example #4
0
// QC:G
int SDLInit::filterEvents(const SDL_Event *event) {

	if((event->type == SDL_QUIT) || (event->type == SDL_KEYDOWN && event->key.keysym.sym == SDLK_ESCAPE)) {
		windowClosed = true;
		return 0;
	}

	if(textInEnabled && event->type == SDL_KEYDOWN) {
		if(event->key.keysym.sym != 0 || (event->key.keysym.sym >= 32 && event->key.keysym.sym <= 127)) {
			pushChar(event->key.keysym.unicode);
		}

		return 0;
	}

	return 1;
}
 NormalizeCharMapPtr MappingCharFilter::match(NormalizeCharMapPtr map)
 {
     NormalizeCharMapPtr result;
     if (map->submap)
     {
         int32_t chr = nextChar();
         if (chr != -1)
         {
             NormalizeCharMapPtr subMap(map->submap.get((wchar_t)chr));
             if (subMap)
                 result = match(subMap);
             if (!result)
                 pushChar(chr);
         }
     }
     if (!result)
         result = map;
     return result;
 }
int main()
{
	int i, j, len, a, b;
	char *src = "6*(5+(2+3)*8+3)";
	char des[255];
	Stack S;

	S = createStack();
	if (S == NULL) {
		printf_s("Error\n");
		return 1;
	}

	i = len = 0;
	while (src[i++] != '\0')
		len++;

	/* 将中缀转换为后缀 */
	for (i = j = 0; i < len; i++) {
		if (isSymbol(src[i])) {
			if (src[i] != ')') {
				if (isEmpty(S))
					pushChar(src[i], S);
				else if (pricmp(src[i], topChar(S)) > 0)
					pushChar(src[i], S);                      
				else {
					while (!isEmpty(S) && pricmp(src[i], topChar(S)) <= 0) {
						des[j++] = topChar(S);
						pop(S);
					}
					pushChar(src[i], S);
				}
			}
			else if (src[i] == ')') {
				while (topChar(S) != '(' && !isEmpty(S)) {
					des[j++] = topChar(S);
					pop(S);
				}
				pop(S);
			}
		}
		else {
			des[j++] = src[i];
		}
	}
	/* 将栈里的剩余符号弹出 */
	while (!isEmpty(S)) {
		des[j++] = topChar(S);
		pop(S);
	}
	des[j--] = '\0';
	printf("%s\n", des);
	/* 转换结束 */
	
	/* 用后缀表达式完成计算 */
	i = len = 0;
	while (des[i++] != '\0')
		len++;

	for (i = 0; i < len; i++) {
		if (!isSymbol(des[i]))
			pushInt(des[i] - 48, S);
		else {
			a = topInt(S);
			pop(S);
			b = topInt(S);
			pop(S);
			//printf_s("\na=%d, b=%d\n", a, b);
			switch (des[i]) {
			case '+':
				pushInt(a + b, S);
				break;
			case '-':
				pushInt(a - b, S);
				break;
			case '*':
				pushInt(a*b, S);
				break;
			case '/':
				pushInt(a / b, S);
				break;
			}
		}
	}
	printf_s("Result=%d\n", topInt(S));
	return 0;
}
Example #7
0
void pushGetNextChar(void)
{
    pushChar(NEXT_CHAR);
    getNextChar();
}
int infixToPostfix(const char from[], char to[])
{
    CharStack *stack = createCharStack();

    int c = EOF;
    int i = 0;
    int j = 0;
    while (true)
    {
        c = from[i];
        ++i;
        if (c == '\0')
            break;
        switch (c)
        {
            case '1': case '2': case '3': case '4': case '5':
            case '6': case '7': case '8': case '9': case '0':
            {
                to[j] = c;
                ++j;
                break;
            }
            case '(':
            {
                pushChar(stack, '(');
                break;
            }
            case ')':
            {
                while ((c = popChar(stack)) != '(' && c != EOF)
                {
                    to[j] = c;
                    ++j;
                }
                if (c == EOF)
                {
                    deleteCharStack(stack);
                    to[j] = '\0';
                    return 1;
                }
                break;
            }
            case '+': case '-': case '*': case '/':
            {
                int c1 = EOF;
                while ((c1 = popChar(stack)) != EOF && c1 != '(' && priority(c) <= priority(c1))
                {
                    to[j] = c1;
                    ++j;
                }
                if (c1 != EOF)
                    pushChar(stack, c1);
                pushChar(stack, c);
                break;
            }
            default:
            {
                deleteCharStack(stack);
                to[j] = '\0';
                return 2;
            }
        } //switch
    } //while
    while ((c = popChar(stack)) != EOF && c != '(')
    {
        to[j] = c;
        ++j;
    }
    deleteCharStack(stack);
    to[j] = '\0';
    if (c == '(')
        return 1;
    return 0;
}
void receiveTask(void* pdata) {
	char byte = '1';
	INT8U err;
	PacketBuffer pb;
	init(&pb);
	LenBuffer* buf;

	printf("ReceiveTask :: started!\n");
	while(1) {
		byte = (char) OSQPend(byteQueue, 0, &err);

		if(byte != START_BYTE && byte != END_BYTE) {
			if(byte == 'f') {
				charRecv = 0x2;
			} else if(byte == 'b') {
				charRecv = 0x2;
			} else if(byte == 'l') {
				charRecv = 0x2;
			} else if(byte == 'r') {
				charRecv = 0x2;
			} else if(byte == 's') {
				charRecv = 0x0;
			} else {
				charRecv = 0;
			}
			IOWR_8DIRECT(PIO_LEDS_BASE, 0, charInter | charRecv | curCommand | (sendCount << 4));
		}
		if(err != OS_NO_ERR) {
			printf("ReceiveTask :: ERROR: %i", err);
			charRecv = 0x0;
			IOWR_8DIRECT(PIO_LEDS_BASE, 0, charInter | charRecv | curCommand | (sendCount << 4));
			continue;
		}
		printf("ReceiveTask :: Received: %i\n", byte);
		if(byte == START_BYTE) {
			clear(&pb);
			pb.isStarted = 1;
		} else if(byte == END_BYTE) {
			if(pb.isStarted) {
				// We have to malloc this because it's
				buf = (LenBuffer*) malloc(sizeof(LenBuffer));
				buf->buf = (char*) malloc(BUF_SIZE * sizeof(char));
				memset(buf->buf, 0, BUF_SIZE);
				buf->len = mRead(&pb, buf->buf);
				pb.isStarted = 0;

				OSQPost(receiveQueue, (void*) buf);
			}

		} else {
			if(pb.isStarted) {
				if(pushChar(&pb, byte)) {
//					printf("ReceiveTask :: %i\n", byte);
				} else {
//					printf("ReceiveTask :: No room in buffer!\n");
				}
			} else {
//				printf("ReceiveTask :: %i - discarded\n", byte);
			}
		}
	}
}
Example #10
0
void _getTokens(const char* s, struct char_char* p, struct token_info* info)
{
    char urlMode = 0, blockMode = 0;
    int tn = 0, ln = 0;
    size_t pos = 0, slen = strlen(s);

    for(; pos < slen; pos++)
    {
        char c = s[pos];
        char cn = s[pos+1];

        if(c == '/' && cn == '*')
        {
            parseMLComment(info, &tn, ln, s, slen, &pos);
        }
        else if (!urlMode && c == '/' && s[pos+5] == '/' && cn == 'd' && s[pos+2] == 'e' && s[pos+3] == 'e' && s[pos+4] == 'p') {
            pushToken(info, &tn, ln, TOKENTYPE_DEEP, "/deep/");
            pos += 5;
        }
        else if(!urlMode && c == '/' && cn == '/')
        {
            if(blockMode > 0)
            {
                parseIdentifier(info, &tn, ln, s, slen, &pos, &urlMode, p);
            }
            else
            {
                parseSLComment(info, &tn, ln, s, slen, &pos);
            }
        }
        else if(c == '"' || c == '\'')
        {
            parseString(info, &tn, ln, s, slen, &pos, c);
        }
        else if(c == ' ')
        {
            parseSpaces(info, &tn, ln, s, slen, &pos);
        }
        else if(isPunctuation(p, c))
        {
            pushChar(info, &tn, ln, isPunctuation(p, c), c);
            if(c == '\n' || c == '\r')
            {
                ln++;
            }

            if(c == ')')
            {
                urlMode = 0;
            }

            if(c == '{')
            {
                blockMode++;
            }

            if(c == '}')
            {
                blockMode--;
            }
        }
        else if(isDecimalDigit(c))
        {
            parseDecimalNumber(info, &tn, ln, s, slen, &pos);
        }
        else
        {
            parseIdentifier(info, &tn, ln, s, slen, &pos, &urlMode, p);
        }
    }
}