“AWIT” which stands for, “Algorithm written in Tagalog”, complete with its own syntaxes, and built-in virtual machine whose main purpose is the accurate and precise analysis of algorithms that exist. However, it will not be strictly in Tagalog but in the Filipino language and the reason for the naming is to preserve the Filipino word, “AWIT” instead of “AWIF”. This will be a great educational programming language for Filipino freelancers, students or professional developers who have interest in both algorithms and programming languages.
The language implementation was based on LOX's clox implementation. From the scanner to the compiler to the VM heck even the Garbage Collector. Although there are a lot of significant differences, the implementations were highly inspired by Nystrom's Crafting Interpreters. Again, thank you!
- Scripting language
- High-level language (follows C-style programming)
- Dynamically typed
- Stack-based
- Interpreted (it's actually a hybrid interpreter since the implementation first compiles to bytecode then be interpreted by the Virtual Machine)
- Managed language (AWIT has its own Garbage Collector)
- Finally, it is Turing-complete
Kamusta, Daigdig!:
ipakita "Kamusta, Daigdig!";
Recursive program to print the 69th number in fibonacci sequence:
gawain fibonacci(n) {
kung (n < 2) ibalik n;
ibalik fibonacci(n - 2) + fibonacci(n - 1);
}
ipakita fib(35); // This will take a couple of seconds.
- Git
- Make and C compiler llvm-mingw-20211002-msvcrt-i686.zip
We recommend llvm-mingw for the make and C compiler but you are free to choose your preffered make and C compiler.
- for WINDOWS-based systems AWIT v0.9.8
- for LINUX-based systems AWIT v0.9.8
$ git clone https://github.com/Philiks/AWIT.git
$ cd AWIT
$ make
or
$ git clone https://github.com/Philiks/AWIT.git
$ cd AWIT/src
$ make
you can run make
either in AWIT or in AWIT/src
Note: The
awit
orawit.exe
is located at the AWIT/src after compilation.
./awit [*.awit file]
(in LINUX-based systems)awit.exe [*.awit file]
(for Windows system)
$ src/./awit mga\ halimbawa/kamustaMundo.awit
Kamusta, Mundo!
or use our REPL
$ src/./awit
> ipakita "Kamusta, Mundo!";
Kamusta, Mundo!
>
Note: Running without the file as argument will fire up the REPL.
tama
o mali
kilalanin singleKaBa = tama;
6.9
420
kilalanin decimal = 6.9;
kilalanin integer = 420;
"Isa akong lupon ng mga salita."
""
kilalanin pangalan = "Felix Raffy Mark";
null
(almost used wala
but null
prevails)
// unnecessary ' = null' since uninitialized
// variables are assigned with null.
kilalanin wala = null;
Token | Name |
---|---|
+ |
addition |
- |
subtraction |
* |
multiplication |
/ |
division |
% |
modulo division (remainder) |
1 + 2 - 3 * 4 / 5 % 6; // This results to 1 btw.
-
negation
-10;
-(10 - 11); // 1
Token | Name |
---|---|
< |
less than |
<= |
less than or equal |
> |
greater than |
>= |
greater than or equal |
kung (10 < 20) {
ipakita 30;
}
==
equal to!=
not equal to
"tayo" != "bagay";
Token | Name |
---|---|
! |
not |
at |
and |
o |
or |
tama o mali; // tama, 'o' at 'at' are short-circuit operators
For more reading about short-circuit evaluation
Operator Precedence
Token | Name |
---|---|
. () |
call |
++ -- |
post-increment |
! - ++ -- |
pre-increment |
* / % |
factor |
+ - |
term |
< > <= >= |
comparison |
== != |
equality |
at |
and |
o |
or |
= |
assignment |
Note: You can always override precedence by using groupin
()
.
Syntax ipakita <ekspresyon> ;
ipakita "Kamusta ka naman?";
declaration
Syntax kilalanin <identifier> ;
kilalanin walangHalaga;
ipakita walangHalaga; // null
definition
Syntax [kilalanin] <identifier> = <ekspresyon> ;
kilalanin mayHalaga = tama;
ipakita mayHalaga; // tama
mayHalaga = 12;
ipakita mayHalaga; // 12
Syntax kung ( <ekspresyon> ) <pahayag> [kundiman <pahayag]
kilalanin edad = 16;
kung (edad < 18)
ipakita "Ikaw ay menor de edad.";
kundiman
ipakita "Isa ka ng matandang nilalang.";
Syntax suriin ( <ekspresyon> ) { [kapag <ekspresyon> : <pahayag>]+ [palya : <pahayag>] }
kilalanin numero = 2;
suriin (numero) {
kapag 1:
ipakita "Isa";
kapag 2:
ipakita "Dalawa";
palya:
ipakita "Di makita ang numero.";
}
Syntax habang ( <ekspresyon> ) <pahayag>
// Prints 0 - 9
kilalanin n = 0;
habang (n < 10)
ipakita n;
Syntax gawin <pahayag> habang ( <ekspresyon> ) ;
// Prints 0 - 10
kilalanin n = 0;
gawin
ipakita n;
habang (n < 10);
Syntax kada ( <ekspresyon> ; <ekspresyon> ; <ekspresyon> ) <pahayag>
// Prints 0 - 9;
kada (kilalanin n = 0; n < 10; n++) {
ipakita n;
}
Syntax itigil ;
kilalanin ctr = 0;
habang (tama) {
kung (ctr == 1)
itigil;
ipakita ctr;
ctr++;
}
Note: Can only be used inside looping statements
habang
gawin-habang
kada
.
Syntax ituloy ;
// DANGER!!! This will cause an infinite loop DO NOT TRY.
// Pero ikaw bahala ;)
kilalanin ctr = 0;
habang (tama) {
kung (ctr == 1)
ituloy;
ipakita ctr;
ctr++;
}
Note: Can only be used inside looping statements
habang
gawin-habang
kada
.
Syntax ibalik [<ekspresyon>] ;
gawain pagsamahin(a, b) {
ibalik a;
}
ipakita pagsamahin(34, 35); // 69
Note: Can only be used inside functions
gawain
.
Syntax { [<pahayag>]* }
kilalanin a = "labas";
{
ipakita a; // labas
kilalanin a = "loob";
ipakita a; // loob
}
Syntax <ekspresyon> ;
kilalanin ctr = 0;
ctr++; // Useful
12; // Useless
Syntax gawain <identifier> ( [<identifier> ,]* ) { <pahayag> }
gawain kamusta() {
ipakita "Kamusta!";
}
kamusta();
Syntax gawain <identifier> ( [<identifier> ,]* ) { <gawain> }
kilalanin tagapalit;
kilalanin tagatingin;
gawain numero() {
kilalanin numero = 69;
gawain palitan() {
numero = 420;
}
gawain patingin() {
ipakita numero;
}
tagapalit = palitan;
tagatingin = patingin;
}
tagatingin(); // 69
tagapalit();
tagatingin(); // 420
Syntax uri <identifier> { <pahayag>* }
uri Tao {
kain() {
ipakita "Kumakain wag guluhin.";
}
tulog() {
ipakita "Tulog wag magdabog.";
}
laro() {
ipakita "Laro bago palo.";
}
}
AWIT is dynamically-typed language therefore you cant define a field after instantiation.
uri Programmer {}
kilalanin programmer = Programmer();
programmer.puyat = tama;
instantiation
Syntax kilalanin <identifier> = <class-name>( [<ekspresyon> ,]* ) ;
kilalanin tao = Tao();
tao.kain();
tao.tulog();
tao.laro();
initialization
Syntax sim ( [<identifier> ,]* ) { <pahayag> }
uri Tao {
sim(pangalan, kasarian) {
ito.pangalan = pangalan;
ito.kasarian = kasarian;
}
}
Note:
sim
is short forsimula
. Note: You cannot useibalik
with a value beside it insidesim
. Note: You don't have to put the fields inside theuri
just prefix it withito.
.
Syntax uri <identifier> < <class-name> { <pahayag> }
uri Estudyante < Tao {
sim(pangkatTaon, pangalan, kasarian) {
mula.sim(pangalan, kasarian);
ito.pangkatTaon = pangkatTaon;
}
uwi() {
ipakita "Uwian na!";
}
}
kilalanin felix = Estudyante("BSCS 4A", "Felix", "Lalaki");
felix.kain();
felix.laro();
felix.uwi();
felix.tulog();
Note: You can user
mula
to access parent's fields and methods.
Returns the current time in seconds in type double
.
Reads an input from the user from the STDIN.
Returns double
if the input is a number. Otherwise it will return string
.
uri
the class instance in which the field-name will be searched.
string
the field to be searched.
Returns tama
if found. Otherwise it will return mali
.
AWIT have 22 reserved words and they are:
at
, gawain
, gawin
, habang
, ibalik
, ipakita
, itigil
, ito
,
ituloy
, kada
, kapag
, kilalanin
, kundiman
, kung
, mali
, mula
,
null
, palya
, suriin
, o
, tama
, uri
::= <keyword>
| <identifier>
| <constant>
| <string-literal>
| <punctuator>
;
::= 'at' | 'ituloy' | 'mula'
| 'gawain' | 'kada' | 'null'
| 'gawin' | 'kapag' | 'palya'
| 'habang' | 'kilalanin' | 'suriin'
| 'ibalik' | 'kundiman' | 'o'
| 'ipakita' | 'kung' | 'tama'
| 'itigil' | 'mali' | 'uri' | 'ito'
;
| <alphabet> <alpha-numeric>* ;
::= <alphabet> | <digit> ;
::= 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm'
| 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z'
| 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M'
| 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'
;
::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ;
::= <number-constant> | <boolean-constant> | 'null' ;
::= <whole-number> | <fractional-number> ;
::= 'tama' | 'mali' ;
::= `"` <character>+ `"` ;
::= <escape-sequence>
| /* Any character on the source code except double-quotation (") and backslash (\) */
;
::= '"' | '\\'
| '\a' | '\b' | '\f' | '\n' | '\e' | '\r' | '\t' | '\v'
;
::= '(' | ')' | '{' | '}' | '[' | ']' | '.'
| '++' | '--' | '+' | '-' | '!'
| '\' | '/' | '*' | '%' | '<' | '>' | '<=' | '>=' | '==' | '!='
| ',' | ';' | ':' | '='
;
This language is all thanks to these people:
Felix Janopol Jr.
Raffy Wamar
Mark Julius Mella
This project is licensed under the MIT License - see the LICENSE file for details.