Search in sources :

Example 1 with Expression

use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.

the class CuplExporter method writeTo.

/**
 * Writes code to given writer
 *
 * @param out the stream to write to
 * @throws IOException            IOException
 * @throws PinMapException        PinMapException
 */
public void writeTo(Writer out) throws IOException, PinMapException {
    out.append("Name     ").append(projectName).append(" ;\r\n").append("PartNo   00 ;\r\n").append("Date     ").append(formatDate(date)).append(" ;\r\n").append("Revision 01 ;\r\n").append("Designer ").append(username).append(" ;\r\n").append("Company  unknown ;\r\n").append("Assembly None ;\r\n").append("Location unknown ;\r\n").append("Device   ").append(devName).append(" ;\r\n");
    headerWritten(out);
    out.append("\r\n/* inputs */\r\n");
    if (!builder.getRegistered().isEmpty())
        out.append("PIN ").append(String.valueOf(clockPin)).append(" = CLK;\r\n");
    for (String in : builder.getInputs()) out.append("PIN ").append(Integer.toString(pinMap.getInputFor(in))).append(" = ").append(in).append(";\r\n");
    out.append("\r\n/* outputs */\r\n");
    for (String var : builder.getOutputs()) {
        if (createNodes) {
            int p = pinMap.isOutputAssigned(var);
            if (p >= 0)
                out.append("PIN ").append(Integer.toString(p)).append(" = ").append(var).append(";\r\n");
            else
                out.append("NODE ").append(var).append(";\r\n");
        } else {
            out.append("PIN ").append(Integer.toString(pinMap.getOutputFor(var))).append(" = ").append(var).append(";\r\n");
        }
    }
    try {
        if (!builder.getRegistered().isEmpty()) {
            out.append("\r\n/* sequential logic */\r\n");
            for (Map.Entry<String, Expression> c : builder.getRegistered().entrySet()) {
                out.append(c.getKey()).append(".D = ");
                breakLines(out, FormatToExpression.FORMATTER_CUPL.format(c.getValue()));
                out.append(";\r\n");
                sequentialWritten(out, c.getKey());
            }
        }
        if (!builder.getCombinatorial().isEmpty()) {
            out.append("\r\n/* combinatorial logic */\r\n");
            for (Map.Entry<String, Expression> c : builder.getCombinatorial().entrySet()) {
                out.append(c.getKey()).append(" = ");
                breakLines(out, FormatToExpression.FORMATTER_CUPL.format(c.getValue()));
                out.append(";\r\n");
            }
        }
    } catch (FormatterException e) {
        throw new IOException(e);
    }
    out.flush();
}
Also used : FormatterException(de.neemann.digital.analyse.expression.format.FormatterException) FormatToExpression(de.neemann.digital.analyse.expression.format.FormatToExpression) Expression(de.neemann.digital.analyse.expression.Expression) IOException(java.io.IOException) Map(java.util.Map)

Example 2 with Expression

use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.

the class KarnaughMapTest method testSimple2_singleAnd.

public void testSimple2_singleAnd() throws IOException, ParseException, KarnaughException {
    Expression exp = new Parser("A B").parse().get(0);
    KarnaughMap c = new KarnaughMap(Variable.vars(2), exp);
    assertEquals(1, c.size());
    for (KarnaughMap.Cover co : c) assertEquals(1, co.getSize());
}
Also used : Expression(de.neemann.digital.analyse.expression.Expression) Parser(de.neemann.digital.analyse.parser.Parser)

Example 3 with Expression

use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.

the class KarnaughMapTest method testSimple3.

public void testSimple3() throws IOException, ParseException, KarnaughException {
    Expression exp = new Parser("(A ¬C) ∨ (¬A ¬B) ∨ (B C)").parse().get(0);
    KarnaughMap c = new KarnaughMap(Variable.vars(3), exp);
    assertEquals(3, c.size());
    for (KarnaughMap.Cover co : c) assertEquals(2, co.getSize());
}
Also used : Expression(de.neemann.digital.analyse.expression.Expression) Parser(de.neemann.digital.analyse.parser.Parser)

Example 4 with Expression

use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.

the class KarnaughMapTest method testSimple2.

public void testSimple2() throws IOException, ParseException, KarnaughException {
    Expression exp = new Parser("(A ¬B) ∨ (¬A B)").parse().get(0);
    KarnaughMap c = new KarnaughMap(Variable.vars(2), exp);
    assertEquals(2, c.size());
    for (KarnaughMap.Cover co : c) assertEquals(1, co.getSize());
}
Also used : Expression(de.neemann.digital.analyse.expression.Expression) Parser(de.neemann.digital.analyse.parser.Parser)

Example 5 with Expression

use of de.neemann.digital.analyse.expression.Expression in project Digital by hneemann.

the class ExpressionListenerJKTest method testSimple.

public void testSimple() throws IOException, ParseException, FormatterException, ExpressionException {
    ExpressionListenerOptimizeJKTest.TestEL exp = new ExpressionListenerOptimizeJKTest.TestEL();
    ExpressionListener elojk = new ExpressionListenerJK(exp);
    Expression e1 = new Parser("(Sn*A)+(!Sn*B)").parse().get(0);
    elojk.resultFound("Sn+1", e1);
    elojk.close();
    assertEquals(3, exp.getList().size());
    assertEquals(e1, exp.getList().get(0));
    assertEquals("B", exp.getList().get(1).toString());
    assertEquals("not(A)", exp.getList().get(2).toString());
}
Also used : Expression(de.neemann.digital.analyse.expression.Expression) Parser(de.neemann.digital.analyse.parser.Parser)

Aggregations

Expression (de.neemann.digital.analyse.expression.Expression)60 Variable (de.neemann.digital.analyse.expression.Variable)34 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)12 Parser (de.neemann.digital.analyse.parser.Parser)11 ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)10 NamedExpression (de.neemann.digital.analyse.expression.NamedExpression)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 Circuit (de.neemann.digital.draw.elements.Circuit)5 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)5 ModelCreator (de.neemann.digital.draw.model.ModelCreator)5 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)5 ArrayList (java.util.ArrayList)5 TestExecuter (de.neemann.digital.TestExecuter)4 QuineMcCluskey (de.neemann.digital.analyse.quinemc.QuineMcCluskey)3 PrimeSelectorDefault (de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault)3 TableRow (de.neemann.digital.analyse.quinemc.TableRow)2 Model (de.neemann.digital.core.Model)2 Date (java.util.Date)2 DetermineJKStateMachine (de.neemann.digital.analyse.DetermineJKStateMachine)1 ExpressionException (de.neemann.digital.analyse.expression.ExpressionException)1