Package com.creativewidgetworks.goldparser.engine

Examples of com.creativewidgetworks.goldparser.engine.Reduction


public class Parameters extends Reduction {

    public static final String KEY_PARAMETERS = "[ParameterStack]";

    public Parameters(GOLDParser parser) {
        Reduction reduction = parser.getCurrentReduction();

        List<String> parameters = new ArrayList<String>();

        if (reduction.size() > 0) {
            Stack stack;

            Variable var = parser.getProgramVariable(KEY_PARAMETERS);
            if (var == null) {
                stack = new Stack();
                parser.setProgramVariable(KEY_PARAMETERS, new Variable(stack));
            } else {
                stack = (Stack)var.asObject();
            }

            stack.push(reduction.get(0).getData());

            // Copy the values of the current stack to the value object leaving
            // all the values on the stack
            int paramCount = stack.size();
            for (int i = paramCount - 1; i >= 0; i--) {
View Full Code Here


public class WhileLoop extends Reduction {
    private Reduction conditional;
    private Reduction statements;

    public WhileLoop(GOLDParser parser) {
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 5) {
                conditional = reduction.get(1).asReduction();
                statements  = reduction.get(3).asReduction();               
            } else {
                parser.raiseParserException(Simple3.formatMessage("error.param_count", "5", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple3.formatMessage("error.no_reduction"));
        }         
    }
View Full Code Here

public class LoopUntil extends Reduction {
    private Reduction conditional;
    private Reduction statements;

    public LoopUntil(GOLDParser parser) {
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 4) {
                statements  = reduction.get(1).asReduction();
                conditional = reduction.get(3).asReduction();
            } else {
                parser.raiseParserException(Simple3.formatMessage("error.param_count", "4", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple3.formatMessage("error.no_reduction"));
        }       
    }
View Full Code Here

    private String variableName;
    private Reduction variableValue;

    public Assign(GOLDParser parser) {
        theParser = parser;
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 3) {
                variableName = reduction.get(0).asString();
                variableValue = reduction.get(2).asReduction();
            } else {
                parser.raiseParserException(Simple3.formatMessage("error.param_count", "3", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple3.formatMessage("error.no_reduction"));
        }
    }
View Full Code Here

    public static String EOLN = "\r\n";
    public static ConsoleDriver ioDriver = new SystemConsole();

    public Print(GOLDParser parser) {
        theParser = parser;
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 2) {
                dataToPrint = reduction.get(1).asReduction();
                variableName = null;
            } else if (reduction.size() == 4) {
                dataToPrint = reduction.get(1).asReduction();
                variableName = reduction.get(3).asString();
            } else {
                if (reduction.size() < 3) {
                    // print x form
                    parser.raiseParserException(Simple3.formatMessage("error.param_count", "2", String.valueOf(reduction.size())));
                }
                // print x read y form
                parser.raiseParserException(Simple3.formatMessage("error.param_count", "4", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple3.formatMessage("error.no_reduction"));
        }       
    }
View Full Code Here

    private Reduction conditional;
    private Reduction postStatement;
    private Reduction statements;

    public ForLoop(GOLDParser parser) {
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 11) {
                initStatement = reduction.get(2).asReduction();
                conditional   = reduction.get(4).asReduction();
                postStatement = reduction.get(6).asReduction();
                statements    = reduction.get(9).asReduction();
            } else {
                parser.raiseParserException(Simple3.formatMessage("error.param_count", "11", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple3.formatMessage("error.no_reduction"));
        }           
    }
View Full Code Here

    private Reduction leftExpression;
    private Reduction rightExpression;

    public Expression(GOLDParser parser) {
        theParser = parser;
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 3) {
                leftExpression  = reduction.get(0).asReduction();
                theOperator     = reduction.get(1).asString();
                rightExpression = reduction.get(2).asReduction()
                if (validOperators.indexOf(theOperator + " ") == -1) {
                    parser.raiseParserException(Simple2.formatMessage("error.invalid_operator", validOperators, theOperator));
                }
            } else {
                parser.raiseParserException(Simple2.formatMessage("error.param_count", "3", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple2.formatMessage("error.no_reduction"));
        }       
    }
View Full Code Here

    private GOLDParser theParser;
    private Reduction valueToNegate;

    public Negation(GOLDParser parser) {
        theParser = parser;
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 2) {
                valueToNegate = reduction.get(1).asReduction();
            } else {
                parser.raiseParserException(Simple2.formatMessage("error.param_count", "2", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple2.formatMessage("error.no_reduction"));
        }           
    }
View Full Code Here

    public static String EOLN = "\r\n";
    public static ConsoleDriver ioDriver = new SystemConsole();

    public Display(GOLDParser parser) {
        theParser = parser;
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 2) {
                dataToPrint = reduction.get(1).asReduction();
                variableName = null;
            } else if (reduction.size() == 4) {
                dataToPrint = reduction.get(1).asReduction();
                variableName = reduction.get(3).asString();
            } else {
                if (reduction.size() < 3) {
                    // print x form
                    parser.raiseParserException(Simple2.formatMessage("error.param_count", "2", String.valueOf(reduction.size())));
                }
                // print x read y form
                parser.raiseParserException(Simple2.formatMessage("error.param_count", "4", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple2.formatMessage("error.no_reduction"));
        }       
    }
View Full Code Here

    private Reduction conditional;
    private Reduction thenStatements;
    private Reduction elseStatements;

    public IfThenElse(GOLDParser parser) {
        Reduction reduction = parser.getCurrentReduction();
        if (reduction != null) {
            if (reduction.size() == 5) {
                // if x then y end
                conditional    = reduction.get(1).asReduction();
                thenStatements = reduction.get(3).asReduction();               
            } else if (reduction.size() == 7) {
                // if x then y else z end
                conditional    = reduction.get(1).asReduction();
                thenStatements = reduction.get(3).asReduction();
                elseStatements = reduction.get(5).asReduction();
            } else {
                if (reduction.size() < 5) {
                    // if x then y form
                    parser.raiseParserException(Simple2.formatMessage("error.param_count", "5", String.valueOf(reduction.size())));
                }
                // if x then y else z end form
                parser.raiseParserException(Simple2.formatMessage("error.param_count", "7", String.valueOf(reduction.size())));
            }
        } else {
            parser.raiseParserException(Simple2.formatMessage("error.no_reduction"));
        }       
     }
View Full Code Here

TOP

Related Classes of com.creativewidgetworks.goldparser.engine.Reduction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.