Exemplo n.º 1
0
        empty_calc::Token get( int& v )
        {
                int c;
                do {
                        c = getc();
                } while( isspace( c ) );

                // 記号類
                switch( c ) {
                case '+': return empty_calc::token_Add;
                case '-': return empty_calc::token_Sub;
                case '*': return empty_calc::token_Mul;
                case '/': return empty_calc::token_Div;
                case EOF: return empty_calc::token_eof;
                }

                // 整数
                if( isdigit( c ) ) {
                        int n = 0;
                        while( c != EOF && isdigit( c ) ) {
                                n *= 10;
                                n += c - '0';
                                c = getc();
                        }
                        ungetc( c );
                        v = n;
                        return empty_calc::token_Number;
                }


                std::cerr << char(c) << std::endl;
                throw unexpected_char();
        }
Exemplo n.º 2
0
static gboolean handle_char(struct sfz_parser_state *state, int ch)
{
    if (isalpha(ch) || isdigit(ch))
    {
        state->key_start = state->pos - 1;
        state->handler = handle_key;
        return TRUE;
    }
    switch(ch)
    {
    case '_':
        return TRUE;
        
    case '\r':
    case '\n':
    case ' ':
    case '\t':
    case -1:
        return TRUE;
    case '<':
        state->token_start = state->pos;
        state->handler = handle_header;
        return TRUE;
    default:
        unexpected_char(state, ch);
        return FALSE;
    }
}
Exemplo n.º 3
0
void baconian_decrypt(FILE *input)
{
	int c;
	int _c;
	int i;
	int value[BITS];

	while ((c = fgetc(input)) != EOF) {
		_c = c;

		if (isalpha(c)) {
			c = toupper(c);

			if (!OKCHAR(c))
				unexpected_char(_c);

			value[BITS - 1] = (c == 'A') ? 0 : 1;

			for (i = BITS - 2; i >= 0; i--) {
				c = fgetc(input);

				if (c == EOF) {
					fprintf(stderr, "unexpected end of input\n");
					exit(1);
				}

				_c = c;

				if (isalpha(c)) {
					c = toupper(c);

					if (!OKCHAR(c))
						unexpected_char(_c);

					value[i] = (c == 'A') ? 0 : 1;
				}
				else {
					unexpected_char(_c);
				}
			}

			c = 'A' + decrypt_value(value);
		}

		fputc(c, stdout);
	}
}
Exemplo n.º 4
0
void
eat_nl(void)			/* eat all space including newlines */
{
    while (1) {
	switch (scan_code[(UChar) next()]) {
	case SC_COMMENT:
	    eat_comment();
	    break;

	case SC_NL:
	    lineno++;
	    /* FALLTHRU  */

	case SC_SPACE:
	    break;

	case SC_ESCAPE:
	    /* bug fix - surprised anyone did this,
	       a csh user with backslash dyslexia.(Not a joke)
	     */
	    {
		int c;

		while (scan_code[NextUChar(c)] == SC_SPACE) {
		    ;		/* empty */
		}
		if (c == '\n')
		    token_lineno = ++lineno;
		else if (c == 0) {
		    un_next();
		    return;
		} else {	/* error */
		    un_next();
		    /* can't un_next() twice so deal with it */
		    yylval.ival = '\\';
		    unexpected_char();
		    if (++compile_error_count == MAX_COMPILE_ERRORS)
			mawk_exit(2);
		    return;
		}
	    }
	    break;

	default:
	    un_next();
	    return;
	}
    }
}
Exemplo n.º 5
0
static gboolean handle_header(struct sfz_parser_state *state, int ch)
{
    if (ch >= 'a' && ch <= 'z')
        return TRUE;
    if (ch == '>')
    {
        char *token = g_strndup(state->buf + state->token_start, state->pos - 1 - state->token_start);
        gboolean result = state->client->token(state->client, token, state->error);
        g_free(token);
        state->handler = handle_char;
        return result;
    }
    unexpected_char(state, ch);
    return FALSE;
}
Exemplo n.º 6
0
static gboolean handle_key(struct sfz_parser_state *state, int ch)
{
    if (isalpha(ch) || isdigit(ch) || ch == '_')
        return TRUE;
    if(ch == '=')
    {
        state->key_end = state->pos - 1;
        scan_for_value(state);
        
        gchar *key = g_strndup(state->buf + state->key_start, state->key_end - state->key_start);
        gchar *value = g_strndup(state->buf + state->value_start, state->value_end - state->value_start);
        gboolean result = state->client->key_value(state->client, key, value);
        g_free(key);
        g_free(value);
        state->handler = handle_char;
        return result;
    }
    unexpected_char(state, ch);
    return FALSE;
}
Exemplo n.º 7
0
    list::Token get(int& v) {
        int c;
        do {
            c = getc();
        } while (isspace(c));

        // 記号類
        if (c == eof()) {
            return list::token_eof;
        } else {
            v = c;
            switch (c) {
                case '(': return list::token_LParen;
                case ')': return list::token_RParen;
                case ',': return list::token_Comma;
                case '*': return list::token_Star;
            }
        }

        // 整数
        if (isdigit(c)) {
            int n = 0;
            while (c != eof()&& isdigit(c)) {
                n *= 10;
                n += c - '0';
                c = getc();
            }
            ungetc(c);
            v = n;
            return list::token_Number;
        }


        std::cerr << char(c) << std::endl;
        throw unexpected_char();
    }
Exemplo n.º 8
0
	matlab_parser::Token get(std::string& v)
	{
		v.clear();
		int c;
		do {
			c = getc();
		} while(isspace(c));

		// operators
		switch(c) {
		case '+': return matlab_parser::token_Add;
		case '-': return matlab_parser::token_Sub;
		case '*': return matlab_parser::token_Mul;
		case '/': return matlab_parser::token_Div;
		case '|': return matlab_parser::token_BitOr;
		case '&': return matlab_parser::token_BitAnd;
		case '^': return matlab_parser::token_Pow;
		case ',': return matlab_parser::token_Comma;
		case '(': return matlab_parser::token_LParen;
		case ')': return matlab_parser::token_RParen;
		case '\'': return matlab_parser::token_Trans;
		case EOF: return matlab_parser::token_eof;
		}

		// ignore equality operators and relational operators

		/*if(c == '='){
			c = getc();

			if(c == '=')
				return matlab_ast::token_Eq;

			ungetc(c);

			throw unexpected_char();
		}*/

		// array operators
		if(c == '.'){
			switch(getc()){
			case '*':
				return matlab_parser::token_ArrayMul;
			case '/':
				return matlab_parser::token_ArrayDiv;
			case '^':
				return matlab_parser::token_ArrayPow;
			case '\'':
				return matlab_parser::token_NCTrans;
			case EOF:
				return matlab_parser::token_eof;
			}
		}

		// identifiers
		if(isalpha(c)){
			while(c != EOF && (isalnum(c) || c == '_')){
				v += c;
				c = getc();
			}
			ungetc(c);
			return matlab_parser::token_Identifier;
		}

		// constants
		// 正規表現の[0-9]*(\.[0-9]*)?([eE][+-]?[0-9]*)?にマッチするかを見る。
		// ".e+1"のように.の前後が両方とも省略されていてもエラーにならない。
		if(isdigit(c) || c == '.') {
			while(isdigit(c) && c != EOF){
				v += c;
				c = getc();
			}

			if(c == '.'){
				v += c;
				c = getc();

				while(isdigit(c) && c != EOF){
					v += c;
					c = getc();
				}
			}

			if(c == 'e' || c == 'E'){
				v += c;

				c = getc();

				auto iter = c_;

				if(c == '+' || c == '-'){
					v += c;
					c = getc();
				}

				while(isdigit(c) && c != EOF){
					v += c;
					c = getc();
				}

				if(iter == c_)
					throw unexpected_char();
			}

			ungetc(c);

			return matlab_parser::token_Constant;
		}


		std::cerr << char(c) << std::endl;
		throw unexpected_char();
	}