Package org.allspice.parser

Examples of org.allspice.parser.Rule


   * @throws StrandedSymbol
   * @throws InvalidStartRule
   */
  private DefaultTranslationMapper createMapper() throws StateConflict, InvalidStartRule, StrandedSymbol {
    DefaultTranslationMapper mapper = new DefaultTranslationMapper() ;
    mapper.addTranslation(new Rule("E'","E"),new TopTrans()) ;
    mapper.addTranslation(new Rule("E","E","+","F"),new PlusTrans()) ;
    mapper.addTranslation(new Rule("E","F"),new FacTrans()) ;
    mapper.addTranslation(new Rule("F","F","*","T"),new TimesTrans()) ;
    mapper.addTranslation(new Rule("F","T"),new TermTrans()) ;
    mapper.addTranslation(new Rule("T","id"),new IdTrans()) ;
    mapper.addTranslation(new Rule("T","(","E",")"),new ParenTrans()) ;
    return mapper;
  }
View Full Code Here


   * @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>(),
      new Tree23Map<Rule,Integer>()) ;
    ParseTable table = ParserGenerator.createParseTable(g);
    return new AugmentedParseTableImpl(new DefaultTranslationMapper(),table) ;
View Full Code Here

        if (!l.isEmpty()) {
          if (l.get(l.size() - 1).code != null) {
            l.remove(l.size() - 1) ;
          }
        }
        Rule r = createRule(def.lhs,l);
        for(NamedRhs rhsitem: def.rhs) {
          if (rhsitem.assoc != null) {
            assoc = assoc.insert(rhsitem.getSym(),rhsitem.assoc) ;
            precedence = precedence.insert(rhsitem.getSym(),Integer.valueOf(currPrec)) ;
          }
        }
        rules.add(r) ;
        rprecedence = rprecedence.insert(r,Integer.valueOf(currPrec)) ;
        for(NamedRhs rhsitem: l) {
          if (rhsitem.code != null) {
            rules.add(new Rule(rhsitem.getSym())) ;
          }
        }
      }
      currPrec++ ;
    }
View Full Code Here

  private static Rule createRule(String lhs,Collection<NamedRhs> rhs) {
    List<String> rulerhs = new ArrayList<String>() ;
    for(NamedRhs r: rhs) {
      rulerhs.add(r.getSym()) ;
    }
    Rule r = new Rule(lhs,rulerhs) ;
    return r;
  }
View Full Code Here

    writer.write(code+"\n}\n") ;
    List<String> srhs = new ArrayList<String>() ;
    for(NamedRhs nrhs: rhs) {
      srhs.add(nrhs.getSym()) ;
    }
    rulenums.put(new Rule(lhs,srhs), new RID(rulenum,args)) ;
    writer.write("private static final Rule RULE"+rulenum+" = "+newRule(new Rule(lhs,srhs))+";\n") ;
  }
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

  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
   */
  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"),
      new Rule("T","id"),
      new Rule("T","(","E",")")),
      new Tree23Map<String,AssocType>(),
      new Tree23Map<String,Integer>(),
      new Tree23Map<Rule,Integer>()) ;
    return g;
  }
View Full Code Here

   * @throws StrandedSymbol
   * @throws InvalidStartRule
   */
  private AugmentedParseTable createParseTable() throws StateConflict, InvalidStartRule, StrandedSymbol {
    DefaultTranslationMapper mapper = createMapper() ;
    final Rule times = new Rule("E","E","*","E");
    final Rule plus = new Rule("E","E","+","E");
    ImmutableMap<String,AssocType> assoc = new Tree23Map<String,AssocType>() ;
    assoc = assoc.insert("+", AssocType.left) ;
    assoc = assoc.insert("*", AssocType.left) ;
    ImmutableMap<String,Integer> prec = new Tree23Map<String,Integer>() ;
    prec = prec.insert("*", Integer.valueOf(1)) ;
View Full Code Here

   * @throws StrandedSymbol
   * @throws InvalidStartRule
   */
  private DefaultTranslationMapper createMapper() throws StateConflict, InvalidStartRule, StrandedSymbol {
    DefaultTranslationMapper table = new DefaultTranslationMapper() ;
    table.addTranslation(new Rule("E'","E"),new TopTrans()) ;
    final Rule plus = new Rule("E","E","+","E");
    table.addTranslation(plus,new PlusTrans()) ;
    final Rule times = new Rule("E","E","*","E");
    table.addTranslation(times,new TimeTrans()) ;
    table.addTranslation(new Rule("E","id"),new IdTrans()) ;
    table.addTranslation(new Rule("E","(","E",")"),new ParenTrans()) ;
    return table;
  }
View Full Code Here

TOP

Related Classes of org.allspice.parser.Rule

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.