
No License
Go
2019年09月02日
package main
import (
"fmt"
"strings"
"os"
)
func main() {
args := os.Args
vt := var_type()
vtype := strings.Split(vt, ",")
support_vtype := []string{"int", "char", "double"}
if len(args) == 2 {
filename := args[1]
file, err := os.Open(filename)
if err != nil{
fmt.Printf("No Such file : %s", filename)
os.Exit(0)
}
nfilename,ext := get_ext_filename(filename)
if ext != "sl"{
fmt.Println(filename, "is not SasaLan File")
os.Exit(0)
}
buf := make([]byte, 1024)
var add_code string
for {
n,err := file.Read(buf)
if n == 0{
break
}
if err != nil{
fmt.Println("Read Error")
break
}
code := string(buf[:n])
add_code += code
}
nl_split := strings.Split(add_code, "\n")
size := len(nl_split)
var var_string string
var var_type_s string
in_if, in_func := "0", "0"
var func_code string
var main_code string
main_code += "#include <stdio.h>\nint main(void){\n"
for i := 0;i < size;i++{
code := nl_split[i]
space_split := strings.Split(code, " ")
if code == ""{
continue
}
if string(code[0]) == "#" {
var comment_value string
for i := 0;i < len(code);i++ {
if i == 0{
continue
} else {
comment_value += string(code[i])
}
}
add_code := "/*" + comment_value + "*/\n"
main_code += add_code
} else if len(space_split) >= 2 {
if space_split[0] == "if" {
var judge_formula string
for i,value := range space_split {
if i == 0 {
continue
} else if i == 1 {
judge_formula += value
} else {
judge_formula += " " + value
}
}
add_code := if_code(judge_formula)
in_if += ",1"
main_code += add_code
}
} else if code == "e" {
if_sp, func_sp := strings.Split(in_if, ","), strings.Split(in_func, ",")
lengh1, lengh2 := len(if_sp) - 1, len(func_sp) - 1
ires, fres := if_sp[lengh1], func_sp[lengh2]
if ires == "1" {
main_code += "}\n"
} else if fres == "1" {
func_code += "}"
}
}
if space_split[0] == "pr" {
var pr_value string
for i := 1;i < len(code);i++{
if i == 0 || i == 1 || i == 2{
continue
} else {
pr_value += string(code[i])
}
}
add_code := pr_code(pr_value, strings.Split(var_string, ","), strings.Split(var_type_s, ","))
main_code += add_code
}
var_split1 := strings.Split(code, string(vtype[0]))
var_split2 := strings.Split(code, string(vt[1]))
var_split3 := strings.Split(code, "f:")
if var_split1[0] == "" {
var_name_value := var_split1[1]
line_split1 := strings.Split(var_name_value, "=")
var_name,var_value := line_split1[0], line_split1[1]
lengh1, lengh2 := len(strings.Split(var_name, " ")), len(strings.Split(var_value, " "))
var vname string
var vvalue string
if lengh1 == 2 && lengh2 == 2{
var_name, var_value := strings.Split(var_name, " ")[0], strings.Split(var_value, " ")[1]
vname += var_name
vvalue += var_value
}
var_type := support_vtype[0]
add_code := var_code(var_type, vname, vvalue)
if len(var_string) == 0{
var_string += vname
} else {
var_string += "," + vname
}
if len(var_type_s) == 0{
var_type_s += var_type
} else {
var_type_s += "," + var_type
}
main_code += add_code
} else if var_split2[0] == "s" {
var_name_value := var_split2[1]
line_split1 := strings.Split(var_name_value, "=")
var_name,var_value := line_split1[0], line_split1[1]
lengh1, lengh2 := len(strings.Split(var_name, " ")), len(strings.Split(var_value, " "))
var vname string
var vvalue string
if lengh1 >= 2 && lengh2 >= 2 {
var_name := strings.Split(var_name, " ")[0]
var_value_sp := strings.Split(var_value, " ")
var res string
for i := 0;i < len(var_value_sp);i++ {
if i == 0{
continue
} else if i == 1{
res += var_value_sp[i]
} else {
res += " " + var_value_sp[i]
}
}
vvalue += res
vname += var_name
} else {
vname += var_name
vvalue += var_value
}
var_type := support_vtype[1]
add_code := var_code(var_type, vname, vvalue)
if len(var_string) == 0{
var_string += vname
} else {
var_string += "," + vname
}
if len(var_type_s) == 0{
var_type_s += var_type
} else {
var_type_s += "," + var_type
}
main_code += add_code
} else if var_split3[0] == ""{ //float && コード変換
var_name_value := var_split3[1]
line_split1 := strings.Split(var_name_value, "=")
var_name, var_value := line_split1[0], line_split1[1]
lengh1, lengh2 := len(strings.Split(var_name, " ")), len(strings.Split(var_value, " "))
var vname string
var vvalue string
if lengh1 >= 2 && lengh2 >= 2 {
var_name := strings.Split(var_name, " ")[0]
var_value_sp := strings.Split(var_value, " ")
var res string
for i,value := range var_value_sp {
if i == 0 {
continue
} else if i == 1 {
res += value
} else {
res += " " + value
}
}
vname += var_name
vvalue += res
} else {
vname += var_name
vvalue += var_value
}
var_type := support_vtype[2]
add_code := var_code(var_type, vname, vvalue)
if len(var_string) == 0{
var_string += vname
} else {
var_string += "," + vname
}
if len(var_type_s) == 0{
var_type_s += var_type
} else {
var_type_s += "," + var_type
}
main_code += add_code
}
}
if string(main_code[len(main_code) - 1]) !="}" {
main_code += "}"
}
cfilename := nfilename + ".c"
nfile,err := os.Create(cfilename)
if err != nil{
fmt.Println("Write Error")
os.Exit(0)
}
nfile.Write(([]byte)(main_code))
fmt.Printf("Output C File : %s\n", cfilename)
} else {
fmt.Println("sasalan [filename]")
os.Exit(0)
}
}
func get_ext_filename(filename string) (string, string) {
split_arr := strings.Split(filename, ".")
max_lengh := len(split_arr) - 1
ext := split_arr[max_lengh]
return split_arr[0],ext
}
func var_type() string {
filename := "doc/var_type"
var code string
file,err := os.Open(filename)
if err != nil{
fmt.Println("Error")
}
buf := make([]byte, 1024)
for {
n,err := file.Read(buf)
if n == 0 {
break
}
if err != nil{
fmt.Println("Read Error")
}
ncode := string(buf[:n])
code += ncode
}
tl := strings.Split(code, "\n")[0]
return tl
}
func var_code(var_type string, var_name string, var_value string) string {
var res string
if var_type == "int" {
code := fmt.Sprintf("int %s = %s;\n", var_name, var_value)
res += code
} else if var_type == "char"{
code := fmt.Sprintf("char %s[] = %s;\n", var_name, var_value)
res += code
} else if var_type == "double" {
code := fmt.Sprintf("float %s = %sf;\n", var_name, var_value)
res += code
}
return res
}
func pr_code(put_string string, var_array []string, var_type_array []string) string {
var judge1 rune = '"'
var res string
pr_split1 := strings.Split(put_string, string(judge1))
join_split1 := strings.Split(put_string, ",")
if len(pr_split1) == 3 {
res += fmt.Sprintf("printf(%s);\n", put_string)
return res
}
if len(join_split1) >= 2 {
base := "printf(" + string(judge1)
var after_str string
judge2 := "0"
for _,v := range join_split1 {
fmt.Println(v)
if string(v[0]) == string(judge1) {
judge2 += ",0"
if len(after_str) == 0 {
after_str += v
} else {
after_str += "," + v
}
base += "%s"
continue
} else if string(v[len(v) - 1]) == string(judge1) {
judge2 += ",1"
if len(after_str) == 0 {
after_str += v
} else {
after_str += "," + v
}
} else if strings.Split(judge2, ",")[len(strings.Split(judge2, ",")) - 1] == "1" {
if len(after_str) == 0 {
after_str += v
} else {
after_str += "," + v
}
} else {
if len(after_str) == 0 {
after_str += v
} else {
after_str += "," + v
}
var vtype string
var res2 string
for i := 0;i < len(var_array);i++ {
if var_array[i] == v {
res2 += "comp"
vtype += var_type_array[i]
break
} else {
res2 += "not"
}
}
if res2 == "not" {
fmt.Printf("There is not variable %s", v)
os.Exit(0)
}
if vtype == "int" {
base += "%d"
} else if vtype == "char" {
base += "%s"
} else if vtype == "double" {
base += "%f"
}
continue
}
}
base += string(judge1) + ", " + after_str + ");\n"
return base
}
var res2 string
var vtype string
for i := 0;i < len(var_array);i++ {
if var_array[i] == put_string{
res2 += "comp"
vtype += var_type_array[i]
break
} else {
res2 += "not"
}
}
if res2 == "not" {
fmt.Printf("There is not variable %s", put_string)
os.Exit(0)
}
if vtype == "int" {
code := "printf(" + string(judge1) + "%d" + string(judge1) + ", " + put_string + ");\n"
res += code
} else if vtype == "char" {
code := "printf(" + string(judge1) + "%s" + string(judge1) + ", " + put_string + ");\n"
res += code
} else if vtype == "double" {
code := "printf(" + string(judge1) + "%f" + string(judge1) + ", " + put_string + ");\n"
res += code
}
return res
}
func if_code(judge_formula string) string {
return fmt.Sprintf("if (%s) {\n", judge_formula)
}

