Package aleGrammar

Examples of aleGrammar.GenSym


   
  }
 
  public String alegAstToSwiplAst () throws InvalidGrammarException {
   
    GenSym genSym = ast.genSym;
   
    Reductions reducts = new Reductions(ast);
    surfaceChecks(reducts);
   
    String res = "";
   
    for (AGEval.IFace i : aleg.interfaces)
      res += "interface(" + i.getName().toLowerCase() + ").\n";
    if (aleg.interfaces.size() == 0) res += "interface(" + fakeAttribute  + ") :- false.\n";

    boolean hasIA = false;
    for (AGEval.IFace i : aleg.interfaces) for (String attrib : i.getPubAttributes().keySet()) {
      res += "interfaceAttribute(" + i.getName().toLowerCase() + ", " + attrib.toLowerCase() + ").\n";
      hasIA = true;
    }
    if (!hasIA) res += "interfaceAttribute(" + fakeAttribute  + ", " + fakeAttribute  + ") :- false.\n";

    for (AGEval.Class c : aleg.classes)
      res += "class(" + c.getName().toLowerCase() + ", " + c.getInterface().getName().toLowerCase() + ").\n";   
    if (aleg.classes.size() == 0) res += "class(" + fakeAttribute  + ", " + fakeAttribute  + ") :- false.\n";
   
    boolean hasCC = false;
    for (AGEval.Class c : aleg.classes) for (String child : c.getChildMappings().keySet()) {
      if (chainLoopsChilds) {
        if ( ast.extendedClasses.get(c).multiChildren.containsKey(child)) {
          res += "classChild(" + c.getName().toLowerCase() + ", " + child.toLowerCase() + "unroll0, " + c.getChildByName(child).getName().toLowerCase() + ").\n";
          res += "classChild(" + c.getName().toLowerCase() + ", " + child.toLowerCase() + "unroll1, " + c.getChildByName(child).getName().toLowerCase() + ").\n";
          res += "classChild(" + c.getName().toLowerCase() + ", " + child.toLowerCase() + "unroll2, " + c.getChildByName(child).getName().toLowerCase() + ").\n";
          res += "classChild(" + c.getName().toLowerCase() + ", " + child.toLowerCase() + "unrolln, " + c.getChildByName(child).getName().toLowerCase() + ").\n";
        } else {
          res += "classChild(" + c.getName().toLowerCase() + ", " + child.toLowerCase() + ", " + c.getChildByName(child).getName().toLowerCase() + ").\n";         
        }
      } else {
        res += "classChild(" + c.getName().toLowerCase() + ", " + child.toLowerCase() + ", " + c.getChildByName(child).getName().toLowerCase() + ").\n";
      }
      hasCC = true;
    }
    if (!hasCC) res += "classChild(" + fakeAttribute  + ", " + fakeAttribute  + ", " + fakeAttribute  + ") :- false.\n";
   
   
    res += "classField(" + fakeAttribute  + ", " + fakeAttribute  + ") :- false.\n";
    for (AGEval.Class c : aleg.classes)  {
      res += "classField(" + c.getName().toLowerCase() + ", " + fakeAttribute + ").\n"; //used later to manipulate nullary functions
      for (String field : c.getPrivFields().keySet())   
        res += "classField(" + c.getName().toLowerCase() + ", " + field.toLowerCase() + ").\n";
    }   
    boolean hasIF = false;
    for (AGEval.IFace i : aleg.interfaces) for (String field : i.getPubFields().keySet()) {
        res += "interfaceField(" + i.getName().toLowerCase() + ", " + field.toLowerCase() + ").\n";
        hasIF = true;
    }
    if (!hasIF) res += "interfaceField(" + fakeAttribute  + ", " + fakeAttribute  + ") :- false.\n";
         
   
    if (!alreadyRan) res += ":- dynamic(assignment/5).\n"; //helps allow grammar to add phantom dependencies as part of query  
    boolean hasAs = false;
    for (AGEval.Class c : aleg.classes)  {
      //simple assignments
      if (chainLoopsChilds) {
        for (Assignment a : ast.assignments) {
          if (a._class == c && a.loopVar.equals("")) {
            if (a.isReduction) throw new InvalidGrammarException("Reduction in non-loop!");
            if (a._variables.size() == 0) {           
              String asgn = "assignment(" + c.getName().toLowerCase() + ", "
                  + attribBase(a._sink).toLowerCase() + ", " + attribName(a._sink).toLowerCase() + ", "
                  + "self, " + fakeAttribute + "). %a40\n"; //force scheduling of nullary    
                res += asgn;
 
            } else {
              for (String src : a._variables.keySet()) {
                if (src.contains("$$")) {
                  boolean isChild = !attribBase(src).toLowerCase().equals("self");
                  res += "assignment(" + c.getName().toLowerCase() + ", "
                    + attribBase(a._sink).toLowerCase() + ", " + attribName(a._sink).toLowerCase() + ", "
                    + "self, " + (isChild ? attribBase(src).toLowerCase() + "_" : "") + attribName(src.replace("$$", "_stepn")).toLowerCase() + "). %a41\n"; //change to _last?
                } else {
                  res += "assignment(" + c.getName().toLowerCase() + ", "
                      + attribBase(a._sink).toLowerCase() + ", " + attribName(a._sink).toLowerCase() + ", "
                      + attribBase(src).toLowerCase() + ", " + attribName(src).toLowerCase() + "). %a42\n";                        
                }
              }
            }
          }
        }
      } else {
        for (AGEval.Function func : c.getFunctions()) {        
          for (String src : func.getStringSrcs()) {
            String asgn = "assignment(" + c.getName().toLowerCase() + ", "
              + attribBase(func.myDest).toLowerCase() + ", " + func.getDestination().getExtVar().toLowerCase() + ", "
              + attribBase(src).toLowerCase() + ", " + attribName(src).toLowerCase() + "). %a43\n";    
            res += asgn;
          }
          if (func.getStringSrcs().length == 0) {
            String asgn = "assignment(" + c.getName().toLowerCase() + ", "
              + attribBase(func.myDest).toLowerCase() + ", " + func.getDestination().getExtVar().toLowerCase() + ", "
              + "self, " + fakeAttribute + "). %a44\n"; //force scheduling of nullary    
            res += asgn;
          }
          hasAs = true;
        }
      }
      //conds
      if (ast.condsTop.containsKey(c)) {
        for (Cond cond : ast.condsTop.get(c)) {
          res += condAssignments(genSym.fake(), c, cond, genSym, reducts);
          throw new InvalidGrammarException("Deprecated: conditionals");       
        }
      }
      //loop assignments
      for (ALEParser.Assignment asgn : ast.assignments)
View Full Code Here

TOP

Related Classes of aleGrammar.GenSym

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.