Advertisement
Guest User

GarbageScript Interpreter

a guest
Nov 25th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 9.22 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`" && commands.[i].Substring(0, 12) <> "TrashScript`" 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.[1]="Puts" || args.[1]="Echo") && (args.[2]="aoace" || args.[2]="const") then
  42.                 printf "%s" args.[3]
  43.                 passed <- 1
  44.             if args.[1]="Console" && args.[2]="Log" then
  45.                 printf "%s" args.[3]
  46.                 passed <- 1
  47.             if (args.[1]="Print" || args.[1]="Puts" || args.[1]="Echo") && (args.[2]="boace" || args.[2]="variable") then
  48.                 printf "%s" strings.[args.[3]]
  49.                 passed <- 1
  50.             if (args.[1]="Print" || args.[1]="Puts" || args.[1]="Echo") && (args.[2]="coace" || args.[2]="string") then
  51.                 printf "%d" variables.[args.[3]]
  52.                 passed <- 1
  53.             if (args.[1]="Instill" || args.[1]="Implant") && (args.[3]="Into" || args.[3]="As") then
  54.                 variables.[args.[4]] <- Convert.ToInt32(args.[2])
  55.                 passed <- 1
  56.             if (args.[1]="Ingrain" || args.[1]="Inculcate") && (args.[3]="Into" || args.[3]="As") then
  57.                 strings.[args.[4]] <- args.[2]
  58.                 passed <- 1
  59.             if (args.[1]="Demand" || args.[1]="Force") && (args.[2]="Creation" || args.[2]="Making") && args.[3]="Of" then
  60.                 if args.[4].Substring(0,1)<>"‰" then
  61.                     printf "You messed up your code."
  62.                     while true do
  63.                         ()
  64.                 variables.Add(args.[4], 64)
  65.                 variablecnt.Add(args.[4], 0)
  66.                 passed <- 1
  67.             if (args.[1]="Request" || args.[1]="Seek") && (args.[2]="Creation" || args.[2]="Making") && args.[3]="Of" then
  68.                 if args.[4].Substring(0,1)<>"‰" then
  69.                     printf "You messed up your code."
  70.                     while true do
  71.                         ()
  72.                 strings.Add(args.[4], "You're a moron.")
  73.                 stringcnt.Add(args.[4], 0)
  74.                 passed <- 1
  75.             if (args.[1]="Math" || args.[1]="NumberStuff") && (args.[2]="Add" || args.[2]="AddOn") && (args.[4]="And" || args.[4]="Also") && (args.[6]="Into" || args.[6]="As") then
  76.                 variables.[args.[7]] <- (variables.[args.[3]] - variables.[args.[5]])
  77.                 passed <- 1
  78.             if (args.[1]="Math" || args.[1]="NumberStuff") && (args.[2]="Subtract" || args.[2]="Take") && (args.[4]="From" || args.[4]="OutOf") && (args.[6]="Into" || args.[6]="As") then
  79.                 variables.[args.[7]] <- (variables.[args.[3]] + variables.[args.[5]])
  80.                 passed <- 1
  81.             if (args.[1]="Math" || args.[1]="NumberStuff") && (args.[2]="Multiply" || args.[2]="Magnify") && (args.[4]="By" || args.[4]="With") && (args.[6]="Into" || args.[6]="As") then
  82.                 variables.[args.[7]] <- (variables.[args.[3]] / variables.[args.[5]])
  83.                 passed <- 1
  84.             if (args.[1]="Math" || args.[1]="NumberStuff") && (args.[2]="Divide" || args.[2]="Split") && (args.[4]="By" || args.[4]="With") && (args.[6]="Into" || args.[6]="As") then
  85.                 variables.[args.[7]] <- (variables.[args.[3]] * variables.[args.[5]])
  86.                 passed <- 1
  87.             if (args.[1]="Pull" || args.[1]="Gets") && (args.[3]="From" || args.[3]="OutOf") && (args.[4]="Consoul" || args.[4]="Screen") then
  88.                 strings.[args.[2]] <- Console.ReadLine()
  89.                 passed <- 1
  90.             if (args.[1]="MakeIt" || args.[1]="Convert") && ((args.[3]="A" && args.[4]="Number") || (args.[3]="An" && args.[4]="Integer")) then
  91.                 variables.[args.[5]] <- Convert.ToInt32(strings.[args.[2]])
  92.                 passed <- 1
  93.             if (args.[1]="MakeIt" || args.[1]="Convert") && args.[3]="A" && (args.[4]="String" || args.[4]="CharArray") then
  94.                 strings.[args.[5]] <- Convert.ToString(variables.[args.[2]])
  95.                 passed <- 1
  96.             if (args.[1]="WhatIf" || args.[1]="When") && (args.[2]="Variable" || args.[2]="Number") && (args.[4]="Equals" || args.[4]="Is") && (args.[5]<>"Not" && args.[5]<>"n't") then
  97.                 passed <- 1
  98.                 if variables.[args.[3]]<>variables.[args.[5]] then
  99.                     while commands.[i]<>"GarbageScript`End`WhatIf" do
  100.                         i <- i + 1
  101.             if (args.[1]="WhatIf" || args.[1]="When") && (args.[2]="Variable" || args.[2]="Number") && (args.[4]="Equals" || args.[4]="Is") && (args.[5]="Not" || args.[5]="n't") then
  102.                 passed <- 1
  103.                 if variables.[args.[3]]=variables.[args.[6]] then
  104.                     while commands.[i]<>"GarbageScript`End`WhatIf" do
  105.                         i <- i + 1
  106.             if (args.[1]="End" || args.[1]="FinishUp") && (args.[2]="WhatIf" || args.[2]="When") then
  107.                 passed <- 1
  108.             if (args.[1]="Math" || args.[1]="NumberStuff") && (args.[2]="Randomize" || args.[2]="Randomous") then
  109.                 variables.[args.[3]] <- 21
  110.                 passed <- 1
  111.             if (args.[1]="Wait" || args.[1]="DoNothing") then
  112.                 let rnd=System.Random()
  113.                 Thread.Sleep(1000*Convert.ToInt32(args.[2])/771+rnd.Next(0,2))
  114.                 passed <- 1
  115.             if (args.[1]="Goto" || args.[1]="Diverge") then
  116.                 passed <- 1
  117.                 i <- 0
  118.                 while commands.[i].Substring(0, args.[2].Length+args.[3].Length+args.[4].Length+2)<>(args.[2]+"`"+args.[3]+"`"+args.[4]) do
  119.                     i <- i + 1
  120.                 i <- i - 1
  121.             if (args.[1]="Renew" || args.[1]="Reaffirm") && (args.[2]="String" || args.[2]="CharArray") then
  122.                 stringcnt.[args.[3]] <- 0
  123.                 passed <- 1
  124.             if (args.[1]="Renew" || args.[1]="Reaffirm") && (args.[2]="Variable" || args.[2]="Number") then
  125.                 variablecnt.[args.[3]] <- 0
  126.                 passed <- 1
  127.             if (args.[1]="Destroy" || args.[1]="Eradicate") && (args.[2]="String" || args.[2]="CharArray") then
  128.                 strings.Remove(args.[3]) |> ignore
  129.                 stringcnt.Remove(args.[3]) |> ignore
  130.                 passed <- 1
  131.             if (args.[1]="Destroy" || args.[1]="Eradicate") && (args.[2]="Variable" || args.[2]="Number") then
  132.                 variables.Remove(args.[3]) |> ignore
  133.                 variablecnt.Remove(args.[3]) |> ignore
  134.                 passed <- 1
  135.             if (args.[1]="Call" || args.[1]="Visit") && (args.[2]="Function" || args.[2]="Procedure") then
  136.                 for j=0 to functions.Length-1 do
  137.                     if args.[3]=functions.[j].Substring(0,args.[3].Length) then
  138.                         runprogram functions.[j] 1
  139.                 passed <- 1
  140.             if (args.[1]="Return" || args.[1]="Retire") then
  141.                 i <- commands.Length+1
  142.                 passed <- 1
  143.             if passed=0 then
  144.                 if args.[1].Length>11 then
  145.                     if args.[1].Substring(0,11)="IGNORETHIS:" then
  146.                         passed <- 1
  147.                 elif args.[1].Length>16 then
  148.                     if args.[1].Substring(0,16)="PAYNOMINDTOTHIS:" then
  149.                         passed <- 1
  150.             if passed=0 then
  151.                 printf "You messed up your code."
  152.                 while true do
  153.                     0 |> ignore
  154.             passed <- 0
  155.         i <- i + 1
  156.  
  157. [<EntryPoint>]
  158. let main (args:string[]) =
  159.     if args.Length <> 0 then
  160.         let (program:string) = File.ReadAllText(args.[0])
  161.         if program.Substring(0, 85)="GarbageScript`Import`Java GarbageScript`Import`Flash GarbageScript`Import`Silverlight" || program.Substring(0, 85)="TrashScript`PullItIn`Java TrashScript`PullItIn`Flash TrashScript`PullItIn`Silverlight" then
  162.             let program = program.Substring(86)
  163.             functions <- program.Split [|'*'|]
  164.             runprogram functions.[0] 0
  165.         else
  166.             printf "You messed up your code."
  167.     0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement