All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.vesalainen.regex.MatchCompiler Maven / Gradle / Ivy

Go to download

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 match methods using DFA
 * @author tkv
 */
public class MatchCompiler extends DFACompiler
{
    public MatchCompiler(DFA dfa, T errorToken, T eofToken)
    {
        super(dfa, errorToken, eofToken);
        //repeats = dfa.RemoveRepeatingTransitions();
    }

    @Override
    protected MatchCompiler copy(DFA ddfa)
    {
        return new MatchCompiler<>(ddfa, errorToken, eofToken);
    }
    
    @Override
    protected void accepting(DFAState s) throws IOException, NoSuchMethodException
    {
        if (s.isAccepting())
        {
            tconst(s.getToken());
            tstore("accepted");
            int fixedEndLength = s.getFixedEndLength();
            if (fixedEndLength != 0)
            {
                tload("reader");
                iconst(fixedEndLength);
                invokevirtual(InputReader.class, "rewind", int.class);
            }
        }
        else
        {
            tconst(errorToken);
            tstore("accepted");
        }
    }

    /**
     *
     * @throws IOException
     * @throws NoSuchMethodException
     */
    protected void error() throws IOException, NoSuchMethodException
    {
        tload("accepted");
        tconst(errorToken);
        if_tcmpne(tokenType, "pushback");

        tload("accepted");
        treturn();
    }

    @Override
    protected void pushback() throws IOException, NoSuchMethodException
    {
        tload("reader");
        tload("cc");
        invokevirtual(InputReader.class, "unread", int.class);
        goto_n("exit");
    }

    @Override
    protected void exit() throws IOException, NoSuchMethodException
    {
        tload("accepted");
        treturn();
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy