Ejemplo n.º 1
0
        public static void Emit(Program root)
        {
            foreach (var rec in root.GetSpecifiedChildren<Record>())
            {
                Emit(rec);
            }

            Source += "public class Program\n{\n";

            foreach (var proc in root.GetSpecifiedChildren<Procedure>().Where(proc => !(proc is Function)))
            {
                Emit(proc);
            }

            foreach (var func in root.GetSpecifiedChildren<Function>())
            {
                Emit(func);
            }

            Source += "public static void Main()\n{\n";

            EmitLocalVariable(root);
            EmitBody(root.GetSpecifiedChildren<Body>().First());
            Source += "}\n";
            Source += "}";
        }
Ejemplo n.º 2
0
 public List<Error> Validate(Program root)
 {
     var errors = new List<Error>();
     errors.AddRange(VariableTypeResolver.ResolveVariableType(root));
     errors.AddRange(BodyResolver.ResoloveBody(root));
     return errors;
 }
Ejemplo n.º 3
0
 public List<Error> Validate(Program root)
 {
     foreach (var err in validations.Select(x => x.Validate(root)).Where(err => err.Count != 0))
     {
         return err;
     }
     return new List<Error>();
 }
Ejemplo n.º 4
0
        public List<Error> Validate(Program root)
        {
            var errors = new List<Error>();

            errors.AddRange(RedefinitionChecker.Validate<Procedure>(root));

            foreach (var proc in root.GetSpecifiedChildren<Procedure>())
            {
                errors.AddRange(VariableTypeResolver.ResolveVariableType(proc));
                errors.AddRange(BodyResolver.ResoloveBody(proc));
            }
            return errors;
        }
Ejemplo n.º 5
0
 public List<Error> Validate(Program root)
 {
     var err = new List<Error>();
     err.AddRange(RedefinitionChecker.Validate<Record>(root));
     foreach (var rec in root.GetSpecifiedChildren<Record>())
     {
         err.AddRange(RedefinitionChecker.Validate<Variable>(rec));
         err.AddRange(VariableTypeResolver.ResolveVariableType(rec));
         foreach (var var in rec.GetSpecifiedChildren<Variable>())
         {
             if (var.Name.Text == rec.Name.Text)
                 err.Add(new Error(rec.GetSourceIdentifier(), rec.Name,
                                   string.Format(ErrorMessages.EnclosingRedef, rec.Name.Text)));
         }
     }
     return err;
 }
Ejemplo n.º 6
0
        public List<Error> Validate(Program root)
        {
            var errors = new List<Error>();

            errors.AddRange(RedefinitionChecker.Validate<Function>(root));

            foreach (var funcDef in root.GetSpecifiedChildren<Function>())
            {
                errors.AddRange(VariableTypeResolver.ResolveVariableType(funcDef));
                errors.AddRange(VariableTypeResolver.ResolveType(funcDef.ReturnType, funcDef));
                errors.AddRange(BodyResolver.ResoloveBody(funcDef));
                var list =
                    funcDef.GetSpecifiedChildren<Body>()
                           .First().Statements.OfType<Assignment>().Where(x=>x.Variable.First().Text == funcDef.Name.Text)
                           .ToList();
                if (list.Count == 0)
                    errors.Add(new Error(root.GetSourceIdentifier(), funcDef.Name,
                                         string.Format(ErrorMessages.FunctionReturnsNothing, funcDef.Name.Text)));
            }
            return errors;
        }