![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Brain**** Compiler & Interpreter in Powershell Hi there! Perhaps some of you know the brain**** programming language (see http://en.wikipedia.org/wiki/Brain**** for more infos...) Here's a sample interpreter written in Powershell: # Powershell Brain**** Interpreter # File: bf2ps.ps1 # Author: Peter Schneider <ps.at.ugwa.net> # Date: 08 April 2007 # Usage: ./bf2ps <file.b> # # Sample Hello World Program: # ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. param ($i) $t = @{ '>'='$p++;'; '<'='$p--;'; '+'='$m[$p]++'; '-'='$m[$p]--'; '.'='write-host $([char]$m[$p]) -n '; ','='$m[$p]=$host.ui.ReadLine() '; '['='while ($m[$p] -ne 0) {'; ']'='}'; } $c = '$p=0;$m=new-object "byte[]" 32768'+"`n"; gc $i -Enc Byte -r 1 | % {$c+=$t["$([char]$_)"]+"`n"} invoke-expression $c And here's the script for the compiler: # Powershell Brain**** Compiler # File: bf2cs.ps1 # Author: Peter Schneider <ps.at.ugwa.net> # Date: 08 April 2007 # Usage: ./bf2cs <file.b> <file.c> [-run] # # Sample Hello World Program: # ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. param ( [string] $infile = $(throw "Please specify input file (.b)"), [string] $outfile = $(throw "Please specify output file (.cs)"), [switch] $run = $false ) $csc = (join-path ($env:windir) Microsoft.NET\Framework\v2.0.50727\csc.exe) $transpose = @{'>' = 'p++;'; '<' = 'p--;'; '+' = 'm[p]++;'; '-' = 'm[p]--;'; '.' = 'Console.Write(m[p]);'; ',' = 'm[p]=Console.ReadLine();'; '[' = "while (m[p]!=0) {"; ']' = '}'; } $header = @" using System; public class Program { public static void Main() { int p=0; char[] m=new char[32768]; "@ if ($(test-path $outfile)) { rm $outfile | out-null } $header | out-file $outfile -append get-content $infile -encoding Byte -readcount 1 | % { $transpose["$([char]$_)"] } | out-file $outfile -append "}}" | out-file $outfile -append & $csc `/target:exe $outfile | out-null if ($run) { $outfile = $outfile.Replace(".cs",".exe") & .`/$outfile } Have fun, Peter Schneider MVP Visual Developer - Visual C# MCT, MCSD.NET, MCAD.NET, MCDBA |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: Problem with Command Interpreter | Vista General | |||
| Re: Problem with Command Interpreter | Vista General | |||
| Re: Problem with Command Interpreter | Vista General | |||
| Real nested Powershell interpreter | PowerShell | |||
| Brainf*** Compiler and Interpreter in Powershell | PowerShell | |||