Package org.jostraca.comp.antlr.preprocessor

Examples of org.jostraca.comp.antlr.preprocessor.Grammar


    protected Hashtable files;  // table of grammar files read in
    protected org.jostraca.comp.antlr.Tool antlrTool;

    public Hierarchy(org.jostraca.comp.antlr.Tool tool) {
        this.antlrTool = tool;
        LexerRoot = new Grammar(tool, "Lexer", null, null);
        ParserRoot = new Grammar(tool, "Parser", null, null);
        TreeParserRoot = new Grammar(tool, "TreeParser", null, null);
        symbols = new Hashtable(10);
        files = new Hashtable(10);

        LexerRoot.setPredefined(true);
        ParserRoot.setPredefined(true);
View Full Code Here


    }

    public void expandGrammarsInFile(String fileName) {
        GrammarFile f = getFile(fileName);
        for (Enumeration e = f.getGrammars().elements(); e.hasMoreElements();) {
            Grammar g = (Grammar)e.nextElement();
            g.expandInPlace();
        }
    }
View Full Code Here

    public Grammar findRoot(Grammar g) {
        if (g.getSuperGrammarName() == null) {    // at root
            return g;
        }
        // return root of super.
        Grammar sg = g.getSuperGrammar();
        if (sg == null) return g;    // return this grammar if super missing
        return findRoot(sg);
    }
View Full Code Here

    /** Return true if hierarchy is complete, false if not */
    public boolean verifyThatHierarchyIsComplete() {
        boolean complete = true;
        // Make a pass to ensure all grammars are defined
        for (Enumeration e = symbols.elements(); e.hasMoreElements();) {
            Grammar c = (Grammar)e.nextElement();
            if (c.getSuperGrammarName() == null) {
                continue;    // at root: ignore predefined roots
            }
            Grammar superG = c.getSuperGrammar();
            if (superG == null) {
                antlrTool.toolError("grammar " + c.getSuperGrammarName() + " not defined");
                complete = false;
                symbols.remove(c.getName()); // super not defined, kill sub
            }
        }

        if (!complete) return false;

        // Make another pass to set the 'type' field of each grammar
        // This makes it easy later to ask a grammar what its type
        // is w/o having to search hierarchy.
        for (Enumeration e = symbols.elements(); e.hasMoreElements();) {
            Grammar c = (Grammar)e.nextElement();
            if (c.getSuperGrammarName() == null) {
                continue;    // ignore predefined roots
            }
            c.setType(findRoot(c).getName());
        }

        return true;
    }
View Full Code Here

    protected Hashtable files;  // table of grammar files read in
    protected org.jostraca.comp.antlr.Tool antlrTool;

    public Hierarchy(org.jostraca.comp.antlr.Tool tool) {
        this.antlrTool = tool;
        LexerRoot = new Grammar(tool, "Lexer", null, null);
        ParserRoot = new Grammar(tool, "Parser", null, null);
        TreeParserRoot = new Grammar(tool, "TreeParser", null, null);
        symbols = new Hashtable(10);
        files = new Hashtable(10);

        LexerRoot.setPredefined(true);
        ParserRoot.setPredefined(true);
View Full Code Here

    }

    public void expandGrammarsInFile(String fileName) {
        GrammarFile f = getFile(fileName);
        for (Enumeration e = f.getGrammars().elements(); e.hasMoreElements();) {
            Grammar g = (Grammar)e.nextElement();
            g.expandInPlace();
        }
    }
View Full Code Here

    public Grammar findRoot(Grammar g) {
        if (g.getSuperGrammarName() == null) {    // at root
            return g;
        }
        // return root of super.
        Grammar sg = g.getSuperGrammar();
        if (sg == null) return g;    // return this grammar if super missing
        return findRoot(sg);
    }
View Full Code Here

    /** Return true if hierarchy is complete, false if not */
    public boolean verifyThatHierarchyIsComplete() {
        boolean complete = true;
        // Make a pass to ensure all grammars are defined
        for (Enumeration e = symbols.elements(); e.hasMoreElements();) {
            Grammar c = (Grammar)e.nextElement();
            if (c.getSuperGrammarName() == null) {
                continue;    // at root: ignore predefined roots
            }
            Grammar superG = c.getSuperGrammar();
            if (superG == null) {
                antlrTool.toolError("grammar " + c.getSuperGrammarName() + " not defined");
                complete = false;
                symbols.remove(c.getName()); // super not defined, kill sub
            }
        }

        if (!complete) return false;

        // Make another pass to set the 'type' field of each grammar
        // This makes it easy later to ask a grammar what its type
        // is w/o having to search hierarchy.
        for (Enumeration e = symbols.elements(); e.hasMoreElements();) {
            Grammar c = (Grammar)e.nextElement();
            if (c.getSuperGrammarName() == null) {
                continue;    // ignore predefined roots
            }
            c.setType(findRoot(c).getName());
        }

        return true;
    }
