Skip to content

Commit

Permalink
Fixed stupid mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
HeronErin committed Apr 22, 2024
1 parent c21eb9f commit b7ea7e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
6 changes: 5 additions & 1 deletion source/parsing/treegen/expressionParser.d
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,16 @@ unittest
{

import parsing.tokenizer.make_tokens;
AstNode[] phaseOneNodes = phaseOne("math.sqrt( 3 *5 +6 *7/ 2 ) *x / 2+ 4 ".tokenizeText);
AstNode[] phaseOneNodes = phaseOne("math.sqrt( 3 *5 +6 *7/ 2 )*x/2+4".tokenizeText);

Array!AstNode nodes;
nodes~=phaseOneNodes;
phaseTwo(nodes);
scanAndMergeOperators(nodes);
// nodes[0].writeln;
nodes[0].tree(0);
// foreach(node ; nodes){
// node.tree(0);
// }

}
39 changes: 19 additions & 20 deletions source/parsing/treegen/tokenRelationships.d
Original file line number Diff line number Diff line change
Expand Up @@ -434,18 +434,18 @@ const OperatorPrecedenceLayer[] operatorPrecedence = [
];
import std.container.array;

private void testAndJoin(const(OperationPrecedenceEntry) entry, ref Array!AstNode nodes, ref size_t startIndex)
private bool testAndJoin(const(OperationPrecedenceEntry) entry, ref Array!AstNode nodes, size_t startIndex)
{
if (entry.tokens.length > nodes.length)
return;
return false;
size_t nodeIndex = startIndex;
AstNode[] operands;

for (size_t index = 0; index < entry.tokens.length; index++)
{
Nullable!AstNode nodeNullable = nodes.nextNonWhiteNode(nodeIndex);
if (nodeNullable.ptr == null)
return;
return false;
AstNode node = nodeNullable;
switch (entry.tokens[index].tokenVariety)
{
Expand All @@ -454,17 +454,17 @@ private void testAndJoin(const(OperationPrecedenceEntry) entry, ref Array!AstNod

if (node.action == AstAction.TokenHolder || node.action == AstAction.Keyword || node.action == AstAction
.Scope)
return;
return false;
operands ~= node;
break;
case TokenType.Operator:
if (node.action != AstAction.TokenHolder)
return;
return false;
Token token = node.tokenBeingHeld;
if (token.tokenVariety != TokenType.Equals && token.tokenVariety != TokenType.Operator)
return;
return false;
if (token.value != entry.tokens[index].value)
return;
return false;
break;
default:
assert(0);
Expand Down Expand Up @@ -492,10 +492,8 @@ private void testAndJoin(const(OperationPrecedenceEntry) entry, ref Array!AstNod
);

nodes[startIndex] = oprNode;
nodes.linearRemove(nodes[startIndex + 1 .. nodeIndex-1]);
startIndex = nodeIndex;


nodes.linearRemove(nodes[startIndex + 1 .. nodeIndex]);
return true;
}

// private void merge(const(OperationPrecedenceEntry) entry, ref Array!AstNode nodes, size_t startIndex)
Expand Down Expand Up @@ -555,19 +553,20 @@ void scanAndMergeOperators(Array!AstNode nodes)
{
foreach (entry; layer.layer)
{
entry.testAndJoin(nodes, index);
if (entry.testAndJoin(nodes, index)){index--; continue;}

}

}
}
static if (layer.order == OperatorOrder.RightToLeft){
for (size_t index = nodes.length; index != -1; index--){
foreach (entry; layer.layer)
{
entry.testAndJoin(nodes, index, index);
}
}
}
// static if (layer.order == OperatorOrder.RightToLeft){
// for (size_t index = nodes.length; index != -1; index--){
// foreach (entry; layer.layer)
// {
// entry.testAndJoin(nodes, index);
// }
// }
// }
}
}

0 comments on commit b7ea7e2

Please sign in to comment.