Skip to content

Latest commit

 

History

History
454 lines (267 loc) · 11.3 KB

API.md

File metadata and controls

454 lines (267 loc) · 11.3 KB

hirnfick

hirnfick

Table of contents

Classes

Compilation Functions

Syntax Checking Functions

Utility Functions

Compilation Functions

compileToC

compileToC(source, indentSize?, indentChar?): string

Converts a Brainfuck program to C.

Throws

BracketMismatchError if mismatching brackets are detected.

Parameters

Name Type Default value Description
source string undefined Brainfuck source to convert.
indentSize number 4 Indentation size.
indentChar string ' ' Indentation character.

Returns

string

Generated C code.

Defined in

src/compilers/c.ts:14


compileToCpp

compileToCpp(source, isMemoryDynamic?, indentSize?, indentChar?): string

Converts a Brainfuck program to C++.

Throws

BracketMismatchError if mismatching brackets are detected.

Parameters

Name Type Default value Description
source string undefined Brainfuck source to convert.
isMemoryDynamic boolean true Enable dynamic memory array.
indentSize number 4 Indentation size.
indentChar string ' ' Indentation character.

Returns

string

Generated C++ code.

Defined in

src/compilers/cpp.ts:15


compileToJsBase

compileToJsBase(source, isMemoryDynamic, enableUserInput, indentSize, indentChar): Object

Converts a Brainfuck program to JavaScript.

Description

This function is used by compileToJsWeb, compileToJsNode and compileToJsDeno to generate their output. You can use it to write functions that generate output for other JavaScript-based platforms.

Throws

BracketMismatchError if mismatching brackets are detected.

Parameters

Name Type Description
source string Brainfuck source to convert.
isMemoryDynamic boolean Enable dynamic memory array.
enableUserInput boolean Enable user input handling.
indentSize number Indentation size.
indentChar string Indentation character.

Returns

Object

Name Type
declaration string[]
definition string[]

Defined in

src/compilers/javascript-base.ts:19


compileToJsDeno

compileToJsDeno(source, isMemoryDynamic?, mainFunctionName?, indentSize?, indentChar?): string

Converts a Brainfuck program to JavaScript (Deno).

Throws

BracketMismatchError if mismatching brackets are detected.

Parameters

Name Type Default value Description
source string undefined Brainfuck source to convert.
isMemoryDynamic boolean true Enable dynamic memory array.
mainFunctionName string 'main' Main function name.
indentSize number 2 Indentation size.
indentChar string ' ' Indentation character.

Returns

string

Generated JavaScript code.

Defined in

src/compilers/javascript-deno.ts:15


compileToJsNode

compileToJsNode(source, isMemoryDynamic?, mainFunctionName?, indentSize?, indentChar?): string

Converts a Brainfuck program to JavaScript (Node.js).

Throws

BracketMismatchError if mismatching brackets are detected.

Parameters

Name Type Default value Description
source string undefined Brainfuck source to convert.
isMemoryDynamic boolean true Enable dynamic memory array.
mainFunctionName string 'main' Main function name.
indentSize number 2 Indentation size.
indentChar string ' ' Indentation character.

Returns

string

Generated JavaScript code.

Defined in

src/compilers/javascript-node.ts:15


compileToJsWeb

compileToJsWeb(source, isMemoryDynamic?, mainFunctionName?, indentSize?, indentChar?): string

Converts a Brainfuck program to JavaScript (Web).

Throws

BracketMismatchError if mismatching brackets are detected.

Parameters

Name Type Default value Description
source string undefined Brainfuck source to convert.
isMemoryDynamic boolean true Enable dynamic memory array.
mainFunctionName string 'main' Output function name.
indentSize number 2 Indentation size.
indentChar string ' ' Indentation character.

Returns

string

Generated JavaScript function source.

Defined in

src/compilers/javascript-web.ts:15


compileToPascal

compileToPascal(source, programName?, indentSize?, indentChar?): string

Converts a Brainfuck program to Pascal.

Throws

BracketMismatchError if mismatching brackets are detected.

Parameters

Name Type Default value Description
source string undefined Brainfuck source to convert.
programName string 'Hirnfick' Name of the generate program (i.e. 'program programName;').
indentSize number 2 Indentation size.
indentChar string ' ' Indentation character.

Returns

string

Generated Pascal code.

Defined in

src/compilers/pascal.ts:15


compileToPython

compileToPython(source, isMemoryDynamic?): string

Converts a Brainfuck program to a Python.

Throws

BracketMismatchError if mismatching brackets are detected.

Parameters

Name Type Default value Description
source string undefined Brainfuck source to convert.
isMemoryDynamic boolean true Enable dynamic memory array.

Returns

string

Generated Python code.

Defined in

src/compilers/python.ts:13


compileToQBasic

compileToQBasic(source, isMemoryDynamic?, indentSize?, indentChar?): string

Converts a Brainfuck program to QBasic.

Throws

BracketMismatchError if mismatching brackets are detected.

Parameters

Name Type Default value Description
source string undefined Brainfuck source to convert.
isMemoryDynamic boolean false Enable dynamic memory array.
indentSize number 2 Indentation size.
indentChar string ' ' Indentation character.

Returns

string

Generated QBasic code.

Defined in

src/compilers/qbasic.ts:15


compileToRust

compileToRust(source, isMemoryDynamic?, indentSize?, indentChar?): string

Converts a Brainfuck program to Rust.

Throws

BracketMismatchError if mismatching brackets are detected.

Parameters

Name Type Default value Description
source string undefined Brainfuck source to convert.
isMemoryDynamic boolean true Enable dynamic memory array.
indentSize number 4 Indentation size.
indentChar string ' ' Indentation character.

Returns

string

Generated Rust code.

Defined in

src/compilers/rust.ts:15


Syntax Checking Functions

hasInfiniteLoops

hasInfiniteLoops(source): boolean

Checks whether a program contains infinite loops.

Parameters

Name Type Description
source string Brainfuck source to check.

Returns

boolean

True if the program is contains an infinite loop, false if it doesn't.

Defined in

src/utils/syntax-checking.ts:30


hasMismatchingLoopBoundaries

hasMismatchingLoopBoundaries(source): boolean

Checks whether a program contains mismatching loop boundaries.

Parameters

Name Type Description
source string Brainfuck source to check.

Returns

boolean

True if the program contains mismatching loop boundaries, false if it doesn't.

Defined in

src/utils/syntax-checking.ts:8


Utility Functions

cleanCode

cleanCode(source): string

Strips comments from Brainfuck source and then cleans the code from anything that's not a Brainfuck command.

Parameters

Name Type Description
source string Brainfuck code to clean up.

Returns

string

Cleaned up Brainfuck code.

Defined in

src/utils/utils.ts:21


genIndent

genIndent(depth, size, char): string

Generates an indentation string.

Parameters

Name Type Description
depth number Indentation depth.
size number Indentation size.
char string Indentation character.

Returns

string

Defined in

src/utils/utils.ts:33