public override IAstNode VisitAssignFieldStmt(MicroCParser.AssignFieldStmtContext context) { var label = ++_label; string recName = context.name.Text; string fieldName = context.field.Text; var recSymbol = _symbolTable.LookupSymbol(recName); if (recSymbol == null) { throw new ArgumentException($"Record: {recName} does not exist"); } var fieldSymbol = recSymbol.Children.SingleOrDefault(f => f.Name == fieldName); if (fieldSymbol == null) { throw new ArgumentException($"Record: {recName} does not include a field: {fieldName}"); } var recIdent = new Identifier(recName, recSymbol.Type, recSymbol.Id); var fieldIdent = new Identifier(fieldName, fieldSymbol.Type, fieldSymbol.Id); RecordAccess left = new RecordAccess(recIdent, fieldIdent); IAExpr right = Visit(context.a_expr()) as IAExpr; var assignStmt = new AssignStmt(left, right); assignStmt.Label = label; return(assignStmt); }
public override IAstNode VisitAexprArrayAccess(MicroCParser.AexprArrayAccessContext context) { string name = context.IDENT().GetText(); var symbol = _symbolTable.LookupSymbol(name); var ident = new Identifier(symbol.Name, symbol.Type, symbol.Id); IAExpr index = Visit(context.a_expr()) as IAExpr; return(new ArrayAccess(ident, index)); }
public override IAstNode VisitWriteStmt(MicroCParser.WriteStmtContext context) { var label = ++_label; IAExpr value = Visit(context.a_expr()) as IAExpr; var writeStmt = new WriteStmt(value); writeStmt.Label = label; return(writeStmt); }
public override IAstNode VisitAexprUnaryMinus(MicroCParser.AexprUnaryMinusContext context) { IAExpr left = Visit(context.left) as IAExpr; if (left is IntLit) { var intLit = left as IntLit; return(new IntLit(-intLit.Value)); } return(new AUnaryMinus(left)); }
public override IAstNode VisitAexprSum(MicroCParser.AexprSumContext context) { IAExpr left = Visit(context.left) as IAExpr; IAExpr right = Visit(context.right) as IAExpr; ABinOperator op = context.op.Text switch { "+" => ABinOperator.Plus, "-" => ABinOperator.Minus, _ => throw new ArgumentException("Invalid ABinOp Sum Operator") }; return(new ABinOp(left, right, op)); }
public override IAstNode VisitReadArrStmt(MicroCParser.ReadArrStmtContext context) { var label = ++_label; string name = context.IDENT().GetText(); var symbol = _symbolTable.LookupSymbol(name); var ident = new Identifier(symbol.Name, symbol.Type, symbol.Id, symbol.Size); IAExpr index = Visit(context.index) as IAExpr; IStateAccess sa = new ArrayAccess(ident, index); var readStmt = new ReadStmt(sa); readStmt.Label = label; return(readStmt); }
public override IAstNode VisitAexprProduct(MicroCParser.AexprProductContext context) { IAExpr left = Visit(context.left) as IAExpr; IAExpr right = Visit(context.right) as IAExpr; ABinOperator op = context.op.Text switch { "*" => ABinOperator.Mult, "/" => ABinOperator.Div, _ => throw new ArgumentException("Invalid ABinOp Product Operator") }; return(new ABinOp(left, right, op)); }
public override IAstNode VisitAssignStmt(MicroCParser.AssignStmtContext context) { var label = ++_label; var name = context.IDENT().GetText(); var symbol = _symbolTable.LookupSymbol(name); var ident = new Identifier(name, symbol.Type, symbol.Id); // TODO: Type check the symbol VarAccess left = new VarAccess(ident); IAExpr right = Visit(context.a_expr()) as IAExpr; var assignStmt = new AssignStmt(left, right); assignStmt.Label = label; return(assignStmt); }
public override IAstNode VisitRexprBinop(MicroCParser.RexprBinopContext context) { IAExpr left = Visit(context.left) as IAExpr; IAExpr right = Visit(context.right) as IAExpr; RBinOperator op = context.rop.Text switch { "<" => RBinOperator.LessThan, ">" => RBinOperator.GreaterThan, "<=" => RBinOperator.LessThanEq, ">=" => RBinOperator.GreaterThanEq, "==" => RBinOperator.Eq, "!=" => RBinOperator.NotEq, _ => throw new ArgumentException("Invalid RBinOpOperator") }; return(new RBinOp(left, right, op)); }
public override IAstNode VisitAssignArrayStmt(MicroCParser.AssignArrayStmtContext context) { var label = ++_label; string name = context.IDENT().GetText(); var symbol = _symbolTable.LookupSymbol(name); var ident = new Identifier(name, symbol.Type, symbol.Id, symbol.Size); // TODO: Type check the symbol IAExpr index = Visit(context.index) as IAExpr; ArrayAccess left = new ArrayAccess(ident, index); IAExpr right = Visit(context.value) as IAExpr; var assignStmt = new AssignStmt(left, right); assignStmt.Label = label; return(assignStmt); }
public ABinOp(IAExpr left, IAExpr right, ABinOperator op) { Left = left; Right = right; Op = op; }
public static Interval Arithmetic(IAExpr aExpr, IADomain domain) => aExpr switch {
public AUnaryMinus(IAExpr left) => Left = left;
public ArrayAccess(Identifier left, IAExpr right) { Left = left; Right = right; }
public WriteStmt(IAExpr left) => Left = left;
public AssignStmt(IStateAccess left, IAExpr right) { Left = left; Right = right; }
public static HashSet <DSSign> Arithmetic(IAExpr aExpr, DSDomain domain) => aExpr switch {