Skip to content

svenpohl/frog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frog interpreter 🐸

A simplified programming language.

Frog can be used to create application extensions with no need to compile C/C++ - code. The input- and output parameters are a simple JSON-structure with the values of variables.

Frog code is interpreted by a single C++ class defined in frog.h and frog.cpp.

"Hello Frog!" simple example code:

// "Hello Frog"  - Example frog code 
// File: hello.frog

int a;
int b;  
int total;
char buffer[255];

// function SUM
SUM:
total = a + b
RETURN;

// function MAIN
MAIN:

buffer[6] = "F"
b         = 2
total     = 0

GOTO SUM

EXPORT CLEAR
EXPORT a
EXPORT b
EXPORT total
EXPORT buffer;

OUT
EXIT

Example output JSON: Variable a gets the default value 40. the string buffer is set to "Hello Xrog!" (Notice: "Xrog" is no typo)

{                                 
"a":"40",                      
"buffer" : "Hallo Xrog!"                      
} 

After running $> ./frog hello.frog the JSON output looks like:

Example input JSON:

{ 
"a":"40",
"b":"2",
"total":"42",
"buffer":"Hallo Frog!"
}

Frog Commands Command or Expression Description

  • MAIN: | The initial entrypoint of the program
  • [Variables] | Integer (int), float, char and arrays of it
  • GOTO SUM | Jump to the label "SUM:". GOTO safes the current code position (for RETURN)
  • SUM: | Defines a label "SUM:".
  • RETURN | Jumps back to the last safed (GOTO) program position
  • IF | IF-condition/compare of two parameters
  • WHILE | Loops the following statement if condition is true.
  • EXPORT i | Marks variable i for being included in the output JSON structure. At first reset the output with EXPORT CLEAR, then add with EXPORT all variables to export. The order of your EXPORT commands will have the same order in the JSON output.
  • OUT | OUT will finalize the construction of the JSON output buffer for the caller (f.e. main.cpp).
  • PRECOMPILED dump buffer | This command will call the precompiled() function in the frog-class. Per default there are the functions dump and echo. You may add here all precompiled additional functions you will need (f.e. SHA256, network-functions, complex calculations and other libraries.).

Limitations

  • No recursion stack
  • Codebuffer size is defined by the caller of the class (f.e. main.cpp)
  • Key-Expressions like IF must be uppercase
  • Only one operator in a assignment supported, f.e. i = i2 + 3

Hints and tipps Start playing with

$ ./frog hello.frog
then
$ ./frog sort.frog

Special Syntax

char buffer[10]
buffer = "Hello quack!" // direct assignment of a string buffer

About

A simplified programming language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published