Package net.percederberg.grammatica

Examples of net.percederberg.grammatica.Grammar


     * Writes the source code files.
     *
     * @throws IOException if the files couldn't be written correctly
     */
    public void write() throws IOException {
        Grammar                   grammar = getGrammar();
        VisualBasicConstantsFile  constants;
        VisualBasicTokenizerFile  tokenizer;
        VisualBasicParserFile     parser;
        VisualBasicAnalyzerFile   analyzer;
        TokenPattern              token;
        ProductionPattern         production;
        int                       i;

        // Create output files
        constants = new VisualBasicConstantsFile(this);
        tokenizer = new VisualBasicTokenizerFile(this);
        analyzer = new VisualBasicAnalyzerFile(this);
        parser = new VisualBasicParserFile(this, tokenizer, analyzer);

        // Create token declarations
        for (i = 0; i < grammar.getTokenPatternCount(); i++) {
            token = grammar.getTokenPattern(i);
            constants.addToken(token);
            tokenizer.addToken(token, constants);
            analyzer.addToken(token, constants);
        }

        // Create production constants
        for (i = 0; i < grammar.getProductionPatternCount(); i++) {
            production = grammar.getProductionPattern(i);
            constants.addProduction(production);
            parser.addProductionConstant(production);
            analyzer.addProduction(production, constants);
        }

        // Create production declarations
        for (i = 0; i < grammar.getProductionPatternCount(); i++) {
            production = grammar.getProductionPattern(i);
            parser.addProduction(production, constants);
        }

        // Write source code files
        constants.writeCode();
View Full Code Here


     * Writes the source code files.
     *
     * @throws IOException if the files couldn't be written correctly
     */
    public void write() throws IOException {
        Grammar              grammar = getGrammar();
        CSharpConstantsFile  constants = new CSharpConstantsFile(this);
        CSharpTokenizerFile  tokenizer = new CSharpTokenizerFile(this);
        CSharpAnalyzerFile   analyzer = new CSharpAnalyzerFile(this);
        CSharpParserFile     parser = new CSharpParserFile(this, tokenizer, analyzer);
        TokenPattern         token;
        ProductionPattern    production;
        int                  i;

        // Create token declarations
        for (i = 0; i < grammar.getTokenPatternCount(); i++) {
            token = grammar.getTokenPattern(i);
            constants.addToken(token);
            tokenizer.addToken(token, constants);
            analyzer.addToken(token, constants);
        }

        // Create production constants
        for (i = 0; i < grammar.getProductionPatternCount(); i++) {
            production = grammar.getProductionPattern(i);
            constants.addProduction(production);
            parser.addProductionConstant(production);
            analyzer.addProduction(production, constants);
        }

        // Create production declarations
        for (i = 0; i < grammar.getProductionPatternCount(); i++) {
            production = grammar.getProductionPattern(i);
            parser.addProduction(production, constants);
        }

        // Write source code files
        constants.writeCode();
View Full Code Here

     * Writes the Java source code files.
     *
     * @throws IOException if the files couldn't be written correctly
     */
    public void write() throws IOException {
        Grammar            grammar = getGrammar();
        JavaConstantsFile  constants = new JavaConstantsFile(this);
        JavaTokenizerFile  tokenizer = new JavaTokenizerFile(this);
        JavaAnalyzerFile   analyzer = new JavaAnalyzerFile(this);
        JavaParserFile     parser = new JavaParserFile(this, tokenizer, analyzer);
        TokenPattern       token;
        ProductionPattern  production;
        int                i;

        // Create token declarations
        for (i = 0; i < grammar.getTokenPatternCount(); i++) {
            token = grammar.getTokenPattern(i);
            constants.addToken(token);
            tokenizer.addToken(token, constants);
            analyzer.addToken(token, constants);
        }

        // Create production constants
        for (i = 0; i < grammar.getProductionPatternCount(); i++) {
            production = grammar.getProductionPattern(i);
            constants.addProduction(production);
            parser.addProductionConstant(production);
            analyzer.addProduction(production, constants);
        }

        // Create production definitions
        for (i = 0; i < grammar.getProductionPatternCount(); i++) {
            production = grammar.getProductionPattern(i);
            parser.addProduction(production, constants);
        }

        // Write source code files
        constants.writeCode();
View Full Code Here

     * Executes the task.
     *
     * @throws RuntimeException if the task execution failed
     */
    public void execute() throws RuntimeException {
        Grammar  grammar;
        int      i;

        // Validate all elements
        if (file == null) {
            throw new RuntimeException("missing 'grammar' attribute");
        }
        if (processors.size() <= 0) {
            throw new RuntimeException(
                "missing <validate>, <java>, <csharp> or <visualbasic> " +
                "inner element");
        }
        for (i = 0; i < processors.size(); i++) {
            ((ProcessingElement) processors.get(i)).validate();
        }

        // Read grammar file
        try {
            grammar = new Grammar(file);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (ParserLogException e) {
            handleError(e);
            return;
View Full Code Here

TOP

Related Classes of net.percederberg.grammatica.Grammar

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.