Package org.allspice.parser

Examples of org.allspice.parser.Grammar


   * @throws StrandedSymbol
   * @throws InvalidStartRule
   */
  private AugmentedParseTable createParseTable() throws StateConflict, InvalidStartRule, StrandedSymbol {
    DefaultTranslationMapper mapper = createMapper();
    Grammar g = new Grammar("E'",mapper.rules.keySet(),
        new Tree23Map<String,AssocType>(),
        new Tree23Map<String,Integer>(),
        new Tree23Map<Rule,Integer>()) ;
    return new AugmentedParseTableImpl(mapper,ParserGenerator.createParseTable(g));
  }
View Full Code Here


   * @throws StateConflict
   * @throws StrandedSymbol
   * @throws InvalidStartRule
   */
  private AugmentedParseTable createParseTable() throws StateConflict, InvalidStartRule, StrandedSymbol {
    Grammar g = new Grammar("E'",Arrays.asList(
      new Rule("E'","E","{"),
      new Rule("E"),
      new Rule("E","E","id")),
      new Tree23Map<String,AssocType>(),
      new Tree23Map<String,Integer>(),
View Full Code Here

          }
        }
      }
      currPrec++ ;
    }
    Grammar g = new Grammar(start,rules,assoc,precedence,rprecedence) ;
    return g.setConflictAllowed(ambig) ;
  }
