Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Brainf__k_net - Module1.vb

Module1.vb

Caricato da: Manvb.net
Scarica il programma completo

  1. Option Strict On
  2. Option Explicit On
  3. Imports System
  4. Module Module1
  5.     Sub Main()
  6.         If My.Application.CommandLineArgs.Count < 1 Then
  7.             Console.WriteLine("Usage: Brainf__k <filename>")
  8.             Console.ReadKey()
  9.             End
  10.         End If
  11.         '****************** DICHIARAZIONI *****************************
  12.         tbyte = "Public Structure bbyte" & newline & _
  13.         "Public val As Byte" & newline & _
  14.         "Public Sub inc()" & newline & _
  15.         "If Me.val = 255 Then" & newline & _
  16.         "Me.val = 0" & newline & _
  17.         "reg=1" & newline & _
  18.         "Else" & newline & _
  19.         "Me.val = me.val + 1" & newline & _
  20.         "End If" & newline & _
  21.         "End Sub" & newline & _
  22.         "Public Sub dec()" & newline & _
  23.         "If Me.val = 0 Then" & newline & _
  24.         "Me.val = 255" & newline & _
  25.         "reg=2" & newline & _
  26.         "Else" & newline & _
  27.         "Me.val = me.val - 1" & newline & _
  28.         "End If" & newline & _
  29.         "End Sub" & newline & _
  30.         "Public Sub ass(ByVal value As Byte)" & newline & _
  31.         "Me.val = value" & newline & _
  32.         "End Sub" & newline & _
  33.         "End Structure" & newline
  34.         smain = "Sub Main()" & newline
  35.         esub = "End Sub" & newline
  36.         ar = "Dim ar(1048576) As bbyte" & newline
  37.         vx = "Dim x As Integer = 0" & newline & "'Da qui inizia il codice vero e proprio" & newline
  38.         code = "Imports System" & newline & "Module Module1" & newline & "Public file As IO.FileStream" & newline & "public reg as byte" & newline & "Public fo as string" & newline
  39.         '**************** FINE DICHIARAZIONI **************************
  40.         '--------------------------------------------------------------
  41.         '**************** SCRITTURA ISTRUZIONI ************************
  42.         _inc = "ar(x).inc()" & newline
  43.         _dec = "ar(x).dec()" & newline
  44.         _in = "ar(x).val = Convert.ToByte(Console.ReadKey.KeyChar)" & newline
  45.         _out = "System.Console.Write(Convert.ToChar(ar(x).val))" & newline
  46.         _ipt = "x = x + 1" & newline
  47.         _dpt = "x = x - 1" & newline
  48.         _sloop = "do while (ar(x).val <> 0)" & newline
  49.         _eloop = "loop" & newline
  50.         _oun = "System.Console.Write((ar(x).val).ToString())" & newline
  51.         _car = "ar(x).val = reg" & newline
  52.         _scar = "reg = ar(x).val" & newline
  53.         _fop = "fo=""""" & newline & "do while ar(x).val <> 0" & newline & _
  54.                "fo = fo & convert.tochar(ar(x).val)" & newline & "loop" & newline & "fo=fo.replace(""?patch"", ""My.Application.CommandLineArgs(0).Split(""."")(0)"")" & newline & "file = New IO.FileStream(fo, IO.FileMode.OpenOrCreate)" & newline
  55.         _fin = "ar(x).val = convert.tobyte(file.readbyte())" & newline
  56.         _fout = "file.writebyte(ar(x).val)" & newline
  57.         _fcl = "file.close()" & newline & "file = nothing" & newline
  58.         _mod = "ar(x).val = ar(x).val mod ar(x-1).val" & newline
  59.         _mul = "ar(x).val = ar(x).val * ar(x-1).val" & newline
  60.         _div = "ar(x).val = ar(x).val \ ar(x-1).val" & newline
  61.         _iun = "ar(x).val = int32.parse(console.readline()) and 255" & newline
  62.         '****************** FINE ISTRUZIONI ***************************
  63.         Dim source As String = My.Computer.FileSystem.ReadAllText(My.Application.CommandLineArgs(0))
  64.         Dim x As Integer
  65.         Dim vb As New Microsoft.VisualBasic.VBCodeProvider()
  66.         Dim parameters As New CodeDom.Compiler.CompilerParameters
  67.         Dim res As CodeDom.Compiler.CompilerResults
  68.         Dim asm As System.Reflection.Assembly
  69.         For Each asm In AppDomain.CurrentDomain.GetAssemblies
  70.             parameters.ReferencedAssemblies.Add(asm.Location)
  71.         Next
  72.         parameters.GenerateExecutable = True
  73.         parameters.OutputAssembly = My.Application.CommandLineArgs(0) & ".exe"
  74.         code = code & tbyte & smain & ar & vx
  75.         Dim z As Integer
  76.         Dim temp As String
  77.         For x = 0 To source.Length - 1
  78.             If source(x) = "(" Then
  79.                 For z = 1 To 9
  80.                     temp = temp & source(x - 1)
  81.                 Next
  82.                 source.Replace(source(x - 1) & "(", temp)
  83.                 temp = ""
  84.                 z = 0
  85.             End If
  86.             If source(x) = ")" Then
  87.                 For z = 1 To 99
  88.                     temp = temp & source(x - 1)
  89.                 Next
  90.                 source.Replace(source(x - 1) & "(", temp)
  91.                 temp = ""
  92.                 z = 0
  93.             End If
  94.             If source(x) = "{" Then
  95.                 For z = 1 To 999
  96.                     temp = temp & source(x - 1)
  97.                 Next
  98.                 source.Replace(source(x - 1) & "(", temp)
  99.                 temp = ""
  100.                 z = 0
  101.             End If
  102.             If source(x) = "}" Then
  103.                 For z = 1 To 9999
  104.                     temp = temp & source(x - 1)
  105.                 Next
  106.                 source.Replace(source(x - 1) & "(", temp)
  107.                 temp = ""
  108.                 z = 0
  109.             End If
  110.             If source(x) = "+" Then
  111.                 code = code & _inc
  112.             End If
  113.             If source(x) = "-" Then
  114.                 code = code & _dec
  115.             End If
  116.             If source(x) = "," Then
  117.                 code = code & _in
  118.             End If
  119.             If source(x) = "." Then
  120.                 code = code & _out
  121.             End If
  122.             If source(x) = ">" Then
  123.                 code = code & _ipt
  124.             End If
  125.             If source(x) = "<" Then
  126.                 code = code & _dpt
  127.             End If
  128.             If source(x) = "[" Then
  129.                 code = code & _sloop
  130.             End If
  131.             If source(x) = "]" Then
  132.                 code = code & _eloop
  133.             End If
  134.             If source(x) = "?" Then
  135.                 code = code & _car
  136.             End If
  137.             If source(x) = "@" Then
  138.                 code = code & _scar
  139.             End If
  140.             If source(x) = "&" Then
  141.                 code = code & _fop
  142.             End If
  143.             If source(x) = "'" Then
  144.                 code = code & _fin
  145.             End If
  146.             If source(x) = Convert.ToChar(34) Then
  147.                 code = code & _fout
  148.             End If
  149.             If source(x) = "|" Then
  150.                 code = code & _fcl
  151.             End If
  152.             If source(x) = "%" Then
  153.                 code = code & _mod
  154.             End If
  155.             If source(x) = "!" Then
  156.                 code = code & _oun
  157.             End If
  158.             If source(x) = "*" Then
  159.                 code = code & _mul
  160.             End If
  161.             If source(x) = "/" Then
  162.                 code = code & _div
  163.             End If
  164.             If source(x) = "^" Then
  165.                 code = code & _iun
  166.             End If
  167.         Next
  168.         code = code & esub & "End Module"
  169.         Console.Write(code)
  170.         res = vb.CompileAssemblyFromSource(parameters, code)
  171.         Dim y As Integer
  172.         Dim codes() As String = code.Split(newline.ToCharArray)
  173.         For y = 0 To res.Errors.Count - 1
  174.             Console.WriteLine("Errore " & res.Errors(y).Line & ": " & res.Errors(y).ErrorText)
  175.             Console.WriteLine("... " & codes(32) & newline)
  176.         Next
  177.         Console.WriteLine()
  178.         Console.WriteLine()
  179.         Console.WriteLine()
  180.         Console.WriteLine("L'eseguibile è stato creato nella cartella del sorgente!")
  181.         Console.WriteLine("Premi e per uscire.")
  182.         Console.WriteLine("Premi s per salvare il codice vb del programma a scopo di studio ed uscire.")
  183.         Console.WriteLine()
  184.         Dim k As Char
  185.         k = Console.ReadKey.KeyChar
  186.         If k = "s" Then
  187.             My.Computer.FileSystem.WriteAllText(My.Application.CommandLineArgs(0) & ".vb", code, False)
  188.         End If
  189.     End Sub
  190. End Module