Examples of GOLDParser


Examples of com.creativewidgetworks.goldparser.parser.GOLDParser

     * @param wantTree true if the parse tree should be generated
     * @return parse tree if generate parse tree open is set
     */
    public String executeProgram(String sourceCode, boolean wantTree) {
        // Use the compiled grammar file inside the jar
        GOLDParser parser = new GOLDParser(
            getClass().getResourceAsStream("/simple3/Simple3.cgt"), // compiled grammar table
            "com.creativewidgetworks.goldparser.simple3",           // rule handler package
            true);                                                  // trim reductions
       
        // Controls whether or not a parse tree is returned or the program executed.
        parser.setGenerateTree(wantTree);
       
        String tree = null;
        try {
            // Parse the source statements to see if it is syntactically correct
            boolean parsedWithoutError = parser.parseSourceStatements(sourceCode);

            // Holds the parse tree if setGenerateTree(true) was called
            tree = parser.getParseTree();
           
            // Either execute the code or print any error message
            if (parsedWithoutError) {
                parser.getCurrentReduction().execute();
            } else {
                System.out.println(parser.getErrorMessage());
            }
        } catch (ParserException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
View Full Code Here

Examples of com.creativewidgetworks.goldparser.parser.GOLDParser

     * @param wantTree true if the parse tree should be generated
     * @return parse tree if generate parse tree open is set
     */
    public String executeProgram(String sourceCode, boolean wantTree) {
        // Use the compiled grammar file inside the jar
        GOLDParser parser = new GOLDParser(
            getClass().getResourceAsStream("/simple2/Simple2.cgt"), // compiled grammar table
            "com.creativewidgetworks.goldparser.simple2",           // rule handler package
            true);                                                  // trim reductions
       
        // Controls whether or not a parse tree is returned or the program executed.
        parser.setGenerateTree(wantTree);
       
        String tree = null;
        try {
            // Parse the source statements to see if it is syntactically correct
            boolean parsedWithoutError = parser.parseSourceStatements(sourceCode);

            // Holds the parse tree if setGenerateTree(true) was called
            tree = parser.getParseTree();
           
            // Either execute the code or print any error message
            if (parsedWithoutError) {
                parser.getCurrentReduction().execute();
            } else {
                System.out.println(parser.getErrorMessage());
            }
        } catch (ParserException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.