Add constexpr DATA
This commit is contained in:
@@ -1176,27 +1176,16 @@ class Parser
|
|||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
bool minusflag;
|
bool minusflag;
|
||||||
//TODO:constexpression()関数作る
|
auto expr = cast(Constant)expression();
|
||||||
if(token.type == TokenType.Minus)
|
if (expr)
|
||||||
{
|
{
|
||||||
lex.popFront();
|
data.addData(expr.value);
|
||||||
token = lex.front();
|
|
||||||
minusflag = true;
|
|
||||||
}
|
}
|
||||||
if(token.type != TokenType.String && token.type != TokenType.Integer)
|
else
|
||||||
{
|
{
|
||||||
syntaxError();
|
syntaxError();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if(minusflag)
|
|
||||||
{
|
|
||||||
data.addData(Value(-token.value.castDouble));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data.addData(token.value);
|
|
||||||
}
|
|
||||||
lex.popFront();
|
|
||||||
token = lex.front();
|
token = lex.front();
|
||||||
if(token.type == TokenType.Comma)
|
if(token.type == TokenType.Comma)
|
||||||
{
|
{
|
||||||
@@ -1801,9 +1790,21 @@ class Parser
|
|||||||
case TokenType.Minus:
|
case TokenType.Minus:
|
||||||
//TODO:UnaryOperatorの実装
|
//TODO:UnaryOperatorの実装
|
||||||
//とりあえず0-exprを作成
|
//とりあえず0-exprを作成
|
||||||
lex.popFront();
|
{
|
||||||
node = new BinaryOperator(new Constant(Value(0), lex.location), TokenType.Minus, term(2/*array*/, null), lex.location);
|
lex.popFront();
|
||||||
return node;
|
auto a = term(2/*array*/, null);
|
||||||
|
double result;
|
||||||
|
if (a.type == NodeType.Constant && constcalc(Value(0), (cast(Constant)a).value, TokenType.Minus, result))
|
||||||
|
{
|
||||||
|
node = new Constant(Value(result), lex.location);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
node = new BinaryOperator(new Constant(Value(0), lex.location), TokenType.Minus, a, lex.location);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
||||||
case TokenType.LogicalNot:
|
case TokenType.LogicalNot:
|
||||||
case TokenType.Not:
|
case TokenType.Not:
|
||||||
lex.popFront();
|
lex.popFront();
|
||||||
|
|||||||
Reference in New Issue
Block a user