|
| 1 | +# Funcy |
| 2 | +_A toy functional language written in Python._ |
| 3 | +__Copyright © 2022 Chris Roberts__ (Krobbizoid). |
| 4 | + |
| 5 | +# Contents |
| 6 | +1. [About](#about) |
| 7 | +2. [Example](#example) |
| 8 | +3. [Grammar](#grammar) |
| 9 | +4. [License](#license) |
| 10 | + |
| 11 | +# About |
| 12 | +Funcy is a toy functional language written in Python. It is developed as an |
| 13 | +exercise to test implementing functions in an interpreted language. It is _not_ |
| 14 | +suitable as a practical language, or as a guide for creating a programming |
| 15 | +language. |
| 16 | + |
| 17 | +# Example |
| 18 | +Below is a 'hello world' program written in Funcy that demonstrates the feature |
| 19 | +set for its initial implementation. The initial implementation is only useful |
| 20 | +for printing a fixed sequence of integers: |
| 21 | +``` |
| 22 | +/* |
| 23 | +* Funcy uses C-like line and block comments. Funcy source code files should be |
| 24 | +* named with the file extension '.fy'. |
| 25 | +* |
| 26 | +* /* |
| 27 | +* * Block comments may be nested inside of other block comments. |
| 28 | +* */ |
| 29 | +*/ |
| 30 | +
|
| 31 | +/* |
| 32 | +* A Funcy program contains 0 or more top-level function declarations. These |
| 33 | +* begin with the 'func' keyword and a function name, followed by a list of |
| 34 | +* parameter names in parentheses, and a function body in a compound statement. |
| 35 | +* In the initial implementation, functions are not callable and their |
| 36 | +* parameters can't be used. |
| 37 | +*/ |
| 38 | +func foo(bar, baz){} |
| 39 | +
|
| 40 | +/* |
| 41 | +* If a function named 'main' exists, it will be used as the entry point for the |
| 42 | +* program. |
| 43 | +*/ |
| 44 | +func main(){ |
| 45 | + /* |
| 46 | + * In the initial implementation, 'print' is a keyword, and not the name of |
| 47 | + * a standard function. In this example, '(123)' is actually a parenthesized |
| 48 | + * expression. The parentheses may be omitted, but they improve |
| 49 | + * compatibility with potential future versions. Only integers are available |
| 50 | + * in the initial implementation, so '123' is printed instead of a hello |
| 51 | + * world message. |
| 52 | + */ |
| 53 | + print(123); |
| 54 | + |
| 55 | + /* |
| 56 | + * Curly braces mark compound statements that contain 0 or more statements |
| 57 | + * in their own scope. |
| 58 | + */ |
| 59 | + { |
| 60 | + /* |
| 61 | + * A statement may contain a standalone expression. No operations are |
| 62 | + * available in the initial implementation. |
| 63 | + */ |
| 64 | + 456; |
| 65 | + |
| 66 | + ; // A semicolon on its own marks a no operation statement. |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +# Grammar |
| 72 | +The EBNF (Extended Backus-Naur Form) grammar for Funcy's initial implementation |
| 73 | +is as follows: |
| 74 | +```EBNF |
| 75 | +program = { func_decl }, EOF ; |
| 76 | +func_decl = "func", IDENTIFIER, "(", [ param_decls ], ")", stmt_compound ; |
| 77 | +param_decls = IDENTIFIER, { ",", IDENTIFIER } ; |
| 78 | +
|
| 79 | +stmt = stmt_compound | stmt_nop | stmt_print | stmt_expr ; |
| 80 | +stmt_compound = "{", { stmt }, "}" ; |
| 81 | +stmt_nop = ";" ; |
| 82 | +stmt_print = "print", expr, ";" ; |
| 83 | +stmt_expr = expr, ";" ; |
| 84 | +
|
| 85 | +expr = expr_primary ; |
| 86 | +expr_primary = "(", expr, ")" | LITERAL_INT ; |
| 87 | +``` |
| 88 | + |
| 89 | +# License |
| 90 | +Funcy is released under the MIT License: |
| 91 | +https://krobbi.github.io/license/2022/mit.txt |
| 92 | + |
| 93 | +See [license.txt](./license.txt) for a full copy of the license text. |
0 commit comments