Package hampi.grammars

Examples of hampi.grammars.Grammar


    assertTrue("cannot parse: " + s, !parse.isEmpty());
  }

  public void testEcmascript5() throws Exception{
    String grammarFile = "tests/resources/ecmascript.txt";
    Grammar g = new Parser(grammarFile).parse();
    assertTrue(!g.isCNF());

    List<Grammar> steps = new ArrayList<Grammar>();
    final String startSymbol = "Statement";
    Grammar gCNF = new CNFConverter().convertToCNF(g, startSymbol, steps);

    CYKParser p = new CYKParser(gCNF);
    String s = "-- <HEX_INTEGER_LITERAL> >= - <STRING_LITERAL>";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    for (ParseTree parseTree : parse){
View Full Code Here


    assertTrue("cannot parse: " + s, !parse.isEmpty());
  }

  public void testEcmascript6() throws Exception{
    String grammarFile = "tests/resources/ecmascript.txt";
    Grammar g = new Parser(grammarFile).parse();
    assertTrue(!g.isCNF());

    List<Grammar> steps = new ArrayList<Grammar>();
    final String startSymbol = "Expression";
    Grammar gCNF = new CNFConverter().convertToCNF(g, startSymbol, steps);

    CYKParser p = new CYKParser(gCNF);
    String s = "typeof true , false";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    for (ParseTree parseTree : parse){
View Full Code Here

    assertTrue("cannot parse: " + s, !parse.isEmpty());
  }

  public void testEcmascript7() throws Exception{
    String grammarFile = "tests/resources/ecmascript.txt";
    Grammar g = new Parser(grammarFile).parse();
    assertTrue(!g.isCNF());

    List<Grammar> steps = new ArrayList<Grammar>();
    final String startSymbol = "AssignmentExpression";
    Grammar gCNF = new CNFConverter().convertToCNF(g, startSymbol, steps);

    CYKParser p = new CYKParser(gCNF);
    String s = "typeof true";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    for (ParseTree parseTree : parse){
View Full Code Here

    assertTrue("cannot parse: " + s, !parse.isEmpty());
  }

  public void testEcmascript8() throws Exception{
    String grammarFile = "tests/resources/ecmascript.txt";
    Grammar g = new Parser(grammarFile).parse();
    assertTrue(!g.isCNF());

    List<Grammar> steps = new ArrayList<Grammar>();
    final String startSymbol = "AssignmentExpression";
    Grammar gCNF = new CNFConverter().convertToCNF(g, startSymbol, steps);

    CYKParser p = new CYKParser(gCNF);
    String s = "false";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    for (ParseTree parseTree : parse){
View Full Code Here

import junit.framework.TestCase;

public class BoundingTests extends TestCase{
  public void testMultiCharTerminals() throws Exception{
    Grammar g = new Parser(GrammarTests.DIR + "test_multiCharTerminal.txt").parse();
    GrammarStringBounder gsb = new GrammarStringBounder();
    Regexp boundedRegexp = gsb.getBoundedRegexp(g, "program", 3, false);
    System.out.println(boundedRegexp);
    assertTrue(!boundedRegexp.matches("AB__"));
    assertTrue(boundedRegexp.matches("AB_"));
View Full Code Here

    assertTrue(!boundedRegexp.matches("AB__"));
    assertTrue(boundedRegexp.matches("AB_"));
  }

  public void test1() throws Exception{
    Grammar g = new Parser(GrammarTests.DIR + "test_generate_parent.txt").parse();
    GrammarStringBounder gsb = new GrammarStringBounder();
    Regexp boundedRegexp = gsb.getBoundedRegexp(g, "expr", 2, false);
    assertTrue(boundedRegexp.matches("()"));
    assertTrue(!boundedRegexp.matches("(())"));
  }
View Full Code Here

    assertTrue(boundedRegexp.matches("()"));
    assertTrue(!boundedRegexp.matches("(())"));
  }

  public void test2() throws Exception{
    Grammar g = new Parser(GrammarTests.DIR + "test_generate_parent.txt").parse();
    GrammarStringBounder gsb = new GrammarStringBounder();
    Regexp boundedRegexp = gsb.getBoundedRegexp(g, "expr", 3, false);
    assertNull(boundedRegexp);
  }
View Full Code Here

    Regexp boundedRegexp = gsb.getBoundedRegexp(g, "expr", 3, false);
    assertNull(boundedRegexp);
  }

  public void test3() throws Exception{
    Grammar g = new Parser(GrammarTests.DIR + "test_generate_parent.txt").parse();
    GrammarStringBounder gsb = new GrammarStringBounder();
    Regexp boundedRegexp = gsb.getBoundedRegexp(g, "expr", 4, false);
    System.out.println(boundedRegexp);
    assertTrue(!boundedRegexp.matches("()"));
    assertTrue(boundedRegexp.matches("(())"));
View Full Code Here

    assertTrue(!boundedRegexp.matches("(((("));

  }

  public void test4() throws Exception{
    Grammar g = new Parser(GrammarTests.DIR + "test_generate_parent.txt").parse();
    GrammarStringBounder gsb = new GrammarStringBounder();
    Regexp boundedRegexp = gsb.getBoundedRegexp(g, "expr", 5, false);
    assertNull(boundedRegexp);
  }
View Full Code Here

    Regexp boundedRegexp = gsb.getBoundedRegexp(g, "expr", 5, false);
    assertNull(boundedRegexp);
  }

  public void test5() throws Exception{
    Grammar g = new Parser(GrammarTests.DIR + "test_generate_parent.txt").parse();
    GrammarStringBounder gsb = new GrammarStringBounder();
    Regexp boundedRegexp = gsb.getBoundedRegexp(g, "expr", 150, false);
    assertNotNull(boundedRegexp);
  }
View Full Code Here

TOP

Related Classes of hampi.grammars.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.