Skip to content

Commit

Permalink
Implement converter, change opcode, add floss
Browse files Browse the repository at this point in the history
  • Loading branch information
mochidaz committed Mar 28, 2022
1 parent bc5764c commit b6e366e
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 22 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ Anton Wibowo programming language, based on the [Brainfuck Esoteric Language](ht
![usage-1](assets/usage-1.png)

### From file
![usage-2](assets/usage-2.png)
![usage-2](assets/usage-2.png)

### Converter

You can convert brainfuck code into anton code like this

![usage-converter](assets/usage-converter.png)
Binary file modified assets/usage-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/usage-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/usage-converter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions samples/floss.at
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pypy,avlinux,pypy,pypy,pypy,floss,,wuzz,django,mxedition,floss,pypy,pypy,quantum,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,quantum,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,quantum,pypy,pypy,pypy,pypy,pypy,pypy,pypy,pypy,pypy,pypy,pypy,quantum,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,quantum,avlinux,pypy,floss,wuzz,wuzz,wuzz,wuzz,wuzz,django,mxedition,floss,pypy,quantum,wuzz,wuzz,wuzz,avlinux,pypy,floss,wuzz,wuzz,django,mxedition,floss,quantum,pypy,pypy,avlinux,pypy,pypy,pypy,floss,wuzz,django,mxedition,floss,quantum,wuzz,wuzz,wuzz,quantum,wuzz,wuzz,wuzz,wuzz,quantum,quantum,
2 changes: 1 addition & 1 deletion samples/hello.at
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,av,floss,wuzz,wuzz,wuzz,wuzz,av,floss,wuzz,wuzz,floss,wuzz,wuzz,wuzz,floss,wuzz,wuzz,wuzz,floss,wuzz,django,django,django,django,wagtail,mxedition,floss,wuzz,floss,wuzz,floss,wagtail,floss,floss,wuzz,av,django,mxedition,django,wagtail,mxedition,floss,floss,quantum,floss,wagtail,wagtail,wagtail,quantum,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,quantum,quantum,wuzz,wuzz,wuzz,quantum,floss,floss,quantum,django,wagtail,quantum,django,quantum,wuzz,wuzz,wuzz,quantum,wagtail,wagtail,wagtail,wagtail,wagtail,wagtail,quantum,wagtail,wagtail,wagtail,wagtail,wagtail,wagtail,wagtail,wagtail,quantum,floss,floss,wuzz,quantum,floss,wuzz,wuzz,quantum,
wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,avlinux,floss,wuzz,wuzz,wuzz,wuzz,avlinux,floss,wuzz,wuzz,floss,wuzz,wuzz,wuzz,floss,wuzz,wuzz,wuzz,floss,wuzz,django,django,django,django,pypy,mxedition,floss,wuzz,floss,wuzz,floss,pypy,floss,floss,wuzz,avlinux,django,mxedition,django,pypy,mxedition,floss,floss,quantum,floss,pypy,pypy,pypy,quantum,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,wuzz,quantum,quantum,wuzz,wuzz,wuzz,quantum,floss,floss,quantum,django,pypy,quantum,django,quantum,wuzz,wuzz,wuzz,quantum,pypy,pypy,pypy,pypy,pypy,pypy,quantum,pypy,pypy,pypy,pypy,pypy,pypy,pypy,pypy,quantum,floss,floss,wuzz,quantum,floss,wuzz,wuzz,quantum,
1 change: 1 addition & 0 deletions samples/hello.bf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
91 changes: 71 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::env;
use std::io::Read;
use std::io::{Read, Write};
use std::fs::File;

#[derive(Debug)]
Expand Down Expand Up @@ -31,6 +31,29 @@ enum Instruction {
Loop(Vec<Instruction>)
}

fn convert_code(source: String) -> String {

let mut converted_source = String::new();

for op in source.chars() {
let opcode = match op {
'>' => "floss,",
'<' => "django,",
'+' => "wuzz,",
'-' => "pypy,",
'.' => "quantum,",
',' => "wagtail,",
'[' => "avlinux,",
']' => "mxedition,",
_ => ""
};

converted_source.push_str(opcode);
}

converted_source
}

fn lex(source: String) -> Vec<OpCode> {
let mut operations = Vec::new();

Expand All @@ -41,10 +64,10 @@ fn lex(source: String) -> Vec<OpCode> {
"floss" => Some(OpCode::AntonIncPtr),
"django" => Some(OpCode::AntonDecPtr),
"wuzz" => Some(OpCode::AntonInc),
"wagtail" => Some(OpCode::AntoncDec),
"pypy" => Some(OpCode::AntoncDec),
"quantum" => Some(OpCode::NovelSifo),
"linux" => Some(OpCode::NovelSifoRead),
"av" => Some(OpCode::LoopBegin),
"wagtail" => Some(OpCode::NovelSifoRead),
"avlinux" => Some(OpCode::LoopBegin),
"mxedition" => Some(OpCode::LoopEnd),
_ => None
};
Expand Down Expand Up @@ -136,31 +159,59 @@ fn main() {
// Determine which file to execute
let args: Vec<String> = env::args().collect();

if args.len() != 2 {
println!("usage: at <file.at>");
if args.len() < 2 {
println!("usage: at <file.at> or at convert file.bf");
std::process::exit(1);
}

let input = &args[1];

let mut source = String::new();
match input.as_str() {
"convert" => {
if args.len() < 3 {
println!("usage: at <file.at> or at convert file.bf");
std::process::exit(1);
}

match File::open(input) {
Ok(mut v) => {
v.read_to_string(&mut source).expect("failed to read program file");
}
Err(_) => {
// To interpret directly
source.push_str(input);
let mut bf_source = String::new();

let mut bf_file = match File::open(&args[2]) {
Ok(v) => v,
Err(_) => panic!("Cannot open bf file!"),
};

bf_file.read_to_string(&mut bf_source).unwrap();

let mut file = match File::create(&args[2].replace(".bf", ".at")) {
Ok(f) => f,
Err(_) => panic!("Cannot create file!"),
};

let convert = convert_code(bf_source);

file.write_all(convert.as_bytes()).unwrap();
}
};
_ => {
let mut source = String::new();

match File::open(input) {
Ok(mut v) => {
v.read_to_string(&mut source).expect("failed to read program file");
}
Err(_) => {
// To interpret directly
source.push_str(input);
}
};

let opcodes = lex(source);
let opcodes = lex(source);

let program = parse(opcodes);
let program = parse(opcodes);

let mut tape: Vec<u8> = vec![0; 1024];
let mut data_pointer = 512;
let mut tape: Vec<u8> = vec![0; 1024];
let mut data_pointer = 512;

run(&program, &mut tape, &mut data_pointer);
run(&program, &mut tape, &mut data_pointer);
}
}
}

0 comments on commit b6e366e

Please sign in to comment.