Anonymous
2021年04月27日
Medication information sheet. Effects of Drug Abuse.
<a href="https://toplyrica.top">order lyrica without rx</a> in the USA
Everything about medicines. Get here.

Anonymous
2021年04月29日
Medication information sheet. Long-Term Effects.
<a href="https://lyrica24x7.top">order lyrica without insurance</a> in the USA
Actual news about medicines. Get information now.

Anonymous
2021年04月30日
cialis dosages <a href="https://mycialistabs.com/">canadian pharmacy cialis</a> canadian pharmacy online cialis

Anonymous
2021年04月30日
cialis goodrx <a href="https://mycialistabs.com/">cheap cialis online</a> what's the difference between viagra and cialis

Anonymous
2021年05月02日
cialis canada <a href="https://toptadalafiltabs.com/">tadalafil walmart</a> cialis recommended dosage

Anonymous
2021年05月03日
how much does cialis cost <a href="https://toptadalafiltabs.com/">over the counter cialis</a> cialis recommended dosage

Anonymous
2021年05月04日
how to write a research essay <a href="https://topessaywriterfas.com/">https://www.topessaywriterfas.com/</a> how to write a good dbq essay

Anonymous
2021年05月05日
how does the strategy of using focus points help you write a problem-and-solution essay? <a href="https://topessaywriterfas.com/">college reflection essay</a> write an essay on responsibilities of a good citizen

