@@ -6,7 +6,7 @@ import (
"reflect"
"strings"

"github.com/scottshotgg/ExpressRedo/token"
"github.com/scottshotgg/express-rearch/token"
)

// ParseString parses a string literal. Anything surrounded by quotes.
@@ -70,6 +70,9 @@ func (p *Parser) ParseGroup() token.Token {
os.Exit(8)

case token.Ident:
groupTokens = append(groupTokens, p.CurrentToken)
p.Shift()
fmt.Println("GROUP PARSE IDENT")
p.ParseIdent(&groupTokens, p.CurrentToken)

case token.Literal:
@@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"github.com/scottshotgg/ExpressRedo/token"
"github.com/scottshotgg/express-rearch/token"
)

var (
@@ -2,8 +2,10 @@ package parse

import (
"encoding/json"
"fmt"

"github.com/scottshotgg/ExpressRedo/token"
"github.com/pkg/errors"
"github.com/scottshotgg/express-rearch/token"
)

// // CollectTokens appends an array of tokens passed in to the EndTokens attribute of Meta
@@ -139,3 +141,147 @@ func TokenToString(t token.Token) string {

return string(jsonToken)
}

func variableTypeFromString(vtString string) (vt VariableType) {
switch vtString {
case "var":
vt = VAR
case "int":
vt = INT
case "bool":
vt = BOOL
case "string":
vt = STRING
case "float":
vt = FLOAT
case "BLOCK":
vt = OBJECT
case "set":
vt = SET
case "array":
vt = ARRAY
case "object":
vt = OBJECT

// default:
// fmt.Println(vtString)
// os.Exit(9)
}

return
}

func accessTypeFromString(atString string) (at AccessType) {
switch atString {
case "public":
at = PUBLIC
case "private":
at = PRIVATE
}

return
}

func VariableTypeString(vt VariableType) (st string) {
switch vt {
case VAR:
st = "var"
case INT:
st = "int"
case FLOAT:
st = "float"
case BOOL:
st = "bool"
case STRING:
st = "string"
case SET:
st = "set"
case OBJECT:
st = "object"
case ARRAY:
st = "array"
// case STRINGA:
// st = "string[]"

default:
st = ""
}

return
}

func AccessTypeString(at AccessType) (st string) {
switch at {
case PUBLIC:
st = "public"
case PRIVATE:
st = "private"

default:
st = ""
}

return
}

func getBaseForType(trueType, actingType string) (interface{}, error) {
switch trueType {
case token.IntType:
return 0, nil

case token.StringType:
return "", nil

case token.BoolType:
return false, nil

case token.FloatType:
return 0.0, nil

case token.CharType:
return "", nil

// case token.StructType:
// fallthrough
// case token.ObjectType:
// return

// case token.FunctionType:

// case token.VarType:

// case token.ArrayType:
// return

default:
var shit interface{}
return shit, errors.Errorf("Base not defined for type: %s %s", trueType, actingType)
}
}

// func getAccessTypeFromIdentName(string identName) (string, error) {
// if len(identName) > 0 {
// PRIVATE
// }
// return "", error
// }

func mapVariableToTokenValue(v *Variable) token.Value {
md := map[string]interface{}{}
for k, value := range v.Metadata {
md[k] = value
}

fmt.Println("md", md)
fmt.Println("metadata", v.Metadata)

return token.Value{
Name: v.Name,
Type: VariableTypeString(v.Type),
Acting: VariableTypeString(v.ActingType),
True: v.Value,
// String: ,
AccessType: AccessTypeString(v.AccessType),
Metadata: md,
}
}
BIN +1.07 KB (110%) test/output/bin/array.expr.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +1.07 KB (110%) test/output/bin/if.expr.exe
Binary file not shown.
BIN -3.05 KB (86%) test/output/bin/loop.expr.exe
Binary file not shown.
BIN -9.99 KB (86%) test/output/bin/object.expr.exe
Binary file not shown.
BIN -11.4 KB (79%) test/output/bin/var.expr.exe
Binary file not shown.
@@ -1,5 +1,5 @@
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/std.cpp"
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/var.cpp"
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/express-rearch/lib/std.cpp"
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/express-rearch/lib/var.cpp"
#include <string>
void declareSomething() { bool i = true; }

@@ -1,7 +1,6 @@
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/std.cpp"
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/var.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/std.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/var.cpp"
#include <string>
void declareSomething() { bool i = true; }

int main() {
bool bool1 = true;
@@ -1,5 +1,5 @@
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/std.cpp"
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/var.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/std.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/var.cpp"
#include <string>

int main() {
@@ -1,7 +1,6 @@
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/std.cpp"
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/var.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/std.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/var.cpp"
#include <string>
void declareSomething() { bool i = true; }

int main() {
int i = 10;
@@ -1,6 +1,5 @@
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/std.cpp"
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/var.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/std.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/var.cpp"
#include <string>
void declareSomething() { bool i = true; }

int main() {}
@@ -1,7 +1,6 @@
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/std.cpp"
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/var.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/std.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/var.cpp"
#include <string>
void declareSomething() { bool i = true; }

int main() {
int i = 8;
@@ -1,7 +1,6 @@
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/std.cpp"
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/var.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/std.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/var.cpp"
#include <string>
void declareSomething() { bool i = true; }

int main() {
int f = 0;
@@ -18,30 +17,30 @@ int main() {
}

{
int arrayBoi_1532797840[] = {1, 2, 4};
int arrayBoi_1532823281[] = {1, 2, 4};
int i = 0;
int i_1532797840 = 0;
while (i_1532797840 < 3) {
int i_1532823281 = 0;
while (i_1532823281 < 3) {
{
i = i_1532797840;
i = i_1532823281;
f = i;
int h = 1;
}
i_1532797840 += 1;
i_1532823281 += 1;
}
}
int countdown[] = {9, 8, 7, 5, 4, 3, 2, 1};

{
int i = 0;
int i_1532797840 = 0;
while (i_1532797840 < 8) {
int i_1532823281 = 0;
while (i_1532823281 < 8) {
{
i = countdown[i_1532797840];
i = countdown[i_1532823281];
f = i;
int h = 1;
}
i_1532797840 += 1;
i_1532823281 += 1;
}
}
}
@@ -1,7 +1,6 @@
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/std.cpp"
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/var.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/std.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/var.cpp"
#include <string>
void declareSomething() { bool i = true; }

int main() {
var obj = {};
@@ -12,26 +11,26 @@ int main() {
obj["hey"] = hey;
var objs[] = {};
{
var _SOTdhyFFyv = {};
_SOTdhyFFyv["another"] = "object";
objs[0] = _SOTdhyFFyv;
var _wCWvQFSYGe = {};
_wCWvQFSYGe["another"] = "object";
objs[0] = _wCWvQFSYGe;
}
{
var obj_YSkjXlpSzV = {};
obj_YSkjXlpSzV["something"] = "here";
var obj_XncSBIWSBK = {};
obj_XncSBIWSBK["something"] = "here";
var hey = {};
hey["me"] = true;
hey["anIntVariable"] = 69;
obj_YSkjXlpSzV["hey"] = hey;
objs[1] = obj_YSkjXlpSzV;
obj_XncSBIWSBK["hey"] = hey;
objs[1] = obj_XncSBIWSBK;
}
{
var obj_FFXnkfZvAP = {};
obj_FFXnkfZvAP["something"] = "here";
var obj_IANNwVcfXW = {};
obj_IANNwVcfXW["something"] = "here";
var hey = {};
hey["me"] = true;
hey["anIntVariable"] = 69;
obj_FFXnkfZvAP["hey"] = hey;
objs[2] = obj_FFXnkfZvAP;
obj_IANNwVcfXW["hey"] = hey;
objs[2] = obj_IANNwVcfXW;
}
}
@@ -1,7 +1,6 @@
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/std.cpp"
#include "/Users/sgg7269/Development/go/src/github.com/scottshotgg/ExpressRedo/lib/var.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/std.cpp"
#include "/home/scottshotgg/Development/go/src/github.com/scottshotgg/express-rearch/lib/var.cpp"
#include <string>
void declareSomething() { bool i = true; }

int main() {
var hi_my_type_is = "what";
@@ -1,4 +1,45 @@
[
{
"Type": "WS",
"Value": {
"Type": "newline",
"String": "\n"
}
},
{
"Type": "WS",
"Value": {
"Type": "newline",
"String": "\n"
}
},
{
"Type": "TYPE",
"Value": {
"Type": "int",
"String": "int"
}
},
{
"Type": "WS",
"Value": {
"Type": "space",
"String": " "
}
},
{
"Type": "IDENT",
"Value": {
"String": "i"
}
},
{
"Type": "WS",
"Value": {
"Type": "newline",
"String": "\n"
}
},
{
"Type": "WS",
"Value": {
@@ -24,7 +65,7 @@
{
"Type": "IDENT",
"Value": {
"String": "declareSomething"
"String": "setToOne"
}
},
{
@@ -34,6 +75,26 @@
"String": "("
}
},
{
"Type": "TYPE",
"Value": {
"Type": "int",
"String": "int"
}
},
{
"Type": "WS",
"Value": {
"Type": "space",
"String": " "
}
},
{
"Type": "IDENT",
"Value": {
"String": "i"
}
},
{
"Type": "R_PAREN",
"Value": {
@@ -89,13 +150,6 @@
"String": " "
}
},
{
"Type": "ASSIGN",
"Value": {
"Type": "set",
"String": ":"
}
},
{
"Type": "ASSIGN",
"Value": {
@@ -113,8 +167,8 @@
{
"Type": "LITERAL",
"Value": {
"Type": "bool",
"True": true
"Type": "int",
"True": 1
}
},
{
@@ -1,32 +1,4 @@
{
"Type": "BLOCK",
"True": [
{
"Name": "declareSomething",
"Type": "FUNCTION",
"True": {
"args": {
"Name": "args",
"Type": "GROUP",
"True": []
},
"body": {
"Type": "BLOCK",
"True": [
{
"Name": "i",
"Type": "bool",
"True": true,
"AccessType": "private"
}
]
},
"returns": {}
},
"AccessType": "private",
"Metadata": {
"lambda": false
}
}
]
"True": []
}
@@ -100,7 +100,7 @@
"AccessType": "private",
"Metadata": {
"assign": true,
"refs": "i_1532797840"
"refs": "i_1532823281"
}
},
{
@@ -120,18 +120,18 @@
"AccessType": "private"
}
],
"String": "i_1532797840\u003c3",
"String": "i_1532823281\u003c3",
"Metadata": {
"end": {
"Name": "i_1532797840",
"Name": "i_1532823281",
"Type": "int",
"True": 3,
"String": "3",
"AccessType": "private"
},
"extraVars": [
{
"Name": "arrayBoi_1532797840",
"Name": "arrayBoi_1532823281",
"Type": "array",
"Acting": "int",
"True": [
@@ -176,14 +176,14 @@
}
],
"start": {
"Name": "i_1532797840",
"Name": "i_1532823281",
"Type": "int",
"True": 0,
"String": "0",
"AccessType": "private"
},
"step": {
"Name": "i_1532797840",
"Name": "i_1532823281",
"Type": "int",
"True": 1,
"String": "1",
@@ -278,7 +278,7 @@
"AccessType": "private",
"Metadata": {
"assign": true,
"refs": "countdown[i_1532797840]"
"refs": "countdown[i_1532823281]"
}
},
{
@@ -298,10 +298,10 @@
"AccessType": "private"
}
],
"String": "i_1532797840\u003c8",
"String": "i_1532823281\u003c8",
"Metadata": {
"end": {
"Name": "i_1532797840",
"Name": "i_1532823281",
"Type": "int",
"True": 8,
"String": "8",
@@ -318,14 +318,14 @@
}
],
"start": {
"Name": "i_1532797840",
"Name": "i_1532823281",
"Type": "int",
"True": 0,
"String": "0",
"AccessType": "private"
},
"step": {
"Name": "i_1532797840",
"Name": "i_1532823281",
"Type": "int",
"True": 1,
"String": "1",
@@ -4,6 +4,20 @@
"Value": {
"Type": "BLOCK",
"True": [
{
"Type": "TYPE",
"Value": {
"Type": "int",
"String": "int"
}
},
{
"Type": "IDENT",
"Value": {
"Type": "private",
"String": "i"
}
},
{
"ID": 9,
"Type": "KEYWORD",
@@ -16,15 +30,30 @@
"Type": "IDENT",
"Value": {
"Type": "private",
"String": "declareSomething"
"String": "setToOne"
}
},
{
"ID": 1,
"Type": "GROUP",
"Value": {
"Type": "GROUP",
"True": []
"True": [
{
"Type": "TYPE",
"Value": {
"Type": "int",
"String": "int"
}
},
{
"Type": "IDENT",
"Value": {
"Type": "private",
"String": "i"
}
}
]
}
},
{
@@ -42,15 +71,15 @@
{
"Type": "ASSIGN",
"Value": {
"Type": "init",
"String": ":="
"Type": "assign",
"String": "="
}
},
{
"Type": "LITERAL",
"Value": {
"Type": "bool",
"True": true
"Type": "int",
"True": 1
}
}
]
@@ -1,19 +1,21 @@
// This file is for testing functions

// Function without any arguments
func declareSomething() {
i := true
//func declareSomething() {
// i := true
//}

int i

// Function with one argument
func setToOne(int i) {
i = 1
}

// Save these for later
// TODO: we also need to do
// an example with desctructuring
/*
// Function with one argument
func increment(int i) {
i = i + 1
}

// Function with return
func gimmeSomething() int {
return 10