Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // lol C#
- public class GStackVar
- {
- public Int32 name;
- public Double value;
- public GStackVar(String name, Double value)
- {
- this.name = name.GetHashCode();
- this.value = value;
- }
- }
- static GStackVar FindInStack(List<GStackVar> stack, String name)
- {
- Int32 n;
- n = name.GetHashCode();
- foreach (GStackVar var in stack)
- {
- if (var.name == n)
- return var;
- }
- return null;
- }
- // do it math? nope.
- static Double Evaluate(String[] line, Int32 start)
- {
- Double value;
- if (!Double.TryParse(line[start], out value))
- throw new Exception();
- return value;
- }
- static void Main()
- {
- StreamReader reader;
- List<GStackVar> stack;
- Int32 linenum;
- String line;
- String[] split;
- GStackVar var;
- reader = new StreamReader("C:\\main.g");
- stack = new List<GStackVar>();
- linenum = 0;
- while (!reader.EndOfStream)
- {
- line = reader.ReadLine();
- if (String.IsNullOrEmpty(line))
- continue;
- if (line[0] != '>')
- continue;
- line = line.Substring(1);
- split = line.Split(' ');
- if (split[0] == "implying" && split[2] == "=")
- {
- var = FindInStack(stack, split[1]);
- if (var == null && !Char.IsNumber(split[1][0]))
- stack.Add(new GStackVar(split[1], Evaluate(split, 3)));
- else
- var.value = Evaluate(split, 3);
- }
- else if (split[0] == "mfw")
- {
- var = FindInStack(stack, split[1]);
- if (var == null)
- Console.WriteLine("line {0}: Unknown variable \"{1}\"", linenum, split[1]);
- else
- Console.WriteLine(var.value);
- }
- else if (split[0] == "yfw")
- {
- var = FindInStack(stack, split[1]);
- if (var == null)
- Console.WriteLine("line {0}: Unknown variable \"{1}\"", linenum, split[1]);
- else
- {
- var.value = Double.Parse(Console.ReadLine());
- }
- }
- else
- {
- Console.WriteLine("line {0}: Unknown instruction \"{1}\"", linenum, split[0]);
- }
- linenum++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement