//main public override void InAMain(AMain node) { // build def for allowed types BasicTypeDefinition intType; intType = new BasicTypeDefinition(); intType.name = "int"; BasicTypeDefinition fltType; fltType = new BasicTypeDefinition(); fltType.name = "float"; BasicTypeDefinition boolType; boolType = new BasicTypeDefinition(); boolType.name = "boolean"; StringTypeDefinition stringType = new StringTypeDefinition(); stringType.name = "string"; // create and seed symbol tables _currentSymbolTable = new Dictionary <string, Definition>(); _currentSymbolTable.Add("int", intType); _currentSymbolTable.Add("float", fltType); _currentSymbolTable.Add("boolean", boolType); _currentSymbolTable.Add("string", stringType); }
public override void InAFunctionFunctionDeclaration(AFunctionFunctionDeclaration node) { // Save current symbol table. _previousSymbolTables.AddFirst(_currentSymbolTable); // Build definitions for allowed types according to grammar. CS426 only allows int and string and float BasicTypeDefinition intType; intType = new BasicTypeDefinition(); intType.name = "int"; StringTypeDefinition stringType = new StringTypeDefinition(); stringType.name = "string"; BasicTypeDefinition floatType; floatType = new BasicTypeDefinition(); floatType.name = "float"; // Create and seed the symbol table. if (!_functionSymbolTable.ContainsKey("int")) { _functionSymbolTable.Add("int", intType); _functionSymbolTable.Add("string", stringType); _functionSymbolTable.Add("float", floatType); } }
//in method public override void InAMethod(AMethod node) { // save current symbol table _previousSymbolTables.AddFirst(_currentSymbolTable); // build new param list _currentParamList = new List <VariableDefinition>(); // build def allowed by types according to grammar BasicTypeDefinition intType; intType = new BasicTypeDefinition(); intType.name = "int"; BasicTypeDefinition fltType; fltType = new BasicTypeDefinition(); fltType.name = "float"; BasicTypeDefinition boolType; boolType = new BasicTypeDefinition(); boolType.name = "boolean"; StringTypeDefinition stringType = new StringTypeDefinition(); stringType.name = "string"; // create and seed symbol table _currentSymbolTable = new Dictionary <string, Definition>(); _currentSymbolTable.Add("int", intType); _currentSymbolTable.Add("float", fltType); _currentSymbolTable.Add("boolean", boolType); _currentSymbolTable.Add("string", stringType); }
public override void InAMainProgram(AMainProgram node) { // Build definitions for allowed types according to grammar. CS246 grammar only allows int, string, and float BasicTypeDefinition intType; intType = new BasicTypeDefinition(); intType.name = "int"; StringTypeDefinition stringType = new StringTypeDefinition(); stringType.name = "string"; BasicTypeDefinition floatType = new BasicTypeDefinition(); floatType.name = "float"; // Create and seed the symbolTable _currentSymbolTable = new Dictionary <string, Definition>(); _currentSymbolTable.Add("int", intType); _currentSymbolTable.Add("string", stringType); _currentSymbolTable.Add("float", floatType); }