Advertisement
Aptennap

Elog, C# interpreter

Oct 1st, 2011
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System;
  3.  
  4. namespace Elog {
  5.     public class Elog {
  6.         public static void Main(string[] args) {
  7.             if(args.Length == 1) run(System.IO.File.ReadAllText(args[0]), "");
  8.             else if(args.Length > 1) {
  9.                 string f = System.IO.File.ReadAllText(args[0]);
  10.                 for(int i = 1; i < args.Length; run(f, args[i++])) ;
  11.             }
  12.         }
  13.    
  14.         public static void run(string s, string inr) {
  15.             int cur = 0, sts = 0;
  16.             Stack<bool> st = new Stack<bool>();
  17.             bool[] ins = new bool[inr.Length];
  18.             int[] vars = new int[256];
  19.             for(int i=0;i<256;vars[i++] = -1);
  20.             for(int i=0;i<inr.Length;ins[i] = (inr[i++]-'0'==0?false:true));
  21.             foreach(char c in s) {
  22.                 if(sts == 0) {
  23.                     if(c == ';') sts = 2;
  24.                     else if(c == ':') sts = 1;
  25.                     else if(c == '.') st.Push(st.Peek());
  26.                     else if(c == '\'') st.Push(st.Pop()?false:true);
  27.                     else if(c == '&') st.Push(st.Pop() && st.Pop());
  28.                     else if(c == '|') st.Push(st.Pop() || st.Pop());
  29.                     else if(c == '^') st.Push(st.Pop() ^ st.Pop());            
  30.                     else if(c == '0') st.Push(false);
  31.                     else if(c == '1') st.Push(true);
  32.                     else if(c > 20) {
  33.                         if(vars[c] == -1) vars[c] = (ins[cur++]?1:0);
  34.                         if(vars[c] > -1) st.Push(vars[c]==1);
  35.                     }
  36.                 } else if(sts == 1 && c > 20) {
  37.                     vars[c] = (st.Pop()?1:0);
  38.                     sts = 0;
  39.                 } else if(c > 20) if(c == '0' || c == '1') Console.Write(c); else Console.Write(vars[c]);
  40.             }
  41.             Console.WriteLine();
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement