OCTAL,
FLOAT,
FLOATEXP,
+ STRING_END,
IDENTIFIER
};
Token::SPECIAL,
Token::SPECIAL,
Token::SPECIAL,
- Token::STRING,
+ Token::SPECIAL,
Token::SPECIAL,
Token::INTEGER,
Token::INTEGER,
Token::INTEGER,
Token::FLOAT,
Token::FLOAT,
+ Token::STRING,
Token::IDENTIFIER
};
return Token(Token::SPECIAL, string(1, c));
else if(isdigit(c))
state = DECIMAL;
- else if(isalpha(c) || c=='_')
+ else if(isalpha(c) || c=='_' || c=='\\')
state = IDENTIFIER;
else
- parse_error(c, "0-9A-Za-z_.\"{};+-");
+ parse_error(c, "0-9A-Za-z_\\.\"{};+-");
break;
case SIGN:
if(c=='\\')
escape = !escape;
else if(c=='"' && !escape)
+ state = STRING_END;
+ else
+ escape = false;
+ break;
+
+ case IDENTIFIER:
+ if(!isalpha(c) && !isdigit(c) && c!='_' && c!='-' && c!='/')
+ parse_error(c, "0-9A-Za-z_/-");
+ break;
+
+ case STRING_END:
+ throw_at(ParseError("Garbage after string"), get_location());
+
+ default:
+ throw_at(InvalidState("Internal error (bad state)"), get_location());
+ }
+
+ if(is_delimiter(next) && state>=ACCEPT)
+ {
+ if(state==IDENTIFIER && buf[0]=='\\')
+ return Token(Token::IDENTIFIER, buf.substr(1));
+ else if(state==STRING_END)
{
try
{
}
}
else
- escape = false;
- break;
-
- case IDENTIFIER:
- if(!isalpha(c) && !isdigit(c) && c!='_')
- parse_error(c, "0-9A-Za-z_");
- break;
-
- default:
- throw_at(InvalidState("Internal error (bad state)"), get_location());
+ return Token(token_type[state], buf);
}
-
- if(is_delimiter(next) && state>=ACCEPT)
- return Token(token_type[state], buf);
}
return Token(Token::SPECIAL, "");
else if(i->get_signature()==FloatType::signature)
out.write(format("%15g", (i->get<FloatType::Store>())));
else if(i->get_signature()==SymbolType::signature)
- out.write(i->get<SymbolType::Store>().name);
+ {
+ string name = i->get<SymbolType::Store>().name;
+ if(isdigit(name[0]))
+ out.write("\\"+name);
+ else
+ out.write(name);
+ }
}
if(!st.sub.empty())
{