Example #1
0
        static void CheckFile(string path)
        {
            var lexer = new WrapperLexer(new ANTLRFileStream(path));
            var tokens = new CommonTokenStream(lexer);
            var parser = new WrapperParser(tokens) {TreeAdaptor = new Adaptor()};
            var adaptor = new Adaptor();
            var errors = new List<SemanticError>();
            var syntacticErrors = new List<TigerError>();
            parser.TreeAdaptor = adaptor;

            try
            {
                //Syntactic Analisis
                var expression = parser.program();

                if (parser.NumberOfSyntaxErrors > 0 || lexer.NumberOfSyntaxErrors > 0 || parser.Errors.Count > 0 || lexer.Errors.Count > 0)
                {
                    syntacticErrors.AddRange(lexer.Errors.Concat(parser.Errors).Cast<TigerError>());
                    syntacticErrors.ForEach(PrintError);
                    Environment.ExitCode = 1;
                }
                else
                {
                    var scope = new Scope();
                    scope.SetTypes();
                    scope.SetFunctions();
                    var ast = (LanguageNode) expression.Tree;
                    //Semantic Analisis
                    ast.CheckSemantics(scope, errors);
                    if (errors.Count > 0 )
                        errors.ForEach(PrintError);
                    else
                    {
                        //Generate Code.
                        Console.WriteLine("No semantic error found.");
                        GenerateCode(ast, path);
                        Environment.ExitCode = 0;
                        Console.WriteLine("Successfull Code Generation");
                    }
                }
            }
            catch (Exception)
            {
                errors.ForEach(PrintError);
            }
        }
Example #2
0
        public Scope(Scope parent)
        {
            Parent = parent;
            Types = new Dictionary<string, TypeInfo>();
            Variables = new Dictionary<string, VariableInfo>();
            Routines = new Dictionary<string, RoutineInfo>();

            NumberScopes = parent != null ? NumberScopes + 1 : 0;
            CurrentScope = NumberScopes;

            if (parent != null)
            {
                if (parent.ChildenScopes == null)
                    parent.ChildenScopes = new List<Scope>();
                parent.ChildenScopes.Add(this);
            }
        }
Example #3
0
 public override void CheckSemantics(Scope scope, List<SemanticError> errors)
 {
     //check the nil assignation
     Value.CheckSemantics(scope, errors);
     Field.ExpressionType = Value.ExpressionType;
 }
 public override void CheckSemantics(Scope scope, List<SemanticError> errors)
 {
     CheckIdentifier(scope, errors);
     Identifier.ILName = scope.GetILTypeName(Identifier.Text);
 }