pp4th(1)
pp4th(1) π A Portable Forth Preprocessor That Slays
okay so bestie, meet pp4th β a portable Forth preprocessor that supports a (modified) subset of ANS-Forth. iykyk. β¨
β¨ SYNTAX β¨
pp4th [options] [file] [argument .. argument]
π¦ DESCRIPTION π¦
okay so pp4th is literally a command line bytecode compiler, preprocessor, virtual machine, decompiler and C-source generator all rolled into one tiny little program. no cap. you can use it to create portable bytecode programs, standalone executables, or as a scripting language or a Forth-to-C translator. for the full tea, read the manual. periodt. π
π OPTIONS π
-Vβ show version and exit. simple, iconic.-vβ enter verbose mode. she's chatty now.-xβ execute a 4tH program. run it, bestie.-pβ preprocess a 4tH preprocessor file.-dβ decompile a 4tH program. reverse engineering vibes.-cβ load a sourcefile and compile it.-sβ save a 4tH program. default isout.hx. π«Ά-gβ generate a C sourcefile. default isout.c.-kβ keep intermediate file. no deleting the evidence.-nβ enables a symbolic decompile in conjunction with the-doption.-iβ show all files included hierarchically.-o filenameβ specify the name of the output file when preprocessing, generating or saving.-D symbolβ define symbol as a CONSTANT, with value1. you may add as many-Doptions as you require. π§-D symbol=valueβ define symbol as a CONSTANT, with value value. you may add as many-Doptions as you require. literally stack 'em.
πΈ COMMANDS πΈ
\ sβ the remainder of the line s is discarded. used for comment. it's giving "not me writing notes in the margins".( s)β discard comment s that is delimited by a right parenthesis. a blank after the leading parenthesis is required. don't forget the space, bestie.char cβ replaces character c as with its ASCII value.[char] cβ replaces character c as with its ASCII value.include sβ the contents of file s, delimited by whitespace, are inserted at this position.[needs s]β the contents of file s, delimited by a right bracket, are inserted at this position.:macro sβ create a macro with the name s, delimited by a semi-colon. when s is encountered it is replaced by the contents of the macro. a macro may contain any sequence of valid 4tH words, including conditional and loop statements, but no macros or include files. so no nesting, okay? πscrap: sβ delete a macro with the name s. after that, s will not be expanded anymore and name s can be used to define a new macro. note that the macro space allocated by s is not freed. it's giving "she's gone but her ghost is still here".let sβ expand FORTRAN formula s.[single]β set FORTRAN formula translation to single word precision.[double]β set FORTRAN formula translation to double word precision.[float]β set FORTRAN formula translation to floating point.[binary]β sets radix to binary. 01100110 01110101 01101110 π[octal]β sets radix to octal.[decimal]β sets radix to decimal. the normie choice.[hex]β sets radix to hexadecimal. edgy.
π MACROS π
@n@β parses the next string and puts it in register n. lowkey stash it.#n#β prints the contents of register n.>n>β pushes the contents of register n on the string stack.<n<β pops the "top of string stack" and puts it in register n.$n$β parses the next string, using the delimiter following it, and puts it in register n. fancy.$#$β parses the next string, using the delimiter following it, and pushes it on the string stack.>#>β parses the next string and pushes it on the string stack.<#<β discards the "top of string stack". aka '@drop'. bye bestie.|#|β prints the "top of string stack" without white space._#_β prints the "top of string stack" with white space. give her some room.>>>β pushes the string following it on the string stack.@depthβ pushes the number of elements contained in the string stack on the string stack.@crβ prints a line delimiter. new line who dis.@ifβ if the numerical value of the "top of string stack" is zero, the rest of the macro definition is skipped. conditional queen.@dupβ duplicates the "top of string stack". she's seeing double.@nipβ discards the "second of string stack".@addβ adds the numerical value of the "top of string stack" and the numerical value of the "second of string stack".@mulβ multiplies the numerical value of the "top of string stack" and the numerical value of the "second of string stack".@divrmβ divides the numerical value of the "second of string stack" by the numerical value of the "top of string stack" and leaves the quotient and remainder. math slay.@overβ duplicates the "second of string stack".@elseβ if the numerical value of the "top of string stack" is non-zero, the rest of the macro definition is skipped. aka '@ifnot'.@existβ pops the "top of string stack". if this represents a valid macro name, a TRUE value is pushed onto the string stack.@minusβ negates the "top of string stack".@evalβ pops the "top of string stack". if the "top of the string stack" contains the name of a macro, it will be executed. if it doesn't, it is printed. she's either a doer or a talker.@cellβ pops the "top of string stack". if it contains a numerical value, a TRUE value is pushed onto the string stack.@signβ pops the "top of string stack". if it's numerical value is negative, "-1" is pushed onto the string stack. if it is zero, "0" is pushed onto the string stack, otherwise "1". giving main character energy.@matchβ pops the "top of string stack" and "second of string stack". if both strings are equal, "0" is pushed on the string stack. if "second of string stack" is smaller than "top of string stack", a negative value is pushed on the string stack, otherwise a positive value.@untilβ pops the "top of string stack" and "second of string stack". if both strings are equal, the rest of the macro definition is skipped.@whileβ pops the "top of string stack" and "second of string stack". if the strings differ, the rest of the macro definition is skipped. loop her until she matches. π₯
π FILES π
*.4thβ text files containing 4tH source (script)*.4ppβ text files containing 4tH preprocessor source (script)*.scrβ block files containing 4tH source (script)*.hxβ Hcode eXecutables (bytecode)*.cβ C source files
π ENVIRONMENT VARIABLES π
DIR4THβ if non-null the full pathname (including the trailing slash) for the 4tH root directory. used only by the compiler. she needs her root, okay? π«Ά
π EXAMPLES π
to compile a 4tH program and save the object code:
pp4th -cso object.hx source.4th
to compile a 4tH program and execute it:
pp4th -x source.4th
to decompile a 4tH program with symbols:
pp4th -dn source.4th
to convert a 4tH program to C source:
pp4th -cgo source.c source.4th
π§ AUTHORS π§
PP4tH was written by Hans Bezemer <the.beez.speaks@gmail.com>. we stan.
β SEE ALSO β
and that's the tea, bestie! this manual page was brought to you by Hans Bezemer, version 3.64.1, dated 3.64.1 (yes same number, iconic). catch you on the flip side! π«Άπβ¨
π¦ where this page comes from
- nixpkgs unstable: 4th 3.64.2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms