/*
*
* Copyright 2012 lexergen.
* This file is part of lexergen.
*
* lexergen is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* lexergen is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with lexergen. If not, see <http://www.gnu.org/licenses/>.
*
* lexergen:
* A tool to chunk source code into tokens for further processing in a compiler chain.
*
* Projectgroup: bi, bii
*
* Authors: Johannes Dahlke
*
* Module: Softwareprojekt Übersetzerbau 2012
*
* Created: Apr. 2012
* Version: 1.0
*
*/
package de.fuberlin.bii.regextodfaconverter.directconverter.lrparser;
import de.fuberlin.bii.regextodfaconverter.directconverter.AutomatEventHandler;
import de.fuberlin.bii.regextodfaconverter.directconverter.lrparser.grammar.Symbol;
import de.fuberlin.bii.regextodfaconverter.directconverter.lrparser.grammar.Terminal;
import de.fuberlin.bii.regextodfaconverter.directconverter.lrparser.itemset.Closure;
import de.fuberlin.bii.regextodfaconverter.directconverter.lrparser.itemset.Lr0Closure;
import de.fuberlin.bii.utils.Test;
/**
* Aktion für den Parser
*
* @author Johannes Dahlke
*
* @param <Element>
*/
@SuppressWarnings("rawtypes")
public abstract class Action<Element extends Symbol, SpecializedClosure extends Closure> implements AutomatEventHandler<Element, SpecializedClosure> {
private Action alternativeAction = null;
public Action() {
super();
}
/**
* Fügt der Aktion eine alternative Aktion hinzu. Diese wird dann gewählt, wenn der {@link ItemAutomat}
* keine passende Reduce-Regel mehr anwenden kann und einen erneuten Anlauf nimmt.
*
* @param theAlternativeAction
*/
public void addAlternative( Action theAlternativeAction) {
if ( Test.isUnassigned( this.alternativeAction))
this.alternativeAction = theAlternativeAction;
else
if ( !this.alternativeAction.equals( theAlternativeAction))
this.alternativeAction.addAlternative( theAlternativeAction);
}
/**
* Test auf Vorhandensein einer alternativen Aktion.
*
* @return
*/
public boolean hasAlternative() {
return Test.isAssigned( alternativeAction);
}
/**
* Akzessor auf die alternative Aktion
* @return
*/
public Action getAlternative() {
return alternativeAction;
}
}