Package org.rascalmpl.test.parser

Source Code of org.rascalmpl.test.parser.EpsilonList

/*******************************************************************************
* Copyright (c) 2009-2011 CWI
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:

*   * Jurgen J. Vinju - Jurgen.Vinju@cwi.nl - CWI
*   * Arnold Lankamp - Arnold.Lankamp@cwi.nl
*******************************************************************************/
package org.rascalmpl.test.parser;

import java.io.IOException;
import java.io.StringReader;

import org.eclipse.imp.pdb.facts.IConstructor;
import org.eclipse.imp.pdb.facts.ISourceLocation;
import org.eclipse.imp.pdb.facts.IValue;
import org.eclipse.imp.pdb.facts.io.StandardTextReader;
import org.rascalmpl.parser.gtd.SGTDBF;
import org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener;
import org.rascalmpl.parser.gtd.stack.AbstractStackNode;
import org.rascalmpl.parser.gtd.stack.EpsilonStackNode;
import org.rascalmpl.parser.gtd.stack.ListStackNode;
import org.rascalmpl.parser.gtd.stack.NonTerminalStackNode;
import org.rascalmpl.parser.uptr.UPTRNodeFactory;
import org.rascalmpl.values.ValueFactoryFactory;
import org.rascalmpl.values.uptr.Factory;

/*
S ::= A+
A ::= epsilon
*/
@SuppressWarnings({"unchecked", "cast"})
public class EpsilonList extends SGTDBF<IConstructor, IConstructor, ISourceLocation> implements IParserTest{
  private final static IConstructor SYMBOL_START_S = VF.constructor(Factory.Symbol_Sort, VF.string("S"));
  private final static IConstructor SYMBOL_A = VF.constructor(Factory.Symbol_Sort, VF.string("A"));
  private final static IConstructor SYMBOL_PLUS_LIST_A = VF.constructor(Factory.Symbol_IterPlus, SYMBOL_A);
  private final static IConstructor SYMBOL_epsilon = VF.constructor(Factory.Symbol_Empty);
 
  private final static IConstructor PROD_S_PLUSLISTA = VF.constructor(Factory.Production_Default,  SYMBOL_START_S, VF.list(SYMBOL_PLUS_LIST_A), VF.set());
  private final static IConstructor PROD_PLUSLISTA = VF.constructor(Factory.Production_Regular, SYMBOL_PLUS_LIST_A);
  private final static IConstructor PROD_A_epsilon = VF.constructor(Factory.Production_Default,  SYMBOL_A, VF.list(SYMBOL_epsilon), VF.set());
 
  private final static AbstractStackNode<IConstructor> NONTERMINAL_START_S = new NonTerminalStackNode<IConstructor>(AbstractStackNode.START_SYMBOL_ID, 0, "S");
  private final static AbstractStackNode<IConstructor> NONTERMINAL_A0 = new NonTerminalStackNode<IConstructor>(0, 0, "A");
  private final static AbstractStackNode<IConstructor> LIST1 = new ListStackNode<IConstructor>(1, 0, PROD_PLUSLISTA, NONTERMINAL_A0, true);
  private final static AbstractStackNode<IConstructor> EPSILON2 = new EpsilonStackNode<IConstructor>(3, 0);
 
  private final static AbstractStackNode<IConstructor>[] S_EXPECT_1 = (AbstractStackNode<IConstructor>[]) new AbstractStackNode[1];
  static{
    S_EXPECT_1[0] = LIST1;
    S_EXPECT_1[0].setProduction(S_EXPECT_1);
    S_EXPECT_1[0].setAlternativeProduction(PROD_S_PLUSLISTA);
  }
 
  private final static AbstractStackNode<IConstructor>[] A_EXPECT_1 = (AbstractStackNode<IConstructor>[]) new AbstractStackNode[1];
  static{
    A_EXPECT_1[0] = EPSILON2;
    A_EXPECT_1[0].setProduction(A_EXPECT_1);
    A_EXPECT_1[0].setAlternativeProduction(PROD_A_epsilon);
  }
 
  public EpsilonList(){
    super();
  }
 
  public AbstractStackNode<IConstructor>[] S(){
    return (AbstractStackNode<IConstructor>[]) new AbstractStackNode[]{S_EXPECT_1[0]};
  }
 
  public AbstractStackNode<IConstructor>[] A(){
    return (AbstractStackNode<IConstructor>[]) new AbstractStackNode[]{A_EXPECT_1[0]};
  }
 
  public IConstructor executeParser(){
    return parse(NONTERMINAL_START_S, null, "".toCharArray(), new DefaultNodeFlattener<IConstructor, IConstructor, ISourceLocation>(), new UPTRNodeFactory());
  }
 
  public IValue getExpectedResult() throws IOException{
    String expectedInput = "appl(prod(sort(\"S\"),[iter(sort(\"A\"))],{}),[appl(regular(iter(sort(\"A\"))),[amb({appl(regular(iter(sort(\"A\"))),[appl(prod(sort(\"A\"),[empty()],{}),[])]),cycle(iter(sort(\"A\")),1)})])])";
    return new StandardTextReader().read(ValueFactoryFactory.getValueFactory(), Factory.uptr, Factory.Tree, new StringReader(expectedInput));
  }
 
  public static void main(String[] args){
    EpsilonList el = new EpsilonList();
    IConstructor result = el.executeParser();
    System.out.println(result);
   
    System.out.println("S([A+(A()),A+(repeat(A())))]) <- good");
  }
}
TOP

Related Classes of org.rascalmpl.test.parser.EpsilonList

TOP
Copyright © 2018 www.massapi.com. 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.