Package hampi.grammars

Examples of hampi.grammars.Grammar


import junit.framework.TestCase;

public class CYKTests extends TestCase{
  public void test1() throws Exception{
    String grammarFile = "tests/resources/test_cyk1.txt";
    Grammar g = new Parser(grammarFile).parse();
    System.out.println(g);
    CYKParser p = new CYKParser(g);
    List<ParseTree> parse = p.parse("s1 s2".split(" "), "S");
    assertTrue(!parse.isEmpty());
  }
View Full Code Here


    assertTrue(!parse.isEmpty());
  }

  public void test2() throws Exception{
    String grammarFile = "tests/resources/test_cyk1.txt";
    Grammar g = new Parser(grammarFile).parse();
    System.out.println(g);
    CYKParser p = new CYKParser(g);
    List<ParseTree> parse = p.parse("s1 s2 s1".split(" "), "S");
    assertTrue(parse.isEmpty());
  }
View Full Code Here

    assertTrue(parse.isEmpty());
  }

  public void test3() throws Exception{
    String grammarFile = "tests/resources/test_cyk2.txt";
    Grammar g = new Parser(grammarFile).parse();
    System.out.println(g);
    CYKParser p = new CYKParser(g);
    String s = "b a a b a";
    List<ParseTree> parse = p.parse(s.split(" "), "S");
    System.out.println(s);
View Full Code Here

    assertTrue(!parse.isEmpty());
  }

  public void test4() throws Exception{
    String grammarFile = "tests/resources/test_cyk2.txt";
    Grammar g = new Parser(grammarFile).parse();
    System.out.println(g);
    CYKParser p = new CYKParser(g);
    String s = "b a b a";
    List<ParseTree> parse = p.parse(s.split(" "), "S");
    assertTrue(parse.toString(), parse.isEmpty());
View Full Code Here

    assertTrue(parse.toString(), parse.isEmpty());
  }

  public void test5() throws Exception{
    String grammarFile = "tests/resources/test_cyk3.txt";
    Grammar g = new Parser(grammarFile).parse();
    System.out.println(g);
    CYKParser p = new CYKParser(g);
    String s = "a b b d a b";
    List<ParseTree> parse = p.parse(s.split(" "), "S");
    assertTrue(!parse.isEmpty());
View Full Code Here

    assertTrue(!parse.isEmpty());
  }

  public void test6() throws Exception{
    String grammarFile = "tests/resources/test_cyk3.txt";
    Grammar g = new Parser(grammarFile).parse();
    System.out.println(g);
    CYKParser p = new CYKParser(g);
    String s = "b a d";
    List<ParseTree> parse = p.parse(s.split(" "), "S");
    assertTrue(parse.toString(), parse.isEmpty());
View Full Code Here

    assertTrue(parse.toString(), parse.isEmpty());
  }

  public void testEcmascript1() 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 = "FunctionDeclaration";
    Grammar gCNF = new CNFConverter().convertToCNF(g, startSymbol, steps);

    CYKParser p = new CYKParser(gCNF);
    String s = "function <IDENTIFIER_NAME> ( ) { break ; }";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    assertTrue("cannot parse: " + s, !parse.isEmpty());
View Full Code Here

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

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

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

    CYKParser p = new CYKParser(gCNF);
    String s = "function <IDENTIFIER_NAME> ( ) { break ; }";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    assertTrue("cannot parse: " + s, !parse.isEmpty());
View Full Code Here

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

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

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

    CYKParser p = new CYKParser(gCNF);
    String s = "break ; ";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    assertTrue("cannot parse: " + s, !parse.isEmpty());
View Full Code Here

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

  public void testEcmascript4() 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 = "FunctionDeclaration";
    Grammar gCNF = new CNFConverter().convertToCNF(g, startSymbol, steps);

    CYKParser p = new CYKParser(gCNF);
    String s = "function <IDENTIFIER_NAME> ( ) { -- <HEX_INTEGER_LITERAL> >= - <STRING_LITERAL> typeof true , false }";
    List<ParseTree> parse = p.parse(s.split(" "), startSymbol);
    for (ParseTree parseTree : parse){
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.