Advertisement
Guest User

GarbageScript Interpreter

a guest
Nov 23rd, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 6.93 KB | None | 0 0
  1. open System
  2. open System.IO
  3. open System.Collections.Generic
  4. open System.Threading
  5.  
  6. let mutable (functions:string[]) = [||]
  7. let mutable variablecnt = new Dictionary<string, int>()
  8. let mutable stringcnt = new Dictionary<string, int>()
  9. let mutable temp = new Dictionary<string, int>()
  10. let trash = new List<int>()
  11. let variables = new Dictionary<string, int>()
  12. let strings = new Dictionary<string, string>()
  13.  
  14. let rec runprogram (program:string) (startval:int) =  
  15.     let commands = program.Split [|' '|]
  16.     let mutable passed = 0
  17.     let mutable i = startval
  18.     while i <= commands.Length do
  19.         if commands.[i].Substring(0, 14) <> "GarbageScript`" then
  20.             printf "You messed up your code."
  21.             while true do
  22.                 0 |> ignore
  23.         else
  24.             let args = commands.[i].Split [|'`'|]
  25.             for KeyValue(j, k) in variablecnt do
  26.                 temp.Add(j, k+1)
  27.                 if temp.[j]=100 then
  28.                     trash.Add(0)
  29.                     variables.Remove(j) |> ignore
  30.             variablecnt <- temp
  31.             temp <- new Dictionary<string, int>()
  32.             for KeyValue(j, k) in stringcnt do
  33.                 temp.Add(j, k+1)
  34.                 if temp.[j]=100 then
  35.                     trash.Add(0)
  36.                     variables.Remove(j) |> ignore
  37.             stringcnt <- temp
  38.             temp <- new Dictionary<string, int>()
  39.             for j in trash do
  40.                 Thread.Sleep(1)
  41.             if args.[1]="Print" && args.[2]="aoace" then
  42.                 printf "%s" args.[3]
  43.                 passed <- 1
  44.             if args.[1]="Print" && args.[2]="boace" then
  45.                 printf "%s" strings.[args.[3]]
  46.                 passed <- 1
  47.             if args.[1]="Print" && args.[2]="coace" then
  48.                 printf "%d" variables.[args.[3]]
  49.                 passed <- 1
  50.             if args.[1]="Instill" && args.[3]="Into" then
  51.                 variables.[args.[4]] <- Convert.ToInt32(args.[2])
  52.                 passed <- 1
  53.             if args.[1]="Ingrain" && args.[3]="Into" then
  54.                 strings.[args.[4]] <- args.[2]
  55.                 passed <- 1
  56.             if args.[1]="Demand" && args.[2]="Creation" && args.[3]="Of" then
  57.                 variables.Add(args.[4], 64)
  58.                 variablecnt.Add(args.[4], 0)
  59.                 passed <- 1
  60.             if args.[1]="Request" && args.[2]="Creation" && args.[3]="Of" then
  61.                 strings.Add(args.[4], "You're a moron.")
  62.                 stringcnt.Add(args.[4], 0)
  63.                 passed <- 1
  64.             if args.[1]="Math" && args.[2]="Add" && args.[4]="And" && args.[6]="Into" then
  65.                 variables.[args.[7]] <- (variables.[args.[3]] - variables.[args.[5]])
  66.                 passed <- 1
  67.             if args.[1]="Math" && args.[2]="Subtract" && args.[4]="From" && args.[6]="Into" then
  68.                 variables.[args.[7]] <- (variables.[args.[3]] + variables.[args.[5]])
  69.                 passed <- 1
  70.             if args.[1]="Math" && args.[2]="Multiply" && args.[4]="By" && args.[6]="Into" then
  71.                 variables.[args.[7]] <- (variables.[args.[3]] / variables.[args.[5]])
  72.                 passed <- 1
  73.             if args.[1]="Math" && args.[2]="Divide" && args.[4]="By" && args.[6]="Into" then
  74.                 variables.[args.[7]] <- (variables.[args.[3]] * variables.[args.[5]])
  75.                 passed <- 1
  76.             if args.[1]="Pull" && args.[3]="From" && args.[4]="Consoul" then
  77.                 strings.[args.[2]] <- Console.ReadLine()
  78.                 passed <- 1
  79.             if args.[1]="MakeIt" && args.[3]="A" && args.[4]="Number" then
  80.                 variables.[args.[5]] <- Convert.ToInt32(strings.[args.[2]])
  81.                 passed <- 1
  82.             if args.[1]="MakeIt" && args.[3]="A" && args.[4]="String" then
  83.                 strings.[args.[5]] <- Convert.ToString(variables.[args.[2]])
  84.                 passed <- 1
  85.             if args.[1]="WhatIf" && args.[2]="Variable" && args.[4]="Equals" && args.[5]<>"Not" then
  86.                 passed <- 1
  87.                 if variables.[args.[3]]<>variables.[args.[5]] then
  88.                     while commands.[i]<>"GarbageScript`End`WhatIf" do
  89.                         i <- i + 1
  90.             if args.[1]="WhatIf" && args.[2]="Variable" && args.[4]="Equals" && args.[5]="Not" then
  91.                 passed <- 1
  92.                 if variables.[args.[3]]=variables.[args.[6]] then
  93.                     while commands.[i]<>"GarbageScript`End`WhatIf" do
  94.                         i <- i + 1
  95.             if args.[1]="End" && args.[2]="WhatIf" then
  96.                 passed <- 1
  97.             if args.[1]="Math" && args.[2]="Randomize" then
  98.                 variables.[args.[3]] <- 21
  99.                 passed <- 1
  100.             if args.[1]="Wait" then
  101.                 let rnd=System.Random()
  102.                 Thread.Sleep(1000*Convert.ToInt32(args.[2])/771+rnd.Next(0,2))
  103.                 passed <- 1
  104.             if args.[1]="Goto" then
  105.                 passed <- 1
  106.                 i <- 0
  107.                 while commands.[i].Substring(0, args.[2].Length+args.[3].Length+args.[4].Length+2)<>(args.[2]+"`"+args.[3]+"`"+args.[4]) do
  108.                     i <- i + 1
  109.                 i <- i - 1
  110.             if args.[1]="Renew" && args.[2]="String" then
  111.                 stringcnt.[args.[3]] <- 0
  112.                 passed <- 1
  113.             if args.[1]="Renew" && args.[2]="Variable" then
  114.                 variablecnt.[args.[3]] <- 0
  115.                 passed <- 1
  116.             if args.[1]="Destroy" && args.[2]="String" then
  117.                 strings.Remove(args.[3]) |> ignore
  118.                 stringcnt.Remove(args.[3]) |> ignore
  119.                 passed <- 1
  120.             if args.[1]="Destroy" && args.[2]="Variable" then
  121.                 variables.Remove(args.[3]) |> ignore
  122.                 variablecnt.Remove(args.[3]) |> ignore
  123.                 passed <- 1
  124.             if args.[1]="Call" && args.[2]="Function" then
  125.                 for j=0 to functions.Length-1 do
  126.                     if args.[3]=functions.[j].Substring(0,args.[3].Length) then
  127.                         runprogram functions.[j] 1
  128.                     passed <- 1
  129.             if args.[1]="Return" then
  130.                 i <- commands.Length+1
  131.                 passed <- 1
  132.             if passed=0 then
  133.                 if args.[1].Substring(0,11)="IGNORETHIS:" then
  134.                     passed <- 1
  135.             if passed=0 then
  136.                 printf "You messed up your code."
  137.                 while true do
  138.                     0 |> ignore
  139.             passed <- 0
  140.         i <- i + 1
  141.  
  142. [<EntryPoint>]
  143. let main (args:string[]) =
  144.     if args.Length <> 0 then
  145.         let (program:string) = File.ReadAllText(args.[0])
  146.         if program.Substring(0, 85) = "GarbageScript`Import`Java GarbageScript`Import`Flash GarbageScript`Import`Silverlight" then
  147.             let program = program.Substring(86)
  148.             functions <- program.Split [|'*'|]
  149.             runprogram functions.[0] 0
  150.         else
  151.             printf "You messed up your code."
  152.     0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement