Warning: session_start(): open(/var/lib/php/sessions/sess_6vo0j7cpu76ksbt0h9l23e7cm9, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
// https://en.wikipedia.org/wiki/Shunting-yard_algorithm
sclass ShuntingYardParser is Steppable {
LS tok;
int iTok = 1;
new LS operatorStack;
new LS outputQueue;
*() {}
*(LS *tok) {}
run { stepAll(this); }
public bool step() {
if (iTok >= l(tok)) {
while (nempty(operatorStack)) {
var o = popLast(operatorStack);
assertNequals(o, "(");
outputQueue.add(o);
}
false;
}
S t = tok.get(iTok);
iTok += 2;
if (eq(t, "("))
operatorStack.add(t);
else if (eq(t, ")")) {
while (!eq(last(operatorStack), "(")) {
assertNempty(operatorStack);
outputQueue.add(popLast(operatorStack));
}
popLast(operatorStack);
} else if (!startsWithLetterOrDigit(t) && !eq(t, ".")) {
// assume it's an operator
S o1 = t;
outputQueue.add(o1);
S o2;
while (!eqOneOf(o2 = last(operatorStack), "(", null)
&& (precedence(o2) > precedence(o1)
|| precedence(o2) == precedence(o1) && isLeftAssociative(o1))) outputQueue.add(popLast(operatorStack));
operatorStack.add(o1);
}
true;
}
int precedence(S op) { ret 0; }
bool isLeftAssociative(S op) { true; }
}