{
RefPtr<Literal> literal = new Literal;
if(var.type=="bool")
+ {
literal->token = (i->second ? "true" : "false");
+ literal->value = static_cast<bool>(i->second);
+ }
else if(var.type=="int")
+ {
literal->token = lexical_cast<string>(i->second);
+ literal->value = i->second;
+ }
var.init_expression = literal;
}
}
left = parexpr;
}
else if(isdigit(token[0]) || token=="true" || token=="false")
- {
- RefPtr<Literal> literal = new Literal;
- literal->token = tokenizer.parse_token();
- left = literal;
- }
+ left = parse_literal();
else if(is_identifier(token))
{
RefPtr<VariableReference> var = create_node<VariableReference>();
}
}
+RefPtr<Literal> Parser::parse_literal()
+{
+ RefPtr<Literal> literal = create_node<Literal>();
+ literal->token = tokenizer.parse_token();
+ if(isdigit(literal->token[0]))
+ {
+ // TODO have the tokenizer return the type of the token
+ if(isnumrc(literal->token))
+ literal->value = lexical_cast<int>(literal->token);
+ else
+ literal->value = lexical_cast<float>(literal->token);
+ }
+ else if(literal->token=="true" || literal->token=="false")
+ literal->value = (literal->token=="true");
+ else
+ throw parse_error(tokenizer.get_location(), literal->token, "a literal");
+
+ return literal;
+}
+
RefPtr<BinaryExpression> Parser::parse_binary(const RefPtr<Expression> &left, const Operator &oper)
{
RefPtr<BinaryExpression> binary = (oper.precedence==16 ?
template<typename T>
void parse_block(Block &, bool, RefPtr<T> (Parser::*)());
RefPtr<Expression> parse_expression(unsigned = 0);
+ RefPtr<Literal> parse_literal();
RefPtr<BinaryExpression> parse_binary(const RefPtr<Expression> &, const Operator &);
RefPtr<FunctionCall> parse_function_call(const VariableReference &);
RefPtr<TypeDeclaration> parse_type_declaration();
#include <string>
#include <vector>
#include <msp/core/refptr.h>
+#include <msp/core/variant.h>
#include "features.h"
#include "glsl_error.h"
#include "sourcemap.h"
struct Literal: Expression
{
std::string token;
+ Variant value;
virtual Literal *clone() const { return new Literal(*this); }
virtual void visit(NodeVisitor &);