Beispiel #1
0
 private bool CheckAndReport(bool expression, SourceLoc sl, string msg)
 {
     if (!expression)
     {
         Console.WriteLine("TypeError: line {0}, col {1} :: {2}", sl.Row, sl.Col, msg);
         errors++;
         return(false);
     }
     return(true);
 }
Beispiel #2
0
        public override ASTNode VisitStructDecl([NotNull] llangParser.StructDeclContext context)
        {
            string     name = context.Iden().GetText();
            Expression rhs  = null;
            TypeSymbol ts   = TypeSymbol.INFER_SYMOBOL(context.typename().GetText());

            if (context.expr() != null)
            {
                rhs = (Expression)Visit(context.expr());
            }

            SourceLoc sl = MakeSourceLoc(context);

            return(new VarDeclNode(name, rhs, ts, sl));
        }
Beispiel #3
0
 public EnumDefNode(string name, TypeSymbol type, SourceLoc sl) : base(ASTKind.EnumDef, sl)
 {
     enumname = name;
     Type     = type;
 }
Beispiel #4
0
 public ASTNode(ASTKind kind, SourceLoc sl)
 {
     this.kind      = kind;
     this.sourceLoc = sl;
 }
Beispiel #5
0
 public DeferedNode(Expression expr, SourceLoc sl) : base(ASTKind.Defer, sl)
 {
     this.expr = expr;
 }
Beispiel #6
0
 public FieldAccessNode(Expression basestruct, string fieldname, SourceLoc sl) : base(ASTKind.FieldAccess, TypeSymbol.INFER_SYMOBOL(fieldname), sl)
 {
     this.basestruct = basestruct;
     this.fieldname  = fieldname;
 }
Beispiel #7
0
 public ConstListExprNode(List <Expression> elems, SourceLoc sl)
     : base(ASTKind.ListExpr, TypeSymbol.INFER_SYMOBOL(""), sl)
 {
     ListValue  = elems;
     IsConstant = true;
 }
Beispiel #8
0
 public ImplicitFunCallExprNode(string funname, Expression name, List <Expression> args, SourceLoc sl) : base(name, args, sl)
 {
     this.kind    = ASTKind.FunCallExprImpl;
     this.funname = funname;
 }
Beispiel #9
0
 public IfNode(Expression test, Statement body, Statement elsebody, SourceLoc sl) : base(ASTKind.If, sl)
 {
     this.test     = test;
     this.ifbody   = body;
     this.elsebody = elsebody;
 }
Beispiel #10
0
 public ForNode(string var, Expression inlist, Statement body, SourceLoc sl) : base(ASTKind.For, sl)
 {
     this.inList = inlist;
     this.var    = var;
     this.body   = body;
 }
Beispiel #11
0
 public WhileNode(Expression test, Statement body, SourceLoc sl) : base(ASTKind.While, sl)
 {
     this.test = test;
     this.body = body;
 }
Beispiel #12
0
 public FunCallStmtNode(Expression name, List <Expression> args, SourceLoc sl) : base(ASTKind.FunCallStmt, sl)
 {
     this.name   = name;
     this.funsig = this.name.Type;
     this.args   = args;
 }
Beispiel #13
0
 public AugAssignNode(Expression lhs, Expression rhs, string op, SourceLoc sl) : base(ASTKind.AugAssign, sl)
 {
     this.lhs = lhs;
     this.rhs = rhs;
     this.op  = op;
 }
Beispiel #14
0
 public AssignNode(Expression lhs, Expression rhs, SourceLoc sl) : base(ASTKind.Assign, sl)
 {
     this.rhs = rhs;
     this.lhs = lhs;
 }
Beispiel #15
0
 public VarDeclNode(string name, Expression rhs, TypeSymbol type, SourceLoc sl) : base(ASTKind.VarDecl, sl)
 {
     this.name = name;
     this.rhs  = rhs;
     this.Type = type;
 }
Beispiel #16
0
 public BinaryExprNode(Expression lhs, Expression rhs, string op, SourceLoc sl) : base(ASTKind.BinaryExpr, TypeSymbol.INFER_SYMOBOL(""), sl)
 {
     this.lhs = lhs;
     this.rhs = rhs;
     this.op  = op;
 }
Beispiel #17
0
 public FunCallExprNode(Expression name, List <Expression> args, SourceLoc sl) : base(ASTKind.FunCallExpr, TypeSymbol.INFER_SYMOBOL(""), sl)
 {
     this.name   = name;
     this.args   = args;
     this.funsig = this.name.Type;
 }
Beispiel #18
0
 public ReturnNode(Expression ret, SourceLoc sl) : base(ASTKind.Return, sl)
 {
     this.ret = ret;
 }
Beispiel #19
0
 public VarListExprNode(Expression lower, Expression upper, Expression stepsize, SourceLoc sl)
     : base(ASTKind.ConstListExpr, TypeSymbol.INFER_SYMOBOL(""), sl)
 {
     this.lower    = lower;
     this.upper    = upper;
     this.stepsize = stepsize;
 }
Beispiel #20
0
 public BlockNode(List <Statement> stmts, SourceLoc sl) : base(ASTKind.Block, sl)
 {
     this.stmts = stmts;
 }
Beispiel #21
0
 public ArrayIndexNode(Expression array, Expression index, SourceLoc sl) : base(ASTKind.ArrayIndex, TypeSymbol.INFER_SYMOBOL("[]"), sl)
 {
     this.array = array;
     this.index = index;
 }
Beispiel #22
0
 public IdenExprNode(string name, TypeSymbol type, SourceLoc sl) : base(ASTKind.IdenExpr, type, sl)
 {
     this.name = name;
 }
Beispiel #23
0
 public NewStructNode(string name, SourceLoc sl) : base(ASTKind.NewStruct, TypeSymbol.INFER_SYMOBOL(name), sl)
 {
 }
Beispiel #24
0
 public IntExprNode(long value, SourceLoc sl) : base(ASTKind.IntExpr, TypeSymbol.INT_SYMBOL, sl)
 {
     IntValue   = value;
     IsConstant = true;
 }
Beispiel #25
0
 public NullNode(SourceLoc sl) : base(ASTKind.Null, TypeSymbol.VOID_SYMBOL, sl)
 {
     IsConstant = true;
 }
Beispiel #26
0
 public FloatExprNode(double value, SourceLoc sl) : base(ASTKind.FloatExpr, TypeSymbol.FLOAT_SYMBOL, sl)
 {
     FloatValue = value;
     IsConstant = true;
 }
Beispiel #27
0
 public Statement(ASTKind kind, SourceLoc sl) : base(kind, sl)
 {
 }
Beispiel #28
0
 public StringExprNode(string value, SourceLoc sl) : base(ASTKind.StringExpr, TypeSymbol.STRING_SYMBOL, sl)
 {
     StringValue = value;
     IsConstant  = true;
 }
Beispiel #29
0
 public UnaryExprNode(Expression expr, string op, SourceLoc sl) : base(ASTKind.UnaryExpr, expr.Type, sl)
 {
     this.expr = expr;
     this.op   = op;
 }
Beispiel #30
0
 public LibImportNode(string name, SourceLoc sl) : base(ASTKind.LibImport, sl)
 {
     this.libname = name;
 }