public SemanticsChecker(Program program, IErrorReporter errorReporter)
 {
     if (program.Scope == null)
         throw new ArgumentException("Global scope is undefined.");
     _programRoot = program;
     _symbolTable = (GlobalScope)program.Scope;
     _errors = errorReporter;
 }
        public SymbolTableBuilder(Program node, IErrorReporter errorReporter)
        {
            _errorReporter = errorReporter;
            _syntaxTree = node;
            _globalScope = new GlobalScope();

            _scopeStack = new Stack<IScope>();
        }
Esempio n. 3
0
 public CodeGenerator(Program abstractSyntaxTree, string moduleName, bool optimize = true)
 {
     if (abstractSyntaxTree.Scope == null)
         throw new ArgumentException("Global scope is undefined.");
     _moduleName = moduleName;
     _astRoot = abstractSyntaxTree;
     _symbolTable = (GlobalScope) abstractSyntaxTree.Scope;
     _constructors = new Dictionary<Type, ConstructorBuilder>();
     _types = new Dictionary<string, TypeBuilder>();
     _methods = new Dictionary<MethodSymbol, MethodBuilder>();
     _fields = new Dictionary<VariableSymbol, FieldBuilder>();
     _optimize = optimize;
 }
        private SymbolTableBuilder.ExitCode BuildSymbolTableFor(string program, out GlobalScope symbolTable)
        {
            var reader = new StringReader(program);
            var scanner = new MiniJavaScanner(reader);
            _errors = new ErrorLogger();
            var parser = new Parser(scanner, _errors, true);
            Program syntaxTree;
            parser.TryParse(out syntaxTree);
            reader.Close();
            Assert.That(_errors.Errors, Is.Empty);

            var symbolTableBuilder = new SymbolTableBuilder(syntaxTree, _errors);
            Assert.That(_errors.Errors, Is.Empty);

            var success = symbolTableBuilder.BuildSymbolTable();
            symbolTable = syntaxTree.Scope as GlobalScope;
            return success;
        }
Esempio n. 5
0
 public void SetUp()
 {
     _globalScope = new GlobalScope();
     _superSuperClass = SymbolCreationHelper.CreateAndDefineClass("Foo", _globalScope);
     _superClass = SymbolCreationHelper.CreateAndDefineClass("Bar", _globalScope);
     _superClass.SuperClass = _superSuperClass;
     _testClass = SymbolCreationHelper.CreateAndDefineClass("Baz", _globalScope);
     _testClass.SuperClass = _superClass;
     _someType = TypeSymbol.MakeScalarTypeSymbol("int", _globalScope).Type;
 }
Esempio n. 6
0
 public void SetUp()
 {
     _globalScope = new GlobalScope();
     _testClassScope = SymbolCreationHelper.CreateAndDefineClass("Foo", _globalScope).Scope;
     _someType = TypeSymbol.MakeScalarTypeSymbol("int", _globalScope).Type;
     _testMethodScope = SymbolCreationHelper.CreateAndDefineMethod(
         "foo", _someType, (IMethodScope)_testClassScope)
         .Scope;
 }
Esempio n. 7
0
 public void SetUp()
 {
     _globalScope = new GlobalScope();
     _blockScope = new ErrorScope(_globalScope);
     _internalBlockScope = new LocalScope(_blockScope);
     _someType = TypeSymbol.MakeScalarTypeSymbol("int", _globalScope).Type;
 }