public void AddVariableDeclaration(string name, string typeName) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("A variable name expected."); } if (string.IsNullOrEmpty(typeName)) { throw new ArgumentException($"A type name for the '{name}' variable expected."); } if (VariableDeclarations.ContainsKey(name)) { throw new CompilerException($"The '{name}' variable is already declared as the {VariableDeclarations[name].TypeName} type."); } switch (typeName) { case "INTEGER": VariableDeclarations.Add(name, VariableDeclaration.CreateIntegerVariableDeclaration(name)); break; case "REAL": VariableDeclarations.Add(name, VariableDeclaration.CreateRealVariableDeclaration(name)); break; case "CHAR": VariableDeclarations.Add(name, VariableDeclaration.CreateCharVariableDeclaration(name)); break; case "BOOLEAN": VariableDeclarations.Add(name, VariableDeclaration.CreateBooleanVariableDeclaration(name)); break; case "STRING": VariableDeclarations.Add(name, VariableDeclaration.CreateStringVariableDeclaration(name)); break; default: throw new CompilerException($"Unknown type '{typeName}' used for the '{name}' variable declaration."); } }
public void AddVar(VariableDeclarationBase variable) { VariableDeclarations.Add(variable); }