Search in sources :

Example 1 with ParseTree

use of br.ufpe.cin.if688.parser.ParseTree in project if688.github.io by if688.

the class App method main.

public static void main(String[] args) throws NotLL1Exception, ErrorOnParseException {
    /*
		 * Gramática de exemplo:
		 *  A -> aB
		 * 	B -> cC
		 * 	C -> d
		 * 
		 */
    Nonterminal start = new Nonterminal("A");
    Nonterminal B = new Nonterminal("B");
    Nonterminal C = new Nonterminal("C");
    Terminal a = new Terminal("a");
    Terminal c = new Terminal("c");
    Terminal d = new Terminal("d");
    List<GeneralSymbol> prodA = new ArrayList<GeneralSymbol>();
    prodA.add(a);
    prodA.add(B);
    List<GeneralSymbol> prodB = new ArrayList<GeneralSymbol>();
    prodB.add(c);
    prodB.add(C);
    List<GeneralSymbol> prodC = new ArrayList<GeneralSymbol>();
    prodC.add(d);
    Production fpA = new Production(start, prodA);
    Production pB = new Production(B, prodB);
    Production pC = new Production(C, prodC);
    Collection<Production> col = new ArrayList<Production>();
    col.add(fpA);
    col.add(pB);
    col.add(pC);
    List<Terminal> example = new ArrayList<Terminal>();
    example.add(a);
    example.add(c);
    example.add(d);
    Grammar g = new Grammar(col, start);
    Map<Nonterminal, Set<GeneralSymbol>> first = SetGenerator.getFirst(g);
    Map<Nonterminal, Set<GeneralSymbol>> follow = SetGenerator.getFollow(g, first);
    Map<LL1Key, List<GeneralSymbol>> table = Table.createTable(g);
    Parser parser = ParserGenerator.createParser(g);
    ParseTree parseTree = ParserUtils.parseSequence(parser, example);
    System.out.println("Exemplo 1:\n" + "A -> aB\n" + "B -> cC\n" + "C -> d");
    System.out.println("Conjunto first: " + first.toString());
    System.out.println("Conjunto follow: " + follow.toString());
    System.out.println("Tabela de parsing: " + table.toString());
    System.out.println("Exemplo de parsing: " + parseTree.toString() + "\n");
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) Parser(br.ufpe.cin.if688.parser.Parser) LL1Key(br.ufpe.cin.if688.table.LL1Key) ArrayList(java.util.ArrayList) List(java.util.List) ParseTree(br.ufpe.cin.if688.parser.ParseTree)

Aggregations

ParseTree (br.ufpe.cin.if688.parser.ParseTree)1 Parser (br.ufpe.cin.if688.parser.Parser)1 LL1Key (br.ufpe.cin.if688.table.LL1Key)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1