Ejemplo n.º 1
0
 public Param(Token name, TypePrim type)
 {
     AddChildren(type);
     this.name     = name;
     this.type     = type;
     locationToken = name;
 }
Ejemplo n.º 2
0
        public override void ResolveNames(Scope scope)
        {
            var printToken       = new Token(TokenType.Print, "printInt", 0);
            var readToken        = new Token(TokenType.Read, "readInt", 0);
            var printStringToken = new Token(TokenType.PrintString, "printString", 0);
            var printFloatToken  = new Token(TokenType.PrintFloat, "printFloat", 0);
            var printType        = new TypePrim(printToken);
            var readType         = new TypePrim(readToken);
            var printStringType  = new TypePrim(printStringToken);
            var printFloatType   = new TypePrim(printFloatToken);

            scope.Add(printToken, new DeclFn(printType, printToken, new List <Param> {
                new Param(printToken, new TypePrim(new Token(TokenType.Int, null, 0)))
            }, null));
            scope.Add(printStringToken, new DeclFn(printStringType, printStringToken, new List <Param> {
                new Param(printStringToken, new TypePrim(new Token(TokenType.String, null, 0)))
            }, null));
            scope.Add(printFloatToken, new DeclFn(printFloatType, printFloatToken, new List <Param> {
                new Param(printFloatToken, new TypePrim(new Token(TokenType.Float, null, 0)))
            }, null));
            scope.Add(readToken, new DeclFn(readType, readToken, new List <Param>(), null));

            decls.ForEach(decl => scope.Add(decl.ReturnName(), decl));
            decls.ForEach(decl => decl.ResolveNames(scope));
        }
Ejemplo n.º 3
0
 public StmtVar(TypePrim type, Token ident, IExpression value)
 {
     AddChildren(type, value);
     this.type  = type;
     this.ident = ident;
     this.value = value;
 }
Ejemplo n.º 4
0
 public StmtVar(TypePrim type, Token ident)
 {
     AddChildren(type);
     this.type  = type;
     this.ident = ident;
     value      = null;
 }
Ejemplo n.º 5
0
        public override TypePrim CheckTypes()
        {
            TypePrim type = null;

            if (TargetNode?.GetType() == typeof(Param))
            {
                type = (TargetNode as Param).Type;
            }
            else if (TargetNode?.GetType() == typeof(StmtVar))
            {
                type = (TargetNode as StmtVar).Type;
            }
            return(type);
        }
Ejemplo n.º 6
0
        public DeclFn(TypePrim type, Token name, List <Param> parameters, List <IStatement> body)
        {
            if (body != null)
            {
                var bodyAndParams = new Node[body.Count + parameters.Count + 1];
                Array.Copy(parameters.ToArray(), bodyAndParams, parameters.Count);
                Array.Copy(body.ToArray(), bodyAndParams, body.Count);
                bodyAndParams[body.Count + parameters.Count] = type;
                AddChildren(bodyAndParams);
            }

            this.type       = type;
            this.name       = name;
            this.parameters = parameters;
            this.body       = body;
            locationToken   = name;
            StartLabel      = new Label();
        }
Ejemplo n.º 7
0
 public DeclVar(TypePrim type, Token ident, IExpression value)
 {
     this.type  = type;
     this.ident = ident;
     this.value = value;
 }
Ejemplo n.º 8
0
 public DeclVar(TypePrim type, Token ident)
 {
     this.type  = type;
     this.ident = ident;
     value      = null;
 }