![JAR search and dependency download from the Maven repository](/logo.png)
net.sourceforge.plantuml.regexdiagram.ShuntingYard Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-mit Show documentation
Show all versions of plantuml-mit Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml.regexdiagram;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
public class ShuntingYard {
final private List ouputQueue = new ArrayList<>();
final private Deque operatorStack = new ArrayDeque<>();
public ShuntingYard(Iterator it) {
while (it.hasNext()) {
final ReToken token = it.next();
// System.err.println("token=" + token);
// System.err.println("ouputQueue=" + ouputQueue);
// System.err.println("operatorStack=" + operatorStack);
if (token.getType() == ReTokenType.SIMPLE_CHAR) {
ouputQueue.add(token);
} else if (token.getType() == ReTokenType.ESCAPED_CHAR) {
ouputQueue.add(token);
} else if (token.getType() == ReTokenType.GROUP) {
ouputQueue.add(token);
} else if (token.getType() == ReTokenType.CLASS) {
ouputQueue.add(token);
} else if (token.getType() == ReTokenType.ANCHOR) {
ouputQueue.add(token);
} else if (token.getType() == ReTokenType.QUANTIFIER) {
ouputQueue.add(token);
} else if (token.getType() == ReTokenType.CONCATENATION_IMPLICIT) {
// push it onto the operator stack.
operatorStack.addFirst(token);
} else if (token.getType() == ReTokenType.ALTERNATIVE) {
while (thereIsAConcatenationAtTheTopOfTheOperatorStack())
ouputQueue.add(operatorStack.removeFirst());
// push it onto the operator stack.
operatorStack.addFirst(token);
} else if (token.getType() == ReTokenType.PARENTHESIS_OPEN) {
operatorStack.addFirst(token);
} else if (token.getType() == ReTokenType.PARENTHESIS_CLOSE) {
while (operatorStack.peekFirst() != null
&& operatorStack.peekFirst().getType() != ReTokenType.PARENTHESIS_OPEN)
ouputQueue.add(operatorStack.removeFirst());
final ReToken first = operatorStack.removeFirst();
// ouputQueue.add(first);
} else {
throw new UnsupportedOperationException(token.toString());
}
}
while (operatorStack.isEmpty() == false) {
final ReToken token = operatorStack.removeFirst();
ouputQueue.add(token);
}
// System.err.println("ouputQueue=" + ouputQueue);
}
private boolean thereIsAConcatenationAtTheTopOfTheOperatorStack() {
final ReToken top = operatorStack.peekFirst();
return top != null && top.getType() == ReTokenType.CONCATENATION_IMPLICIT;
}
public final List getOuputQueue() {
return Collections.unmodifiableList(ouputQueue);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy