// adds a local method ST to the class. Semantically this corresponds to opening a new scope in the class. public void AddLocalMethodST(string methodName, MethodSymbolTable methodST) { if (_classMethodSymbolTables.ContainsKey(methodName)) { _errorSummary.AddError(new SemanticError($"'{methodName}' is already declared", methodST.MethodDeclaring.SourcePosition)); } else { _classMethodSymbolTables.Add(methodName, methodST); } }
// Fills the global symbol table by creating a mapping from class and interface names to their respective symbol tables. // The global symbol table maps to class symbol tables; class symbol tables maps to class declarations and finally // method symbol tables maps to method declarations thus effectively creating the desired nested scope structure. // Note that for simplicity we use class symbol tables for both classes and interfaces. // The symbol tables created in this class are used in the later type checking and enables the type checker to correctly handle // forward referencing of variables. // also returns the name of the class in which the 'Main' method is declared. if no such method is found, an error is produced. public (Dictionary <string, ClassSymbolTable>, string) FillTable(List <ProgramNode> ASTRoots) { BuiltStdLib(); foreach (ProgramNode n in ASTRoots) { n.Accept(this, null); } if (!_hasMainMethod) { _errorSummary.AddError(new SemanticError("No viable 'Main' method found", null)); } return(_globalTable, _mainMethodParentClassName); }
// checks whether the current token is of the expected type. If so, reads the next token and if not reports an error and performs error recovery private void Accept(Token.TokenType expectedType) { if (_currentToken.Type != expectedType) { _errorSummary.AddError(new SyntaxError($"Expected token of type '{expectedType}'", _currentToken.SourcePosition)); Recover(expectedType); } else { _currentToken = _tokenStream.Read(); } }
public void EnterSymbol(string ident, DeclaringNode declaring) { if (_methodVarDeclarings.ContainsKey(ident)) { _errorSummary.AddError(new SemanticError($"'{ident}' is already declared", declaring.SourcePosition)); } else { _methodVarDeclarings.Add(ident, declaring); } }
protected void lbSave_Click(object sender, EventArgs e) { Account account = new Account { Name = txtName.Text.Trim(), Username = txtUsername.Text.Trim().ToLower(), Email = txtUsername.Text.Trim().ToLower(), ContactNumber = txtContact.Text.Trim(), DisplayContactNumberInDespatch = cbDisplayContactNumber.Checked, DOB = txtDOB.Text.Trim() }; // Get assigned roles if any var roles = new List <string>(); for (int i = 0; i < cblRoles.Items.Count; i++) { if (cblRoles.Items[i].Selected) { roles.Add(cblRoles.Items[i].Value); } } account.Roles = roles.ToArray(); // Get password string password; if (cbSendAutoPwd.Checked) { password = AdminStoreUtility.GenerateRandomPasswordGUID(8); } else { password = txtPwd.Text.Trim(); } bool sendPassEmailFlag = cbSendAutoPwd.Checked; bool sendEmailFlag = sendPassEmailFlag ? false : cbWelcomeEmail.Checked; var result = AccountService.ProcessRegistration(account, password, sendEmailFlag, sendPassEmailFlag); if (!string.IsNullOrEmpty(result.Message)) { ErrorSummary.AddError(result.Message, "vgNewCustomer", this.Page); } else { Response.Redirect("/customer/customer_info.aspx?" + QueryKey.MSG_TYPE + "=" + (int)MessageType.AccountCreated + "&userid=" + result.ProfileId.ToString()); } }
public Token Scan() { Token answer; while (IsSkipChar(_charStream.Peek())) { Skip(); } if (_charStream.EOF()) { answer = new Token(Token.TokenType.EOF, new SourceCodePosition(_lineNumber, _charNumber, _fileName)); } else if (Char.IsDigit(_charStream.Peek())) { answer = ScanNumberToken(); } else if (IsValidIdentStartChar(_charStream.Peek())) { answer = ScanIdentOrKeywordToken(); } else if (IsValidMathOpStartChar(_charStream.Peek())) { answer = ScanMathOpToken(); } else if (IsValidControlChar(_charStream.Peek())) { answer = ScanControlToken(); } else if (_charStream.Peek() == '"') // string { answer = ScanStringToken(); } else { _errorSummary.AddError(new SyntaxError($"invalid symbol '{_charStream.Peek()}'", new SourceCodePosition(_lineNumber, _charNumber, _fileName))); _charStream.Read(); // read and discard the invalid symbol to continue scanning return(Scan()); } return(answer); }
protected void lbSaveContinue_Click(object sender, EventArgs e) { string urlKey = txtUrlKey.Text.Trim(); // If urlKey is empty, regenerate with given name if (urlKey == string.Empty) { urlKey = AdminStoreUtility.GetFriendlyUrlKey(txtName.Text.Trim()); txtUrlKey.Text = urlKey; } // Make sure urlKey is unique var foundProduct = ProductService.GetProductByUrlKey(urlKey); int productId = QueryProductId; string message = string.Empty; if (((foundProduct != null) && (foundProduct.Id != productId))) { ErrorSummary.AddError("Url Key is not unique.", "vgNewProduct", this.Page); } else { Product product = new Product(); product.Name = Server.HtmlEncode(txtName.Text.Trim()); product.Description = string.Empty; product.BrandId = Convert.ToInt32(ddlBrand.SelectedValue); product.DeliveryId = Convert.ToInt32(ddlDelivery.SelectedValue); product.UrlRewrite = urlKey; product.Enabled = ddlStatus.Items.FindByValue(product.Enabled ? ENABLED : DISABLED).Selected = true; product.IsPharmaceutical = cbIsPharm.Checked; product.OpenForOffer = cbOpenForOffer.Checked; product.Discontinued = cbDiscontinued.Checked; product.ShowPreOrderButton = cbDisplayPreOrder.Checked; product.EnforceStockCount = cbEnforceStockCount.Checked; product.IsGoogleProductSearchDisabled = cbGoogleProductSearchDisabled.Checked; product.ProductCode = txtProductCode.Text.Trim(); product.HasFreeWrapping = cbFreeWrap.Checked; product.OptionType = Convert.ToInt32(ddlOptionType.SelectedValue); product.ProductMark = txtProductMark.Text.Trim(); product.ProductMarkType = Convert.ToInt32(ddlProductMarks.SelectedValue); if (!string.IsNullOrEmpty(txtProductMarkExpiryDate.Text.Trim())) { product.ProductMarkExpiryDate = DateTime.ParseExact(txtProductMarkExpiryDate.Text, AppConstant.DATE_FORM1, CultureInfo.InvariantCulture); } product.IsPhoneOrder = cbIsPhoneOrder.Checked; product.VisibleIndividually = cbVisibleIndividually.Checked; int taxCategoryId = Convert.ToInt32(ddlTaxCategory.SelectedValue); var taxCategory = ProductService.GetTaxCategory(taxCategoryId); product.TaxCategory = taxCategory; if (txtStepQuantity.Text.Trim() != string.Empty) { int defaultQty = 1; if (!int.TryParse(txtStepQuantity.Text.Trim(), out defaultQty)) { defaultQty = 1; } if (defaultQty <= 0) { defaultQty = 1; } product.StepQuantity = Convert.ToInt32(txtStepQuantity.Text.Trim()); if (cbIsPharm.Checked) { product.StepQuantity = 1; } } product.Id = ProductService.InsertProduct(product); var categoryId = Convert.ToInt32(hfCategory.Value); if (categoryId != AppConstant.DEFAULT_CATEGORY) { CategoryService.ProcessCategoryAssignmentForProduct(categoryId, product.Id); } Response.Redirect("/catalog/product_info.aspx?" + QueryKey.MSG_TYPE + "=" + (int)MessageType.ProductCreated + "&productid=" + product.Id); } }