View Full Code Here

  }
 
  public static Pgen parsePGEN(Reader r) throws SyntaxError {
    Pgen parsedg;
    DefaultTranslationMapper mapper = new DefaultTranslationMapper() ;
    Grammar g ;
    mapper.addTranslation(new Rule(FILE),new CreateGrammarTrans()) ;
    mapper.addTranslation(new Rule(FILE,FILE,TYPE,GENERIC_TYPE,SYMLIST,";"),new AddTypeTrans()) ;
    mapper.addTranslation(new Rule(FILE,FILE,RULEDEF),new AddRuleDefToFile()) ;
    mapper.addTranslation(new Rule(FILE,FILE,"(",RULEBLOCK,")"),new AddEquPrecToFile()) ;
    mapper.addTranslation(new Rule(FILE,FILE,START,SYM),new CreateStartTrans()) ;
    mapper.addTranslation(new Rule(FILE,FILE,EXTEND,GENERIC_TYPE),new ExtendsTrans()) ;
    mapper.addTranslation(new Rule(FILE,FILE,IMPORT,JAVATYPE),new ImportTrans()) ;
    mapper.addTranslation(new Rule(FILE,FILE,IMPORT,JAVATYPE,".","*"),new ImportTransStar()) ;
    mapper.addTranslation(new Rule(FILE,FILE,AMBIG),new Ambig()) ;
    mapper.addTranslation(new Rule(RULEBLOCK),new EmptyRuleBlock()) ;
    mapper.addTranslation(new Rule(RULEBLOCK,RULEBLOCK,RULEDEF),new AddRuleDef()) ;
    mapper.addTranslation(new Rule(RULEDEF,SYM,":",RHS,";"),new CreateRuleTrans()) ;
    mapper.addTranslation(new Rule(ATTRS),new NewAttrTrans()) ;
    mapper.addTranslation(new Rule(ATTRS,NON),new AddNoneTrans()) ;
    mapper.addTranslation(new Rule(ATTRS,LEFT),new AddLeftTrans()) ;
    mapper.addTranslation(new Rule(ATTRS,RIGHT),new AddRightTrans()) ;
    mapper.addTranslation(new Rule(RHS),new EmptyRhsTrans()) ;
    mapper.addTranslation(new Rule(RHS,RHS,CODE,VAR_OPT),new BuildNoTrans()) ;
    mapper.addTranslation(new Rule(RHS,RHS,SYM,ATTRS,VAR_OPT),new BuildRhsTrans()) ;
    mapper.addTranslation(new Rule(SYMLIST),new EmptySymList()) ;
    mapper.addTranslation(new Rule(SYMLIST,SYMLIST,SYM),new BuildSymList()) ;
    mapper.addTranslation(new Rule(SYM,QUOTEDSTRING),new MakeIdTrans()) ;
    mapper.addTranslation(new Rule(SYM,ID),new MakeIdTrans()) ;
    mapper.addTranslation(new Rule(VAR_OPT),new EmptyVar()) ;
    mapper.addTranslation(new Rule(VAR_OPT,"=",ID),new IdVar()) ;
    mapper.addTranslation(new Rule(JAVATYPE,ID),new TypeFromId()) ;
    mapper.addTranslation(new Rule(JAVATYPE,JAVATYPE,".",ID),new TypeByConstruction()) ;
    mapper.addTranslation(new Rule(GENERIC_TYPE,JAVATYPE),new SimpleType()) ;
    mapper.addTranslation(new Rule(GENERIC_TYPE,JAVATYPE,GENERIC),new GenericType()) ;
    try {
      g = new Grammar(S,new ConcatCollection<Rule>(mapper.rules.keySet(),new Rule(S,FILE)),new Tree23Map<String,AssocType>(),
          new Tree23Map<String,Integer>(),
          new Tree23Map<Rule,Integer>()) ;
    } catch (InvalidStartRule e) {
      throw new RuntimeException(e) ;
    } catch (StrandedSymbol e) {
View Full Code Here

    try {
      parsedg = PGENParser.parsePGEN(r);
    } catch (SyntaxError e1) {
      throw new GrammarIsInvalid(e1) ;
    }
    Grammar theGrammar ;
    try {
      theGrammar = parsedg.getGrammar() ;
    } catch (InvalidStartRule e) {
      throw new GrammarIsInvalid(e) ;
    } catch (StrandedSymbol e) {
View Full Code Here

  }

  public static Tok parseTok(Reader r) throws SyntaxError {
    Tok parsedg;
    DefaultTranslationMapper mapper = new DefaultTranslationMapper() ;
    Grammar g ;
    mapper.addTranslation(new Rule("explist"),new explist_base()) ;
    mapper.addTranslation(new Rule("type","ID"),new simpleType()) ;
    mapper.addTranslation(new Rule("type","type",".","ID"),new dotType()) ;
    mapper.addTranslation(new Rule("explist","explist","REGEXP","CODE",";"),new explist_add()) ;
    mapper.addTranslation(new Rule("explist","explist","ID","REGEXP"),new explist_addsymlib()) ;
    mapper.addTranslation(new Rule("explist","explist","EXTENDS","type"),new explist_extends()) ;
    mapper.addTranslation(new Rule("explist","explist","IMPORT","type"),new import_add()) ;
    mapper.addTranslation(new Rule("explist","explist","IMPORT","type",".","*"),new import_addstar()) ;
    try {
      g = new Grammar("S",new ConcatCollection<Rule>(mapper.rules.keySet(),new Rule("S","explist")),new Tree23Map<String,AssocType>(),
          new Tree23Map<String,Integer>(),
          new Tree23Map<Rule,Integer>()) ;
    } catch (InvalidStartRule e) {
      throw new RuntimeException(e) ;
    } catch (StrandedSymbol e) {
View Full Code Here

   * @throws StrandedSymbol
   * @throws InvalidStartRule
   *
   */
  public void test0() throws IOException, InvalidStartRule, StrandedSymbol {
    Grammar g = createGrammar() ;
    ObjectOutputStream oos = new ObjectOutputStream(new ByteArrayOutputStream()) ;
    oos.writeObject(g) ;
  }
View Full Code Here

   * @throws StateConflict
   * @throws StrandedSymbol
   * @throws InvalidStartRule
   */
  private ParseTable createParseTable() throws StateConflict, InvalidStartRule, StrandedSymbol {
    Grammar g = createGrammar();
    ParseTable table = ParserGenerator.createParseTable(g);
    return table;
  }
View Full Code Here

   * @return the grammar
   * @throws StrandedSymbol
   * @throws InvalidStartRule
   */
  private static Grammar createGrammar() throws InvalidStartRule, StrandedSymbol {
    Grammar g = new Grammar("E'",Arrays.asList(
      new Rule("E'","E"),
      new Rule("E","E","+","F"),
      new Rule("E","F"),
      new Rule("F","F","*","T"),
      new Rule("F","T"),
View Full Code Here

    prec = prec.insert("*", Integer.valueOf(1)) ;
    prec = prec.insert("+", Integer.valueOf(2)) ;
    ImmutableMap<Rule,Integer> rprec = new Tree23Map<Rule,Integer>() ;
    rprec = rprec.insert(times,Integer.valueOf(1)) ;
    rprec = rprec.insert(plus,Integer.valueOf(2)) ;
    Grammar g = new Grammar("E'",mapper.rules.keySet(),assoc,prec,rprec) ;
    return new AugmentedParseTableImpl(mapper,ParserGenerator.createParseTable(g));
  }
View Full Code Here

TOP

Related Classes of org.allspice.parser.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.