Anonymous
2021年05月06日
malayalam essay on students and social service <a href="http://writemyessayslfd.com/">essay on writing</a> words to use when writing an essay

Anonymous
2021年05月06日
cusyom essay writing service <a href="http://writemyessayslfd.com/">write a reflection essay</a> essay service in united states

Anonymous
2021年05月07日
sildenafil cost <a href="https://mrviagrashop.com">generic viagra walmart</a> alternative to viagra

Anonymous
2021年05月07日
viagra falls <a href="https://mrviagrashop.com">viagra without prescription</a> canada viagra

Anonymous
2021年05月07日
womens viagra <a href="https://mysildenafilkr.com/">generic viagra usa</a> viagra online

Anonymous
2021年05月07日
sildenafil online <a href="https://mysildenafilkr.com/">generic viagra walmart</a> best place to buy viagra online

Anonymous
2021年05月11日
cialis patent expiration 2016 <a href="http://tadalafilled.com/">cialis coupons</a> cialis drug class

Anonymous
2021年05月11日
core competencies resume <a href="http://coverletterforresumetop.com/">writing a nursing resume</a> resume writers near me

Anonymous
2021年05月12日
resume critique <a href="http://coverletterforresumetop.com/">online resume website</a> tech resume

Anonymous
2021年05月12日
cialis side effects with alcohol <a href="http://tadalafilled.com/">generic cialis canada</a> when should i take cialis

Anonymous
2021年05月12日
retail manager resume <a href="https://writingacoverletteronline.com/">pay for resume</a> who do i address a cover letter to

Anonymous
2021年05月13日
objective in a resume <a href="https://writingacoverletteronline.com/">best rated resume writing services</a> cover letter now

Anonymous
2021年05月13日
natural viagra for men <a href="https://edviagramaster.net/">viagra for women</a> best over the counter viagra

Anonymous
2021年05月14日
women viagra <a href="https://edviagramaster.net/">pills like viagra</a> buy viagra online

Anonymous
2021年05月15日
women viagra <a href="https://sildenafilviagratop.com">viagra connect</a> viagra walgreens

Anonymous
2021年05月15日
best over the counter viagra <a href="https://sildenafilviagratop.com">natural viagra for men</a> female viagra walmart

Anonymous
2021年05月15日
cost of cialis without insurance <a href="https://cialisortadalafil.com/">how to get cialis</a> cialis daily dose

Anonymous
2021年05月15日
cost of cialis at walmart <a href="https://cialisortadalafil.com/">tadalafil cost</a> cialis com coupons

Anonymous
2021年05月16日
coupon for cialis <a href="https://topcialistabs.com/">cialis manufacturer coupon lilly</a> cialis free trial phone number

Anonymous
2022年03月27日
nursing essay importance of community service <a href="https://englishessayblog.com/">essay writer cheap</a> responsible alcohol beverage service essay

Anonymous
2021年05月17日
is there a generic cialis <a href="https://topcialistabs.com/">levitra vs cialis</a> us pharmacy prices for cialis

Anonymous
2022年03月28日
essay writing service threat <a href="https://englishessayblog.com/">professional college essay writers</a> best paper essay service

Anonymous
2021年05月18日
Drug information sheet. Drug Class.
<a href="https://smotrite-online-films.ru">where to buy valtrex online</a> in USA
Some news about drugs. Read information here.

Anonymous
2021年05月21日
<a href="https://5bz.ru/">предприятия россии база данных</a>

Anonymous
2021年06月01日
Drugs information. Long-Term Effects.
<a href="https://topregabalin.top">where can i buy pregabalin</a> in US
Best what you want to know about medication. Read now.

Anonymous
2022年05月02日
buy real viagra online <a href="https://viagrahom.com/">sildenafil citrate for sale</a> over the counter viagra substitute walgreens
Output