View Full Code Here

    Hierarchy hier, String file
  ) throws RecognitionException, TokenStreamException {
   
    Token  hdr = null;
   
      Grammar gr;
      IndexedVector opt=null;
   
   
    try {      // for error handling
      {
      _loop265:
      do {
        if ((LA(1)==HEADER_ACTION)) {
          hdr = LT(1);
          match(HEADER_ACTION);
          hier.getFile(file).addHeaderAction(hdr.getText());
        }
        else {
          break _loop265;
        }
       
      } while (true);
      }
      {
      switch ( LA(1)) {
      case OPTIONS_START:
      {
        opt=optionSpec(null);
        break;
      }
      case EOF:
      case ACTION:
      case LITERAL_class:
      {
        break;
      }
      default:
      {
        throw new NoViableAltException(LT(1), getFilename());
      }
      }
      }
      {
      _loop268:
      do {
        if ((LA(1)==ACTION||LA(1)==LITERAL_class)) {
          gr=class_def(file, hier);
         
                if ( gr!=null && opt!=null ) {
                  hier.getFile(file).setOptions(opt);
                }
                if ( gr!=null ) {
                  gr.setFileName(file);
                  hier.addGrammar(gr);
                }
               
        }
        else {
View Full Code Here

  }
 
  public final Grammar  class_def(
    String file, Hierarchy hier
  ) throws RecognitionException, TokenStreamException {
    Grammar gr;
   
    Token  preamble = null;
    Token  sub = null;
    Token  sup = null;
    Token  tk = null;
    Token  memberA = null;
   
      gr=null;
      IndexedVector rules = new IndexedVector(100);
      IndexedVector classOptions = null;
      String sc = null;
   
   
    try {      // for error handling
      {
      switch ( LA(1)) {
      case ACTION:
      {
        preamble = LT(1);
        match(ACTION);
        break;
      }
      case LITERAL_class:
      {
        break;
      }
      default:
      {
        throw new NoViableAltException(LT(1), getFilename());
      }
      }
      }
      match(LITERAL_class);
      sub = LT(1);
      match(ID);
      match(LITERAL_extends);
      sup = LT(1);
      match(ID);
      {
      switch ( LA(1)) {
      case SUBRULE_BLOCK:
      {
        sc=superClass();
        break;
      }
      case SEMI:
      {
        break;
      }
      default:
      {
        throw new NoViableAltException(LT(1), getFilename());
      }
      }
      }
      match(SEMI);
     
            gr = (Grammar)hier.getGrammar(sub.getText());
            if ( gr!=null ) {
      //        antlr.Tool.toolError("redefinition of grammar "+gr.getName()+" ignored");
              gr=null;
              throw new SemanticException("redefinition of grammar "+sub.getText(), file, sub.getLine(), sub.getColumn());
            }
            else {
              gr = new Grammar(hier.getTool(), sub.getText(), sup.getText(), rules);
              gr.superClass=sc;
              if ( preamble!=null ) {
                gr.setPreambleAction(preamble.getText());
              }
            }
         
      {
      switch ( LA(1)) {
      case OPTIONS_START:
      {
        classOptions=optionSpec(gr);
        break;
      }
      case ACTION:
      case ID:
      case TOKENS_SPEC:
      case LITERAL_protected:
      case LITERAL_private:
      case LITERAL_public:
      {
        break;
      }
      default:
      {
        throw new NoViableAltException(LT(1), getFilename());
      }
      }
      }
     
          if ( gr!=null ) {
            gr.setOptions(classOptions);
          }
         
      {
      switch ( LA(1)) {
      case TOKENS_SPEC:
      {
        tk = LT(1);
        match(TOKENS_SPEC);
        gr.setTokenSection(tk.getText());
        break;
      }
      case ACTION:
      case ID:
      case LITERAL_protected:
      case LITERAL_private:
      case LITERAL_public:
      {
        break;
      }
      default:
      {
        throw new NoViableAltException(LT(1), getFilename());
      }
      }
      }
      {
      switch ( LA(1)) {
      case ACTION:
      {
        memberA = LT(1);
        match(ACTION);
        gr.setMemberAction(memberA.getText());
        break;
      }
      case ID:
      case LITERAL_protected:
      case LITERAL_private:
View Full Code Here

TOP

Related Classes of org.jostraca.comp.antlr.preprocessor.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.