001package jmri.jmrit.logixng.util.parser;
002
003import jmri.JmriException;
004import jmri.jmrit.logixng.SymbolTable;
005
006/**
007 * A parsed expression
008 */
009public class ExpressionNodeComplex implements ExpressionNode {
010
011    private final ExpressionNode _firstNode;
012    private final ExpressionNodeWithParameter _secondNode;
013    
014    public ExpressionNodeComplex(
015            ExpressionNode firstNode,
016            ExpressionNodeWithParameter secondNode) {
017        _firstNode = firstNode;
018        _secondNode = secondNode;
019    }
020    
021    @Override
022    public Object calculate(SymbolTable symbolTable) throws JmriException {
023        Object parameter = _firstNode.calculate(symbolTable);
024        return _secondNode.calculate(parameter, symbolTable);
025    }
026    
027    /** {@inheritDoc} */
028    @Override
029    public boolean canBeAssigned() {
030        return _secondNode.canBeAssigned();
031    }
032    
033    /** {@inheritDoc} */
034    @Override
035    public void assignValue(SymbolTable symbolTable, Object value) throws JmriException {
036        Object parameter = _firstNode.calculate(symbolTable);
037        _secondNode.assignValue(parameter, symbolTable, value);
038    }
039    
040    /** {@inheritDoc} */
041    @Override
042    public String getDefinitionString() {
043        return _firstNode.getDefinitionString()
044                + "->"
045                + _secondNode.getDefinitionString();
046    }
047    
048}