private IfStatement IfStatementToAst(Brunch <KjuAlphabet> branch) { var blockList = new List <InstructionBlock>(); Expression condition = null; foreach (var child in branch.Children) { switch (child.Category) { case KjuAlphabet.Expression: condition = this.ExpressionToAst(child as Brunch <KjuAlphabet>); break; case KjuAlphabet.Block: blockList.Add(this.BlockToAst(child as Brunch <KjuAlphabet>)); break; } } var elseBody = blockList.Count == 1 ? new InstructionBlock(branch.InputRange, new List <Expression>()) : blockList[1]; var ret = new IfStatement( branch.InputRange, condition, blockList[0], elseBody); return(ret); }
private Expression UnapplyExpressionAst(Brunch <KjuAlphabet> brunch) { var nameToken = (Token <KjuAlphabet>)brunch.Children[2]; var nameText = nameToken.Text; return(new UnApplication(brunch.InputRange, nameText)); }
private WhileStatement WhileStatementToAst(Brunch <KjuAlphabet> branch) { var condition = this.ExpressionToAst((Brunch <KjuAlphabet>)branch.Children[1]); var body = this.BlockToAst((Brunch <KjuAlphabet>)branch.Children[2]); return(new WhileStatement(branch.InputRange, condition, body)); }
private Expression AllocToAst(Brunch <KjuAlphabet> brunch) { var type = this.TypeIdentifierAst(brunch.Children[2]); switch (brunch.Children.Count) { case 4: { return(new StructAlloc(brunch.InputRange, type)); } case 6: { var size = this.ExpressionToAst((Brunch <KjuAlphabet>)brunch.Children[4]); return(new ArrayAlloc(brunch.InputRange, type, size)); } default: { this.diagnostics.Add( new Diagnostic( DiagnosticStatus.Error, AssignmentLhsErrorDiagnosticsType, $"Unexpected number of children: {brunch.Children.Count}", new List <Range> { brunch.InputRange })); throw new ParseTreeToAstConverterException( $"Unexpected number of children: {brunch.Children.Count} at {brunch.InputRange}"); } } }
private Expression ParenEnclosedStatementToAst(Brunch <KjuAlphabet> branch) { var result = this.StatementToAst((Brunch <KjuAlphabet>)branch.Children[1]); this.operationOrderFlipper.AddEnclosedWithParentheses(result); return(result); }
private StructDeclaration StructDefinitionAst(Brunch <KjuAlphabet> branch) { var nameToken = (Token <KjuAlphabet>)branch.Children[1]; var name = nameToken.Text; var fieldsBranch = (Brunch <KjuAlphabet>)branch.Children[3]; var fieldsNodes = this.StructFieldsAstList(fieldsBranch); var ret = new StructDeclaration(branch.InputRange, name, fieldsNodes); foreach (StructField field in fieldsNodes) { List <KeyValuePair <StructDeclaration, StructField> > candidates; try { candidates = this.fieldsToStructDeclarations[field.Name]; } catch (KeyNotFoundException) { candidates = new List <KeyValuePair <StructDeclaration, StructField> >(); this.fieldsToStructDeclarations.Add(field.Name, candidates); } candidates.Add(new KeyValuePair <StructDeclaration, StructField>(ret, field)); } return(ret); }
private VariableDeclaration VariableDeclarationToAst(Brunch <KjuAlphabet> branch) { string identifier = null; DataType type = null; Expression value = null; foreach (var child in branch.Children) { switch (child.Category) { case KjuAlphabet.VariableFunctionIdentifier: identifier = ((Token <KjuAlphabet>)child).Text; break; case KjuAlphabet.TypeDeclaration: type = this.TypeDeclarationAst((Brunch <KjuAlphabet>)child); break; case KjuAlphabet.Expression: value = this.ExpressionToAst(child as Brunch <KjuAlphabet>); break; } } return(new VariableDeclaration(branch.InputRange, type, identifier, value)); }
private List <Expression> FunctionCallArgumentsToAst(Brunch <KjuAlphabet> branch) { return(branch.Children .Where(child => child.Category == KjuAlphabet.Expression) .Cast <Brunch <KjuAlphabet> >() .Select(this.ExpressionToAst) .ToList()); }
private VariableDeclaration FunctionParameterToAst(Brunch <KjuAlphabet> branch) { var identifier = ((Token <KjuAlphabet>)branch.Children[0]).Text; var type = branch.Children.Count == 2 ? this.TypeDeclarationAst((Brunch <KjuAlphabet>)branch.Children[1]) : null; return(new VariableDeclaration(branch.InputRange, type, identifier, null)); }
public async Task <ActionResult> DeleteConfirmed(int id) { Brunch brunch = await db.Brunch.FindAsync(id); db.Brunch.Remove(brunch); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
private StructField StructFieldAst(Brunch <KjuAlphabet> branch) { var nameToken = (Token <KjuAlphabet>)branch.Children[0]; var name = nameToken.Text; var typeIdentifier = branch.Children.Count == 3 ? this.TypeDeclarationAst((Brunch <KjuAlphabet>)branch.Children[1]) : null; return(new StructField(branch.InputRange, name, typeIdentifier)); }
public BrunchDto(Brunch entity) { this.Id = entity.Id; this.Address = entity.Address; this.Name = entity.Name; this.Email = entity.Email; this.StaffId = entity.Staff.Select(x => x.Id).ToList(); this.OrdersId = entity.Orders.Select(x => x.Id).ToList(); // this.Staff = (entity.Staff == null) ? null : entity.Staff.Select(e=>new StaffDto(e)).ToList(); }
private InstructionBlock BlockToAst(Brunch <KjuAlphabet> branch) { var instructions = branch.Children .Where(child => child.Category == KjuAlphabet.Instruction) .Cast <Brunch <KjuAlphabet> >() .Select(this.InstructionToAst) .ToList(); return(new InstructionBlock(branch.InputRange, instructions)); }
private Expression AccessToAst(Brunch <KjuAlphabet> branch) { var atom = branch.Children.First(); var accesses = branch.Children.Skip(1).Cast <Brunch <KjuAlphabet> >(); return(accesses.Aggregate( this.ExpressionAtomToAst((Brunch <KjuAlphabet>)atom), (expression, access) => { var accessType = (Brunch <KjuAlphabet>)access.Children[0]; switch (accessType.Category) { case KjuAlphabet.ArrayAccess: { return new ArrayAccess( branch.InputRange, expression, this.GeneralToAst(accessType.Children[1])); } case KjuAlphabet.FieldAccess: { var labelToken = (Token <KjuAlphabet>)accessType.Children[1]; var label = labelToken.Text; // Warning: the below list gets modified later by StructDeclarations. List <KeyValuePair <StructDeclaration, StructField> > candidates; try { candidates = this.fieldsToStructDeclarations[label]; } catch (KeyNotFoundException) { candidates = new List <KeyValuePair <StructDeclaration, StructField> >(); this.fieldsToStructDeclarations.Add(label, candidates); } var ret = new FieldAccess(branch.InputRange, expression, label); ret.StructCandidates = candidates; return ret; } default: var message = $"Unknown access type: {accessType.Category}"; this.diagnostics.Add( new Diagnostic( DiagnosticStatus.Error, AstConversionErrorDiagnosticsType, message, new List <Range> { branch.InputRange })); throw new ParseTreeToAstConverterException( message); } })); }
public async Task <ActionResult> Edit([Bind(Include = "brunchNameId,practicsName,city,street")] Brunch brunch) { if (ModelState.IsValid) { db.Entry(brunch).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(brunch)); }
public IHttpActionResult Post(Brunch brunch) { try { service.Save(brunch); return(CreatedAtRoute("DefaultApi", new { id = brunch.Id }, new BrunchDto(brunch))); } catch (Exception ex) { throw ex; } }
private Expression ApplyExpressionAst(Brunch <KjuAlphabet> brunch) { var function = this.GeneralToAst(brunch.Children[2]); var arguments = brunch .Children .Skip(3) .Where(x => x.Category == KjuAlphabet.Expression) .Select(this.GeneralToAst).ToList(); return(new Application(brunch.InputRange, function, arguments)); }
public async Task <ActionResult> Create([Bind(Include = "brunchNameId,practicsName,city,street")] Brunch brunch) { if (ModelState.IsValid) { db.Brunch.Add(brunch); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(brunch)); }
private DataType FunctionTypeIdentifierAst(Brunch <KjuAlphabet> brunch) { var argumentsTypes = brunch.Children .Where(child => child.Category == KjuAlphabet.FunctionTypeArgumentType) .Select(this.TypeIdentifierAst); var returnType = brunch.Children .Where(child => child.Category == KjuAlphabet.FunctionTypeResultType) .Select(this.TypeIdentifierAst) .Single(); return(new UnresolvedFunctionType(argumentsTypes, returnType)); }
// GET: Brunche/Delete/5 public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Brunch brunch = await db.Brunch.FindAsync(id); if (brunch == null) { return(HttpNotFound()); } return(View(brunch)); }
private Expression ExpressionLogicalNotToAst(Brunch <KjuAlphabet> branch) { if (branch.Children.Count == 1) { return(this.AccessToAst((Brunch <KjuAlphabet>)branch.Children[0])); } var operationToken = (Token <KjuAlphabet>)branch.Children[0]; var operationTokenCategory = operationToken.Category; var operationType = this.symbolToUnaryOperationType[operationTokenCategory]; var expression = this.ExpressionLogicalNotToAst((Brunch <KjuAlphabet>)branch.Children[1]); return(new UnaryOperation(branch.InputRange, operationType, expression)); }
private Expression ExpressionPlusMinusToAst(Brunch <KjuAlphabet> branch) { if (branch.Children.Count == 1) { return(this.ExpressionTimesDivideModuloToAst((Brunch <KjuAlphabet>)branch.Children[0])); } else { var operationType = this.symbolToOperationType[branch.Children[1].Category]; var leftValue = this.ExpressionTimesDivideModuloToAst((Brunch <KjuAlphabet>)branch.Children[0]); var rightValue = this.ExpressionPlusMinusToAst((Brunch <KjuAlphabet>)branch.Children[2]); return(new ArithmeticOperation(branch.InputRange, leftValue, rightValue, operationType)); } }
private Expression ExpressionLessThanGreaterThanToAst(Brunch <KjuAlphabet> branch) { if (branch.Children.Count == 1) { return(this.ExpressionPlusMinusToAst(branch.Children[0] as Brunch <KjuAlphabet>)); } else { var comparisonType = this.symbolToComparisonType[branch.Children[1].Category]; var leftValue = this.ExpressionPlusMinusToAst((Brunch <KjuAlphabet>)branch.Children[0]); var rightValue = this.ExpressionLessThanGreaterThanToAst((Brunch <KjuAlphabet>)branch.Children[2]); return(new Comparison(branch.InputRange, leftValue, rightValue, comparisonType)); } }
private Expression ExpressionLogicalAndToAst(Brunch <KjuAlphabet> branch) { if (branch.Children.Count == 1) { return(this.ExpressionEqualsNotEqualsToAst((Brunch <KjuAlphabet>)branch.Children[0])); } else { var logicalOperationType = LogicalBinaryOperationType.And; var leftValue = this.ExpressionEqualsNotEqualsToAst((Brunch <KjuAlphabet>)branch.Children[0]); var rightValue = this.ExpressionLogicalAndToAst((Brunch <KjuAlphabet>)branch.Children[2]); return(new LogicalBinaryOperation(branch.InputRange, leftValue, rightValue, logicalOperationType)); } }
private Expression ReturnStatementToAst(Brunch <KjuAlphabet> branch) { Expression value = null; foreach (var child in branch.Children) { switch (child.Category) { case KjuAlphabet.Expression: value = this.ExpressionToAst(child as Brunch <KjuAlphabet>); break; } } return(new ReturnStatement(branch.InputRange, value)); }
private Expression ExpressionAtomToAst(Brunch <KjuAlphabet> branch) { var firstChild = branch.Children[0]; Expression primaryExpression; switch (firstChild.Category) { case KjuAlphabet.Literal: { primaryExpression = this.GeneralToAst(firstChild); break; } case KjuAlphabet.VariableUse: { primaryExpression = this.VariableUseToAst((Brunch <KjuAlphabet>)firstChild); break; } case KjuAlphabet.Alloc: { primaryExpression = this.AllocToAst((Brunch <KjuAlphabet>)firstChild); break; } case KjuAlphabet.ParenEnclosedStatement: { primaryExpression = this.ParenEnclosedStatementToAst((Brunch <KjuAlphabet>)firstChild); break; } default: var message = $"Unknown expression atom: {firstChild.Category}"; this.diagnostics.Add( new Diagnostic( DiagnosticStatus.Error, AstConversionErrorDiagnosticsType, message, new List <Range> { branch.InputRange })); throw new ParseTreeToAstConverterException(message); } return(primaryExpression); }
private Expression VariableUseToAst(Brunch <KjuAlphabet> branch) { string id = ((Token <KjuAlphabet>)branch.Children[0]).Text; if (branch.Children.Count == 1) { // Value return(new Variable(branch.InputRange, id)); } else { // Function call var arguments = this.FunctionCallArgumentsToAst((Brunch <KjuAlphabet>)branch.Children[1]); return(new FunctionCall(branch.InputRange, id, arguments)); } }
public IHttpActionResult Get(int id) { Brunch brunch = service.GetBuyId(id); try { if (brunch == null) { return(NotFound()); } return(Ok(new BrunchDto(brunch))); } catch (Exception ex) { throw ex; } }
private FunctionDeclaration FunctionDeclarationToAst(Brunch <KjuAlphabet> branch) { var parameters = new List <VariableDeclaration>(); string identifier = null; DataType type = null; InstructionBlock body = null; bool isForeign = false; foreach (var child in branch.Children) { switch (child.Category) { case KjuAlphabet.FunctionParameter: parameters.Add(this.FunctionParameterToAst((Brunch <KjuAlphabet>)child)); break; case KjuAlphabet.VariableFunctionIdentifier: identifier = ((Token <KjuAlphabet>)child).Text; break; case KjuAlphabet.TypeDeclaration: type = this.TypeDeclarationAst((Brunch <KjuAlphabet>)child); break; case KjuAlphabet.Block: body = this.BlockToAst((Brunch <KjuAlphabet>)child); break; case KjuAlphabet.Import: isForeign = true; break; } } return(new FunctionDeclaration( branch.InputRange, identifier, type, parameters, body, isForeign)); }
public IHttpActionResult Put(int id, Brunch brunch) { try { if (id != brunch.Id) { return(BadRequest()); } service.Update(brunch); } catch (DbUpdateConcurrencyException) { if (service.GetBuyId(id) == null) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }