Ejemplo n.º 1
0
public static int Parse (string s, string/*!*/ filename, out /*maybe null*/ Program program, bool useBaseName=false) /* throws System.IO.IOException */ {
  Contract.Requires(s != null);
  Contract.Requires(filename != null);

  byte[]/*!*/ buffer = cce.NonNull(UTF8Encoding.Default.GetBytes(s));
  MemoryStream ms = new MemoryStream(buffer,false);
  Errors errors = new Errors();
  Scanner scanner = new Scanner(ms, errors, filename, useBaseName);

  Parser parser = new Parser(scanner, errors, false);
  parser.Parse();
  if (parser.errors.count == 0)
  {
    program = parser.Pgm;
    program.ProcessDatatypeConstructors();
    return 0;
  }
  else
  {
    program = null;
    return parser.errors.count;
  }
}
Ejemplo n.º 2
0
public Parser(Scanner/*!*/ scanner, Errors/*!*/ errors, bool disambiguation)
 : this(scanner, errors)
{
  // initialize readonly fields
  Pgm = new Program();
  dummyExpr = new LiteralExpr(Token.NoToken, false);
  dummyCmd = new AssumeCmd(Token.NoToken, dummyExpr);
  dummyBlock = new Block(Token.NoToken, "dummyBlock", new List<Cmd>(), new ReturnCmd(Token.NoToken));
  dummyType = new BasicType(Token.NoToken, SimpleType.Bool);
  dummyExprSeq = new List<Expr> ();
  dummyTransferCmd = new ReturnCmd(Token.NoToken);
  dummyStructuredCmd = new BreakCmd(Token.NoToken, null);
}
Ejemplo n.º 3
0
/*--------------------------------------------------------------------------*/


	public Parser(Scanner/*!*/ scanner, Errors/*!*/ errors) {
		this.scanner = scanner;
		this.errors = errors;
		Token/*!*/ tok = new Token();
		tok.val = "";
		this.la = tok;
		this.t = new Token(); // just to satisfy its non-null constraint
	}
Ejemplo n.º 4
0
//	[NotDelayed]
	public Scanner (Stream/*!*/ s, Errors/*!*/ errorHandler, string/*!*/ fileName, bool useBaseName = false) : base() {
	  Contract.Requires(s != null);
	  Contract.Requires(errorHandler != null);
	  Contract.Requires(fileName != null);
		pt = tokens = new Token();  // first token is a dummy
		t = new Token(); // dummy because t is a non-null field
		this._buffer = new Buffer(s, true);
		this.errorHandler = errorHandler;
		this.Filename = useBaseName? GetBaseName(fileName) : fileName;
		Init();
	}
Ejemplo n.º 5
0
//	[NotDelayed]
	public Scanner (string/*!*/ fileName, Errors/*!*/ errorHandler, bool useBaseName = false) : base() {
	  Contract.Requires(fileName != null);
	  Contract.Requires(errorHandler != null);
		this.errorHandler = errorHandler;
		pt = tokens = new Token();  // first token is a dummy
		t = new Token(); // dummy because t is a non-null field
		try {
			Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
			this._buffer = new Buffer(stream, false);
			Filename = useBaseName? GetBaseName(fileName): fileName;
			Init();
		} catch (IOException) {
			throw new FatalError("Cannot open file " + fileName);
		}
	}
Ejemplo n.º 6
0
 public BigBlocksResolutionContext(StmtList stmtList, Errors errorHandler)
 {
     Contract.Requires(errorHandler != null);
       Contract.Requires(stmtList != null);
       this.stmtList = stmtList;
       this.errorHandler = errorHandler;
       ComputeAllLabels(stmtList);
 }
Ejemplo n.º 7
0
 public Implementation(IToken/*!*/ tok,
   string/*!*/ name,
   List<TypeVariable>/*!*/ typeParams,
   List<Variable>/*!*/ inParams,
   List<Variable>/*!*/ outParams,
   List<Variable>/*!*/ localVariables,
   [Captured] StmtList/*!*/ structuredStmts,
   QKeyValue kv,
   Errors/*!*/ errorHandler)
   : base(tok, name, typeParams, inParams, outParams) {
   Contract.Requires(tok != null);
   Contract.Requires(name != null);
   Contract.Requires(typeParams != null);
   Contract.Requires(inParams != null);
   Contract.Requires(outParams != null);
   Contract.Requires(localVariables != null);
   Contract.Requires(structuredStmts != null);
   Contract.Requires(errorHandler != null);
   LocVars = localVariables;
   StructuredStmts = structuredStmts;
   BigBlocksResolutionContext ctx = new BigBlocksResolutionContext(structuredStmts, errorHandler);
   Blocks = ctx.Blocks;
   BlockPredecessorsComputed = false;
   scc = null;
   Attributes = kv;
 }
Ejemplo n.º 8
0
 public Implementation(IToken tok, string name, List<TypeVariable> typeParams, List<Variable> inParams, List<Variable> outParams, List<Variable> localVariables, [Captured] StmtList structuredStmts, Errors errorHandler)
   : this(tok, name, typeParams, inParams, outParams, localVariables, structuredStmts, null, errorHandler) {
   Contract.Requires(errorHandler != null);
   Contract.Requires(structuredStmts != null);
   Contract.Requires(localVariables != null);
   Contract.Requires(outParams != null);
   Contract.Requires(inParams != null);
   Contract.Requires(typeParams != null);
   Contract.Requires(name != null);
   Contract.Requires(tok != null);
   //:this(tok, name, typeParams, inParams, outParams, localVariables, structuredStmts, null, errorHandler);
 }