Golang : Experimental Jawi programming language
Alright, today is Sunday and I got some free time to spare. So, I used my free time to build this simple project of using Jawi as programming language. This project is inspired by the 文言 wenyan-lang(a programming language using ancient Chinese a.k.a Hokkien).
https://github.com/wenyan-lang/wenyan
Since building the lexer, parser, AST, compiler and code generator will take a very long time for me, therefore I cheat a little bit. The Jawi codes will be translated into Golang equivalent codes to be compiled by Golang compiler.
NOTES : This example below will generate enough Golang codes to produce a simple Hello World example. There are more works to be done if I need to cover all the reserved words of Golang and that will need another free Sunday for me....
Here you go!
package main
import (
"fmt"
"strings"
"text/scanner"
)
func main() {
jawiGolang := map[string]string{}
dictionary := `var,ڤايمباولايهوباه
Println,چايتاقڬاراس
const,مالر
package,ڤاکيج
import,امڤاوت
main,اوتام
func,فوڠسي`
lines := strings.Split(dictionary, "\n")
// build the dictionary
for _, line := range lines {
if len(line) > 0 {
split := strings.Split(line, ",")
golang := split[0]
jawi := split[1]
jawiGolang[jawi] = golang
}
}
//test
jawiCode := `ڤاکيج اوتام
امڤاوت (
"fmt"
)
ڤايمباولايهوباه txt = "世界汝好 ! Hello World !"
مالر jawitxt = "هاي دنيا !"
فوڠسي اوتام() {
fmt.چايتاقڬاراس (txt)
fmt.چايتاقڬاراس (jawitxt)
}`
codeReader := strings.NewReader(jawiCode)
var scn scanner.Scanner
scn.Init(codeReader)
scn.Whitespace ^= 1<<'\t' | 1<<'\n' | 1<<'\r' | 1<<' ' // don't skip tabs and new lines
for tok := scn.Scan(); tok != scanner.EOF; tok = scn.Scan() {
switch tok {
case '\n':
fmt.Println()
case '\t':
fmt.Print(" ")
default:
if jawiGolang[scn.TokenText()] != "" {
fmt.Print(jawiGolang[scn.TokenText()])
} else {
fmt.Print(scn.TokenText())
}
}
}
fmt.Println()
}
A friend suggested that I complete the entire project with LLVM. I will try to explore LLVM further and see how it goes. Trouble with Jawi is that it is right to left oriented writing system, maybe just a small problem to overcome. Will see how it goes.
References:
See also : Golang : Experimenting with the Rejang script
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+23.5k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+12.6k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+19.1k Mac OSX : Homebrew and Golang
+14.3k Golang : How to pass map to html template and access the map's elements
+7.8k Javascript : How to check a browser's Do Not Track status?
+52.4k Golang : How to get struct field and value by name
+4.6k Adding Skype actions such as call and chat into web page examples
+5.4k Golang : Stop goroutine without channel
+8k Golang : Append and add item in slice
+5.9k Linux/MacOSX : Search for files by filename and extension with find command
+26.6k Golang : How to check if a connection to database is still alive ?
+14.5k Golang : How to check if your program is running in a terminal