@fareldev-hub/flang
v1.2.0
Published
Bahasa pemrograman flang yang berbase Python
Readme
FLang
FLang is a simple interpreted programming language with the .flg file
extension. Its interpreter is written in Python and distributed through npm
so it can be run from the terminal.
The npm package also includes a VS Code extension that provides syntax
highlighting, editor configuration, and a custom icon for .flg files.
Features
- Variables with
varand reassignment. - Strings and numbers.
- The
+,-,==,>, and<operators. ifandelseconditionals.whileloops.- Functions with parameters.
- Built-in
printandinputfunctions. - Single-line comments with
//. - Syntax highlighting and
.flgicons for VS Code, VS Code Insiders, and VSCodium.
Installation
Prerequisites
- Node.js 16 or later.
- Python 3.
- VS Code, VS Code Insiders, or VSCodium (optional, for syntax highlighting and file icons).
Install FLang globally:
npm install -g @fareldev-hub/flangDuring installation, FLang automatically checks for Python 3 and pip. When both are available, it runs:
python3 -m pip install larkOn Windows, FLang also tries the Python Launcher (py -3).
If Python is not installed, download it from:
https://www.python.org/downloads/
If Python is installed but pip is unavailable, follow the official pip installation guide:
https://pip.pypa.io/en/stable/installation/
After installing Python or pip, run the npm installation again:
npm install -g @fareldev-hub/flangThe npm installation also tries to install the bundled FLang extension into
any VS Code-compatible editor available in PATH. If no compatible editor is
found, the interpreter is still installed and npm does not fail.
To skip automatic VS Code extension installation:
FLANG_SKIP_VSCODE_INSTALL=1 npm install -g @fareldev-hub/flangIf the extension was not installed automatically, install it manually:
code --install-extension "$(npm root -g)/@fareldev-hub/flang/vscode-extension"Once the extension is active, .flg files are recognized as FLang files,
receive syntax highlighting, and use the FLang file icon.
Quick start
Create a file named hello.flg:
var name = "Andi"
print "Hello " + name
var age = 20
if age > 18 {
print "Adult"
} else {
print "Underage"
}
func greet(person) {
print "Welcome, " + person
}
greet(name)
var i = 0
while i < 3 {
print i
i = i + 1
}Run it with either command:
flang hello.flgor:
flang run hello.flgOutput:
Hello Andi
Adult
Welcome, Andi
0
1
2Show the version
flang -vor:
flang --versionThe displayed version is read directly from the npm package's package.json.
Show FLang information
Running flang without a file displays the language name, version, creator,
an description, and usage examples:
flangSyntax reference
Variables
Use var when declaring a new variable. Reassignment does not require var.
var name = "Budi"
var age = 18
age = 19Strings and numbers
Strings use double quotation marks. The current implementation supports integer numbers.
var message = "Hello"
var count = 10
print message
print countprint accepts one or more comma-separated expressions.
print "Hello world"
print "Name:", name, "Age:", ageThe + operator can concatenate strings with other values.
print "Count: " + 10Operators
| Operator | Purpose | Example |
| --- | --- | --- |
| + | Add or concatenate values | a + b |
| - | Subtract numbers | a - b |
| == | Compare equality | a == b |
| > | Check whether a value is greater | a > b |
| < | Check whether a value is smaller | a < b |
If and else
Code blocks are written between { and }.
if age == 18 {
print "Exactly 18"
} else {
print "Not 18"
}While
var i = 0
while i < 5 {
print i
i = i + 1
}Functions
Define functions with func. The current version does not support return.
func greet(name) {
print "Hello " + name
}
greet("Budi")Functions can have multiple parameters:
func show(name, age) {
print name, age
}
show("Budi", 20)Input
Use input to read text from the terminal.
var name = input("What is your name? ")
print "Hello " + nameComments
Single-line comments start with //.
// This is a comment
var value = 10 // A comment after codeRunning from source
If you do not want to install the npm package globally:
python3 -m pip install lark
node bin/flang.js hello.flgVS Code extension
The extension is located in the vscode-extension directory. It provides:
- The
flanglanguage definition for.flgfiles. - Syntax highlighting for keywords, functions, numbers, strings, operators, and comments.
- A custom
.flgfile icon. - Automatic closing for
{},(), and quotation marks.
Install the extension from source:
code --install-extension ./vscode-extensionCurrent limitations
- Functions do not support
returnyet. else ifis not supported yet.- The
*,/, and%operators are not supported yet. - Error messages do not always include line numbers.
- The currently available built-ins are
inputandprint.
License
FLang is released under the MIT License. See LICENSE for the full license text.
