Package edu.mit.csail.sdg.alloy4

Examples of edu.mit.csail.sdg.alloy4.ErrorSyntax


     * @throws ErrorSyntax if increment is less than one
     */
    public CommandScope(Pos pos, Sig sig, boolean isExact, int startingScope, int endingScope, int increment) throws ErrorSyntax {
        if (pos == null) pos = Pos.UNKNOWN;
        if (sig == null) throw new NullPointerException();
        if (startingScope < 0) throw new ErrorSyntax(pos, "Sig "+sig+" cannot have a negative starting scope ("+startingScope+")");
        if (endingScope < 0) throw new ErrorSyntax(pos, "Sig "+sig+" cannot have a negative ending scope ("+endingScope+")");
        if (endingScope < startingScope) throw new ErrorSyntax(pos, "Sig "+sig+" cannot have an ending scope ("+endingScope+") smaller than its starting scope ("+startingScope+")");
        if (startingScope == endingScope) increment = 1;
        if (increment < 1) throw new ErrorSyntax(pos, "Sig "+sig+"'s increment value cannot be "+increment+".\nThe increment must be 1 or greater.");
        this.pos = pos;
        this.sig = sig;
        this.isExact = isExact;
        this.startingScope = startingScope;
        this.endingScope = endingScope;
View Full Code Here


        this.decl2type = new LinkedHashMap<Variable,Pair<Type,Pos>>();
        this.originalOptions = opt;
        this.originalCommand = (originalCommand==null ? "" : originalCommand);
        this.bitwidth = bitwidth;
        this.maxseq = maxseq;
        if (bitwidth < 1)   throw new ErrorSyntax("Cannot specify a bitwidth less than 1");
        if (bitwidth > 30throw new ErrorSyntax("Cannot specify a bitwidth greater than 30");
        if (maxseq < 0)     throw new ErrorSyntax("The maximum sequence length cannot be negative.");
        if (maxseq > max()) throw new ErrorSyntax("With integer bitwidth of "+bitwidth+", you cannot have sequence length longer than "+max());
        kAtoms = ConstList.make(atoms);
        bounds = new Bounds(new Universe(kAtoms));
        factory = bounds.universe().factory();
        TupleSet sigintBounds = factory.noneOf(1);
        TupleSet seqidxBounds = factory.noneOf(1);
View Full Code Here

private final Symbol alloy_sym(String txt, int type) {
    Pos p = alloy_here(txt); return new Symbol(type, p, p);
}
private final Symbol alloy_string(String txt) throws Err {
    Pos p = alloy_here(txt);
    if (!Version.experimental) throw new ErrorSyntax(p, "String literal is not currently supported.");
    StringBuilder sb = new StringBuilder(txt.length());
    for(int i=0; i<txt.length(); i++) {
       char c = txt.charAt(i);
       if (c=='\r' || c=='\n') throw new ErrorSyntax(p, "String literal cannot span multiple lines; use \\n instead.");
       if (c=='\\') {
          i++;
          if (i>=txt.length()) throw new ErrorSyntax(p, "String literal cannot end with a single \\");
          c = txt.charAt(i);
          if (c=='n') c='\n'; else if (c!='\'' && c!='\"' && c!='\\') throw new ErrorSyntax(p, "String literal currenty only supports\nfour escape sequences: \\\\, \\n, \\\', and \\\"");
       }
       sb.append(c);
    }
    txt = sb.toString();
    if (txt.length()==2) throw new ErrorSyntax(p, "Empty string is not allowed; try rewriting your model to use an empty set instead.");
    return new Symbol(CompSym.STR, p, ExprConstant.Op.STRING.make(p, txt));
}
View Full Code Here

    Pos p=alloy_here(txt);
    int n=0;
    try {
       n=Integer.parseInt(txt);
    } catch(NumberFormatException ex) {
       throw new ErrorSyntax(p, "The number "+txt+" is too large to be stored in a Java integer");
    }
    return new Symbol(CompSym.NUMBER, p, ExprConstant.Op.NUMBER.make(p, n));
}
View Full Code Here

        case 81:
          { return alloy_sym(yytext(), CompSym.EXTENDS     );
          }
        case 136: break;
        case 1:
          { throw new ErrorSyntax(alloy_here(" "), "Syntax error at the "+yytext()+" character.");
          }
        case 137: break;
        case 26:
          { throw new ErrorSyntax(alloy_here(yytext()),"String literal is missing its closing \" character");
          }
        case 138: break;
        case 59:
          { return alloy_sym(yytext(), CompSym.FOR         );
          }
        case 139: break;
        case 28:
          { return alloy_num (yytext());
          }
        case 140: break;
        case 70:
          { return alloy_sym(yytext(), CompSym.IDEN        );
          }
        case 141: break;
        case 15:
          { return alloy_sym(yytext(), CompSym.LT          );
          }
        case 142: break;
        case 17:
          { return alloy_sym(yytext(), CompSym.AT          );
          }
        case 143: break;
        case 34:
          { return alloy_sym(yytext(), CompSym.RANGE       );
          }
        case 144: break;
        case 69:
          { return alloy_sym(yytext(), CompSym.UNIV        );
          }
        case 145: break;
        case 2:
          { return alloy_sym(yytext(), CompSym.NOT         );
          }
        case 146: break;
        case 49:
          { return alloy_sym(yytext(), CompSym.SET         );
          }
        case 147: break;
        case 6:
          { return alloy_sym(yytext(), CompSym.RPAREN      );
          }
        case 148: break;
        case 42:
          { return alloy_sym(yytext(), CompSym.IN          );
          }
        case 149: break;
        case 75:
          { return alloy_sym(yytext(), CompSym.CHECK       );
          }
        case 150: break;
        case 29:
          { return alloy_sym(yytext(), CompSym.AND         );
          }
        case 151: break;
        case 62:
          { return alloy_sym(yytext(), CompSym.SOME        );
          }
        case 152: break;
        case 74:
          { return alloy_sym(yytext(), CompSym.FACT        );
          }
        case 153: break;
        case 10:
          { return alloy_sym(yytext(), CompSym.MINUS       );
          }
        case 154: break;
        case 5:
          { return alloy_sym(yytext(), CompSym.LPAREN      );
          }
        case 155: break;
        case 65:
          { return alloy_sym(yytext(), CompSym.NONE        );
          }
        case 156: break;
        case 18:
          { return alloy_sym(yytext(), CompSym.LBRACKET    );
          }
        case 157: break;
        case 19:
          { return alloy_sym(yytext(), CompSym.RBRACKET    );
          }
        case 158: break;
        case 68:
          { return alloy_sym(yytext(), CompSym.ENUM        );
          }
        case 159: break;
        case 47:
          { return alloy_sym(yytext(), CompSym.ALL         );
          }
        case 160: break;
        case 83:
          { return alloy_sym(yytext(), CompSym.ABSTRACT    );
          }
        case 161: break;
        case 76:
          { return alloy_sym(yytext(), CompSym.ASSERT      );
          }
        case 162: break;
        case 61:
          { throw new ErrorSyntax(alloy_here(yytext()),"String literal cannot be followed by a legal identifier character.");
          }
        case 163: break;
        case 54:
          { return alloy_sym(yytext(), CompSym.LET         );
          }
        case 164: break;
        case 27:
          {
          }
        case 165: break;
        case 44:
          { throw new ErrorSyntax(alloy_here(yytext()),"Name cannot start with a number.");
          }
        case 166: break;
        default:
          if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
            zzAtEOF = true;
View Full Code Here

   public Expr desugar() throws ErrorSyntax {
      boolean hasDisjoint = false;
      for(Decl d: decls) {
         if (d.isPrivate!=null) {
            ExprHasName n = d.names.get(0);
            throw new ErrorSyntax(d.isPrivate.merge(n.pos), "Local variable \"" + n.label + "\" is always private already.");
         }
         if (d.disjoint2!=null) {
            ExprHasName n = d.names.get(d.names.size()-1);
            throw new ErrorSyntax(d.disjoint2.merge(n.pos), "Local variable \"" + n.label + "\" cannot be bound to a 'disjoint' expression.");
         }
         hasDisjoint = hasDisjoint || (d.names.size()>1 && d.disjoint != null);
      }
      if (!hasDisjoint) return this;
      TempList<Decl> newdecls = new TempList<Decl>(decls.size());
View Full Code Here

     */
    public static Expr make(Pos pos, ExprVar var, Expr expr, Expr sub) {
        if (expr.ambiguous) expr = expr.resolve(expr.type, null);
        JoinableList<Err> errs = var.errors.make(expr.errors).make(sub.errors);
        if (expr.mult!=0)
            errs = errs.make(new ErrorSyntax(expr.span(), "Multiplicity expression not allowed here."));
        if (sub.mult != 0)
            errs = errs.make(new ErrorSyntax(sub.span(), "Multiplicity expression not allowed here."));
        if (errs.size()==0 && var.type!=expr.type)
            if (var.type.is_int!=expr.type.is_int
             || var.type.is_bool!=expr.type.is_bool
             || var.type.arity()!=expr.type.arity())
                errs = errs.make(new ErrorType(var.span(), "This variable has type "+var.type+" but is bound to a value of type "+expr.type));
View Full Code Here

        return (y==null) ? (-1) : y;
    }

    /** Sets the scope for a sig; returns true iff the sig's scope is changed by this call. */
    private void sig2scope(Sig sig, int newValue) throws Err {
        if (sig.builtin)                throw new ErrorSyntax(cmd.pos, "Cannot specify a scope for the builtin signature \""+sig+"\"");
        if (!(sig instanceof PrimSig))  throw new ErrorSyntax(cmd.pos, "Cannot specify a scope for a subset signature \""+sig+"\"");
        if (newValue<0)                 throw new ErrorSyntax(cmd.pos, "Cannot specify a negative scope for sig \""+sig+"\"");
        int old=sig2scope(sig);
        if (old==newValue) return;
        if (old>=0)        throw new ErrorSyntax(cmd.pos, "Sig \""+sig+"\" already has a scope of "+old+", so we cannot set it to be "+newValue);
        sig2scope.put((PrimSig)sig, newValue);
        rep.scope("Sig "+sig+" scope <= "+newValue+"\n");
    }
View Full Code Here

        return sig==SIGINT || sig==SEQIDX || sig==STRING || ((sig instanceof PrimSig) && exact.containsKey(sig));
    }

    /** Make the given sig "exact". */
    private void makeExact(Pos pos, Sig sig) throws Err {
        if (!(sig instanceof PrimSig)) throw new ErrorSyntax(pos, "Cannot specify a scope for a subset signature \""+sig+"\"");
        exact.put(sig, sig);
    }
View Full Code Here

        exact.put(sig, sig);
    }

    /** Modifies the integer bitwidth of this solution's model (and sets the max sequence length to 0) */
    private void setBitwidth(Pos pos, int newBitwidth) throws ErrorAPI, ErrorSyntax {
        if (newBitwidth<1throw new ErrorSyntax(pos, "Cannot specify a bitwidth less than 1");
        if (newBitwidth>30) throw new ErrorSyntax(pos, "Cannot specify a bitwidth greater than 30");
        bitwidth = newBitwidth;
        maxseq = 0;
        sig2scope.put(SIGINT, 1<<bitwidth);
        sig2scope.put(SEQIDX, 0);
    }
View Full Code Here

TOP

Related Classes of edu.mit.csail.sdg.alloy4.ErrorSyntax

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.