mirror of
https://github.com/Noratrieb/brainfuck.git
synced 2026-01-16 22:35:03 +01:00
interpreter
This commit is contained in:
parent
b30fa04dcc
commit
e815fd8c66
8 changed files with 647 additions and 19 deletions
|
|
@ -1,13 +1,35 @@
|
|||
import './App.scss';
|
||||
import CodeInput from "./components/CodeInput";
|
||||
import ProgramOutput from "./components/ProgramOutput";
|
||||
import React, {useState} from "react";
|
||||
import Interpreter from "./brainfuck/Interpreter";
|
||||
import RunInfo from "./components/RunInfo";
|
||||
|
||||
function App() {
|
||||
const [interpreter, setInterpreter] = useState<Interpreter | null>(null);
|
||||
|
||||
const [out, setOut] = useState("");
|
||||
const [input, setInput] = useState("");
|
||||
|
||||
const outHandler = (char: number) => {
|
||||
setOut(out => out + String.fromCharCode(char))
|
||||
}
|
||||
|
||||
const inHandler = (): number => {
|
||||
return 65;
|
||||
}
|
||||
|
||||
const start = () => setInterpreter(new Interpreter(input, outHandler, inHandler));
|
||||
const next = () => interpreter?.next();
|
||||
const prev = () => interpreter?.prev();
|
||||
|
||||
return (
|
||||
<div className="App-header">
|
||||
<div className="bf-input">
|
||||
<textarea placeholder="Input your code here..."/>
|
||||
</div>
|
||||
<CodeInput setInput={input => setInput(input)}/>
|
||||
<RunInfo nextHandler={next} prevHandler={prev} startHandler={start} interpreter={interpreter}/>
|
||||
<ProgramOutput text={out}/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
export default App;
|
||||
Loading…
Add table
Add a link
Reference in a new issue