using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GASi { public enum kType { STRING, INT, FLOAT, DATE, BOOL, VOID } class Conversion { public static kType StringToType(string str) { try { return (kType)Enum.Parse(typeof(kType), str, true); } catch { throw Transpiler.Exception("Could not determine type implied by keyword '"+ str +"'", 0, 0); } } } class ScopeTable { private List Variables = new List(); public void AddVariable(Variable var) { if(!CheckVariableExists(var.Name)) Variables.Add(var); else throw Transpiler.Exception("Variable already exists with name '" + var.Name + "' in this scope", 0, 0); } public bool CheckVariableExists(string name) { return Variables.FirstOrDefault(x => x.Name == name) != null; } public Variable GetVariable(string name) { return Variables.FirstOrDefault(x => x.Name == name); } public class Variable { public string Name { get; set; } public kType Type { get; set; } } } class MethodTable { private List Methods = new List(); public void AddMethod(Method method) { // TODO determine if GAS allows function overloading if(!CheckMethodExists(method.Name)) Methods.Add(method); else throw Transpiler.Exception("Method already exists with name '" + method.Name + "'", 0, 0); } public bool CheckMethodExists(string name) { return Methods.FirstOrDefault(x => x.Name == name) != null; } public Method GetMethod(string name) { return Methods.FirstOrDefault(x => x.Name == name); } public class Method { public string Name { get; set; } public kType ReturnType { get; set; } public List Arguments { get; set; } public ScopeTable Scope { get; set; } = new ScopeTable(); public class Argument { public string Name { get; set; } public kType Type { get; set; } } } } }