Skip to content

Commit

Permalink
Fixed many errors that occured while having a function within a funct…
Browse files Browse the repository at this point in the history
…ion, fixed some errors that were in conditional statements and loops
  • Loading branch information
Jamlie committed Oct 9, 2023
1 parent ba6d284 commit 157d336
Show file tree
Hide file tree
Showing 12 changed files with 803 additions and 407 deletions.
Binary file modified bin/jamlang.exe
Binary file not shown.
62 changes: 55 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package main

import (
"fmt"
"os"
"flag"
"strings"
"bufio"
"io/ioutil"
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"

"os"
"strings"

"github.com/Jamlee977/CustomLanguage/parser"
"github.com/Jamlee977/CustomLanguage/runtimelang"
)
Expand Down Expand Up @@ -111,6 +111,30 @@ func main() {
}
defer file.Close()

_, err = io.Copy(file, resp.Body)
if err != nil {
fmt.Println(err)
os.Exit(0)
}
} else if args[0] == "random" {
resp, err := http.Get("https://raw.githubusercontent.com/Jamlee977/CustomLanguage/main/std/random.jam")
if err != nil {
fmt.Println(err)
os.Exit(0)
}
defer resp.Body.Close()

if _, err := os.Stat("std"); os.IsNotExist(err) {
os.Mkdir("std", 0755)
}

file, err := os.Create("std/" + args[0] + ".jam")
if err != nil {
fmt.Println(err)
os.Exit(0)
}
defer file.Close()

_, err = io.Copy(file, resp.Body)
if err != nil {
fmt.Println(err)
Expand All @@ -121,7 +145,7 @@ func main() {
os.Exit(0)
}
} else {
option := args[0]
option := args[0]
if option == "run" {
if len(args) < 2 {
fmt.Println("No file specified")
Expand Down Expand Up @@ -187,6 +211,30 @@ func main() {
}
defer file.Close()

_, err = io.Copy(file, resp.Body)
if err != nil {
fmt.Println(err)
os.Exit(0)
}
} else if args[1] == "random" {
resp, err := http.Get("https://raw.githubusercontent.com/Jamlee977/CustomLanguage/main/std/random.jam")
if err != nil {
fmt.Println(err)
os.Exit(0)
}
defer resp.Body.Close()

if _, err := os.Stat("std"); os.IsNotExist(err) {
os.Mkdir("std", 0755)
}

file, err := os.Create("std/random.jam")
if err != nil {
fmt.Println(err)
os.Exit(0)
}
defer file.Close()

_, err = io.Copy(file, resp.Body)
if err != nil {
fmt.Println(err)
Expand Down
7 changes: 5 additions & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,11 @@ func (p *Parser) parseFunctionDeclaration() ast.Statement {

p.expect(tokentype.LSquirly, "Error: Expected '{' after function declaration")

p.isFunction = true
defer func() { p.isFunction = false }()
if !p.isFunction {
p.isFunction = true
defer func() { p.isFunction = false }()
}

body := []ast.Statement{}
for p.at().Type != tokentype.EndOfFile && p.at().Type != tokentype.RSquirly {
body = append(body, p.parseStatement())
Expand Down
Loading

0 comments on commit 157d336

Please sign in to comment.