예제 #1
0
 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;
 }
예제 #2
0
        public SymbolTableBuilder(Program node, IErrorReporter errorReporter)
        {
            _errorReporter = errorReporter;
            _syntaxTree = node;
            _globalScope = new GlobalScope();

            _scopeStack = new Stack<IScope>();
        }
예제 #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;
        }
예제 #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;
 }
예제 #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;
 }
예제 #7
0
 public void SetUp()
 {
     _globalScope = new GlobalScope();
     _blockScope = new ErrorScope(_globalScope);
     _internalBlockScope = new LocalScope(_blockScope);
     _someType = TypeSymbol.MakeScalarTypeSymbol("int", _globalScope).Type;
 }