org.vesalainen.regex.FindCompiler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lpg Show documentation
Show all versions of lpg Show documentation
Java Lookahead Parser Generator. Generator produces LALR(k) parsers. Grammar
rules are entered using annotations. Rule annotation can be attached to reducer
method, which keeps rule and it's action together.
The newest version!
package org.vesalainen.regex;
import org.vesalainen.parser.util.InputReader;
import org.vesalainen.grammar.state.DFAState;
import org.vesalainen.grammar.state.DFA;
import java.io.IOException;
/**
* This class compiles find methods using DFA
* @author tkv
* @param
*/
public class FindCompiler extends DFACompiler
{
public FindCompiler(DFA dfa, T errorToken, T eofToken)
{
super(dfa, errorToken, eofToken);
dfa.calculateMaxFindSkip();
}
@Override
protected FindCompiler copy(DFA ddfa)
{
return new FindCompiler<>(ddfa, errorToken, eofToken);
}
@Override
protected void afterState(DFAState s) throws IOException, NoSuchMethodException
{
if (dfa.isAcceptStart())
{
tload("reader");
iconst(s.getAcceptStartLength());
invokevirtual(InputReader.class, "setAcceptStart", int.class);
}
}
@Override
protected void accepting(DFAState s) throws IOException, NoSuchMethodException
{
if (s.isAccepting())
{
tconst(s.getToken());
tstore("accepted");
tload("reader");
invokevirtual(InputReader.class, "findAccept");
}
}
@Override
protected void error() throws IOException, NoSuchMethodException
{
tload("accepted");
tconst(errorToken);
if_tcmpne(tokenType, "pushback");
tload("reader");
invokevirtual(InputReader.class, "findRecover");
goto_n("start");
}
@Override
protected void pushback() throws IOException, NoSuchMethodException
{
tload("reader");
invokevirtual(InputReader.class, "findPushback");
goto_n("exit");
}
@Override
protected void exit() throws IOException, NoSuchMethodException
{
tload("accepted");
treturn();
}
}