Exemplo n.º 1
0
void Lex::Dump(int pos)
{
#ifdef LOGNEXT
	int code = Code(pos);
	switch(code) {
	case t_string: LOG(AsCString(Text(pos))); break;
	case t_double: LOG(Double(pos)); break;
	case t_integer: LOG(Int(pos)); break;
	case t_character: LOG("char " << AsCString(String(Chr(pos), 1))); break;
	default:
		if(code < 0)
			LOG(decode(Code(),
				t_dblcolon, "::",
				t_mulass, "*=",
				t_divass, "/=",
				t_modass, "%=",
				t_xorass, "^=",
				t_neq, "!=",
				t_dot_asteriks, ".*",
				t_elipsis, "...",
				t_inc, "++",
				t_addass, "+=",
				t_dec, "--",
				t_arrow_asteriks, "->*",
				t_arrow, "->",
				t_subass, "-=",
				t_and, "&&",
				t_andass, "&=",
				t_or, "||",
				t_orass, "|=",
				t_eq, "==",
				t_shl, "<<",
				t_shlass, "<<=",
				t_le, "<=",
				t_shr, ">>",
				t_shrass, ">>=",
				t_ge, ">=",
				te_integeroverflow, "<integer overflow>",
				te_badcharacter, "<bad char>",
				te_badstring, "<bad string>",
				"???"));
		else
		if(code < 256)
			LOG((char)code);
		else
			LOG(id[code - 256]);
	}
#endif
}
Exemplo n.º 2
0
 printf(":%s:\n",ptr);
 free(ptr);

 ptr=Asc("A","\0");
 printf("Asc:%s:\n",ptr);
 free(ptr);
 
 ptr=Asc(" ","\0");
 printf(":%s:\n",ptr);
 free(ptr);

 ptr=Asc("","\0");
 printf(":%s:\n",ptr);
 free(ptr);

 ptr=Chr("65","\0");
 printf("Chr:%s:\n",ptr);
 free(ptr);
 
 ptr=Chr("32","\0");
 printf(":%s:\n",ptr);
 free(ptr);

 ptr=Chr(" ","\0");
 printf(":%s:\n",ptr);
 free(ptr);

 ptr=PadL("Herve","30","I","\0");
 printf("PadL:%s:\n",ptr);
 free(ptr);
Exemplo n.º 3
0
TokenPtr SLScanner::ScanToken()
{
    std::string spell;

    /* Scan directive (beginning with '#') */
    if (Is('#'))
        return ScanDirective();

    /* Scan identifier */
    if (std::isalpha(UChr()) || Is('_'))
        return ScanIdentifier();

    /* Scan number */
    if (Is('.'))
        return ScanNumberOrDot();
    if (std::isdigit(UChr()))
        return ScanNumber();

    /* Scan string literal */
    if (Is('\"'))
        return ScanStringLiteral();

    /* Scan operators */
    if (Is('='))
    {
        spell += TakeIt();
        if (Is('='))
            return Make(Tokens::BinaryOp, spell, true);
        return Make(Tokens::AssignOp, spell);
    }

    if (Is('~'))
        return Make(Tokens::UnaryOp, spell, true);

    if (Is('!'))
    {
        spell += TakeIt();
        if (Is('='))
            return Make(Tokens::BinaryOp, spell, true);
        return Make(Tokens::UnaryOp, spell);
    }

    if (Is('%'))
    {
        spell += TakeIt();
        if (Is('='))
            return Make(Tokens::AssignOp, spell, true);
        return Make(Tokens::BinaryOp, spell);
    }

    if (Is('*'))
    {
        spell += TakeIt();
        if (Is('='))
            return Make(Tokens::AssignOp, spell, true);
        return Make(Tokens::BinaryOp, spell);
    }

    if (Is('^'))
    {
        spell += TakeIt();
        if (Is('='))
            return Make(Tokens::AssignOp, spell, true);
        return Make(Tokens::BinaryOp, spell);
    }

    if (Is('+'))
        return ScanPlusOp();
    if (Is('-'))
        return ScanMinusOp();

    if (Is('<') || Is('>'))
        return ScanAssignShiftRelationOp(Chr());

    if (Is('&'))
    {
        spell += TakeIt();
        if (Is('='))
            return Make(Tokens::AssignOp, spell, true);
        if (Is('&'))
            return Make(Tokens::BinaryOp, spell, true);
        return Make(Tokens::BinaryOp, spell);
    }

    if (Is('|'))
    {
        spell += TakeIt();
        if (Is('='))
            return Make(Tokens::AssignOp, spell, true);
        if (Is('|'))
            return Make(Tokens::BinaryOp, spell, true);
        return Make(Tokens::BinaryOp, spell);
    }

    if (Is(':'))
    {
        spell += TakeIt();
        if (Is(':'))
            return Make(Tokens::DColon, spell, true);
        return Make(Tokens::Colon, spell);
    }

    /* Scan punctuation, special characters and brackets */
    switch (Chr())
    {
        case ';': return Make(Tokens::Semicolon, true); break;
        case ',': return Make(Tokens::Comma,     true); break;
        case '?': return Make(Tokens::TernaryOp, true); break;
        case '(': return Make(Tokens::LBracket,  true); break;
        case ')': return Make(Tokens::RBracket,  true); break;
        case '{': return Make(Tokens::LCurly,    true); break;
        case '}': return Make(Tokens::RCurly,    true); break;
        case '[': return Make(Tokens::LParen,    true); break;
        case ']': return Make(Tokens::RParen,    true); break;
    }

    ErrorUnexpected();

    return nullptr;
}