public VarInfo(SemType type, Lexema location, string scope, int offset) { Type = type; Location = location; Params = new List <VarInfo>(); FullName = $"{scope}/{location.Tok}{{{offset}}}"; }
public IActionResult Index(SemType semType) { if (semType.SemesterType.Equals("odd")) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44336/api/type"); var post = client.PostAsJsonAsync <SemType>("type", semType); post.Wait(); var result = post.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Create", "FacultyChoice")); } } } else { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44336/api/type"); var post = client.PostAsJsonAsync <SemType>("type", semType); post.Wait(); var result = post.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Create", "FacultyChoice")); } } } return(View()); }
private static void Mismatch(SemType type, SemType eType, Lexema l) { var t = type == SemType.LongLongInt ? SemType.Int : type; var tt = eType == SemType.LongLongInt ? SemType.Int : eType; if (t != tt) { throw new SemanticException("Expression type mismatch", l, $"cannot assign {eType.ToStr()} to {type.ToStr()}"); } }
private VarInfo AddVar(Lexema var, SemType type) { var name = var.Tok; var currentFrame = environment.Last(); if (currentFrame.ContainsKey(name)) { var prev = currentFrame[name]; throw new SemanticException($"Cannot redefine variable: `{name}`", var, $"previous declaration at {prev.Location.Line}:{prev.Location.Symbol}"); } return(currentFrame[name] = VarInfo.Of(type, var, "")); }
private void Def(SemType type) { Sure(() => { var id = L(LexType.Tident); AddVar(id, type); Maybe(() => { L(LexType.Teq); var l = GetNextLex(); var eType = Expr(); Mismatch(type, eType, l); }); }); }
public string MovType(SemType type) { switch (type) { case SemType.Char: return($"movzx {B64}"); case SemType.Int: return($"mov {B32}"); case SemType.LongLongInt: return($"mov {B64}"); default: throw new ArgumentOutOfRangeException(nameof(type)); } }
public string OfType(SemType type) { switch (type) { case SemType.Char: return(B8); case SemType.Int: return(B32); case SemType.LongLongInt: return(B64); default: throw new ArgumentOutOfRangeException(nameof(type)); } }
public dynamic Cast(SemType type) { switch (type) { case SemType.Int: return((int)Value); case SemType.LongLongInt: return((long)Value); case SemType.Char: return((byte)Value); default: throw new ArgumentOutOfRangeException(nameof(type)); } }
public ActionResult Edit(string SnId, string S, SemType semtype, DateTime Time, string Cats, string professionTags, string UserTag, string UserTags, string[] fileInsert) { NullChecker.NullCheck(new object[] { SnId, S }); if (String.IsNullOrWhiteSpace(UserTag)) { throw new JsonCustomException(ControllerError.ajaxErrorSemAdmin); } var snid = EncryptionHelper.Unprotect(SnId); var s = EncryptionHelper.Unprotect(S); var semToEdit = unitOfWork.SeminarRepository.GetByID(snid); if (s == snid) { if (TryUpdateModel(semToEdit, "", new string[] { "title", "desc", "date", "maxAudiences", "duration", "price", "isPublic" })) { semToEdit.date = semToEdit.date + new TimeSpan(Time.Hour, Time.Minute, Time.Second); var currentType = semToEdit.GetType().BaseType.Name; if (currentType != semtype.ToString()) { unitOfWork.seminarTypeChange(semToEdit.seminarId, semtype.ToString()); } semToEdit.date = semToEdit.date.ToUniversalTime(); semToEdit.files = String.Join(",", new HashSet <string>(fileInsert.Where(f => !String.IsNullOrWhiteSpace(f)))); semToEdit.moderatorId = (int)EncryptionHelper.Unprotect(UserTag); if (!String.IsNullOrWhiteSpace(UserTags)) { UpSertSeminarBroadcasters(UserTags, semToEdit); } UpSertSeminarCats(Cats, semToEdit); UpSertSeminarProffs(professionTags, semToEdit); unitOfWork.SeminarRepository.Update(semToEdit); unitOfWork.Save(); return(Json(new { Success = true, Url = Url.Action("Detail", new { SnId = semToEdit.seminarId, SName = StringHelper.URLName(semToEdit.title) }) })); } throw new ModelStateException(this.ModelState); } throw new JsonCustomException(ControllerError.ajaxError); }
private VarInfo AddVar(Lexema var, SemType type) { var name = var.Tok; var currentFrame = environment.Last(); if (currentFrame.ContainsKey(name)) { var prev = currentFrame[name]; throw new SemanticException($"Cannot redefine variable: `{name}`", var, $"previous declaration at {prev.Location.Line}:{prev.Location.Symbol}"); } var varInfo = VarInfo.Of(type, var, Scope, allocSize); if (type != SemType.Function) { allocSize += GetSize(type); allocMax = Math.Max(allocSize, allocMax); } return(currentFrame[name] = varInfo); }
public ActionResult Create([Bind(Include = "title,desc,date,Time,maxAudiences,duration,price,isPublic")] Seminar smr, SemType semtype, string Cats, DateTime Time, string professionTags, string UserTag, string UserTags, string[] fileInsert) { if (String.IsNullOrWhiteSpace(UserTag)) { throw new JsonCustomException(ControllerError.ajaxErrorSemAdmin); } if (ModelState.IsValid) { smr.date = smr.date.ToUniversalTime(); smr.files = String.Join(",", new HashSet <string>(fileInsert.Where(f => !String.IsNullOrWhiteSpace(f)))); smr.moderatorId = (int)EncryptionHelper.Unprotect(UserTag); if (!String.IsNullOrWhiteSpace(UserTags)) { UpSertSeminarBroadcasters(UserTags, smr); } UpSertSeminarCats(Cats, smr); UpSertSeminarProffs(professionTags, smr); smr.token = Guid.NewGuid(); switch (semtype) { case SemType.Workshop: unitOfWork.WorkshopRepository.Insert(smr as Workshop); break; case SemType.Webinar: unitOfWork.WebinarRepository.Insert(smr as Webinar); break; case SemType.VideoConference: unitOfWork.VideoConferenceRepository.Insert(smr as VideoConference); break; default: throw new JsonCustomException(ControllerError.ajaxErrorSemAdmin); } unitOfWork.Save(); return(Json(new { Success = true, Url = Url.Action("Detail", new { SnId = smr.seminarId, SnName = StringHelper.URLName(smr.title) }) })); } throw new ModelStateException(this.ModelState); }
public void Check() { sc.PushState(); var l = sc.Next(); sc.PopState(); var inps = table["program".Of()]; if (!inps.ContainsKey(l.Type)) { throw new ParseException(l, inps.Keys.ToArray()); } magaz.AddRange(inps[l.Type].Reverse()); while (magaz.Count > 0) { var term = magaz.Last() as Term; var neterm = magaz.Last() as Neterm; var delta = magaz.Last() as Delta; if (term != null) { var ll = sc.Next(); if (ll.Type != term.Type) { throw new ParseException(ll, term.Type); } switch (ll.Type) { case LexType.Tident: lastId = ll; break; case LexType.TlongIntType: case LexType.TintType: case LexType.TcharType: ttype = new Dictionary <LexType, SemType> { [LexType.TlongIntType] = SemType.LongLongInt, [LexType.TintType] = SemType.Int, [LexType.TcharType] = SemType.Char }[ll.Type]; break; case LexType.Tintd: case LexType.Tinth: case LexType.Tinto: lastConst = ll.IntValue; break; case LexType.Tchar: lastConst = ll.Tok[1]; break; case LexType.Tand: case LexType.Tor: case LexType.Tdiv: case LexType.Tmod: case LexType.Tmul: case LexType.Tplus: case LexType.Tminus: case LexType.Tlshift: case LexType.Trshift: case LexType.Txor: case LexType.Tnot: ops.Push(ll); break; } magaz.RemoveAt(magaz.Count - 1); } else if (neterm != null) { sc.PushState(); var ll = sc.Next(); sc.PopState(); var inpss = table[neterm]; if (!inpss.ContainsKey(ll.Type)) { throw new ParseException(ll, inpss.Keys.ToArray()); } magaz.RemoveAt(magaz.Count - 1); magaz.AddRange(inpss[ll.Type].Reverse()); } else { delta?.Action(this); magaz.RemoveAt(magaz.Count - 1); } } }
public static VarInfo Of(SemType type, Lexema location, string scope, int offset = 0) { return(new VarInfo(type, location, scope, offset)); }
public static TriadResult Of(int index, SemType type) { return(new TriadResult { Index = index, Type = type }); }