More work on grammer and standard library! It can kinda load grammer now! Kinda. Marcus ran into the function pointer returns pointer ambiguity, so that'll have to be done tomorrow.
This commit is contained in:
@@ -840,7 +840,9 @@ NodeTree<ASTData>* ASTTransformation::doFunction(NodeTree<ASTData>* scope, std::
|
||||
std::cout << i->getDataRef()->toString() << " ";
|
||||
std::cout << std::endl;
|
||||
NodeTree<ASTData>* operatorMethod = NULL;
|
||||
if (nodes[0]->getDataRef()->valueType && nodes[0]->getDataRef()->valueType->typeDefinition)
|
||||
|
||||
// make sure this isn't a pointer, also. Silly vector<string> bug
|
||||
if (nodes[0]->getDataRef()->valueType && !nodes[0]->getDataRef()->valueType->getIndirection() && nodes[0]->getDataRef()->valueType->typeDefinition)
|
||||
operatorMethod = functionLookup(nodes[0]->getDataRef()->valueType->typeDefinition, lookupOp, mapNodesToTypes(slice(nodes,1,-1)));
|
||||
if (operatorMethod) {
|
||||
//Ok, so we construct
|
||||
|
||||
+67
-2
@@ -3,10 +3,54 @@ import vector
|
||||
import set
|
||||
import symbol
|
||||
import regex
|
||||
import io
|
||||
|
||||
fun parse_line(line: string::string): vector::vector<string::string> {
|
||||
var out.construct(): vector::vector<string>
|
||||
var begin = 0
|
||||
for (var i = 1; i < line.length(); i++;) {
|
||||
if (line[i] == '=') {
|
||||
i += 2
|
||||
begin = i
|
||||
}
|
||||
if (line[i] == ' ') {
|
||||
out.add(line.slice(begin, i))
|
||||
begin = i + 1
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
fun load_grammer(path: string::string): grammer {
|
||||
var gram.construct(): grammer
|
||||
io::read_file(path).lines().for_each(fun(line: string::string) {
|
||||
if (line.length() == 0)
|
||||
return;
|
||||
if (line[0] == '#') {
|
||||
io::print("comment: "); io::println(line)
|
||||
return;
|
||||
}
|
||||
var parts = parse_line(line)
|
||||
/*io::print("parts: ")*/
|
||||
/*parts.for_each(fun(i :string::string){ io::print(i); io::print(" "); })*/
|
||||
/*io::println()*/
|
||||
gram.rules.add(rule(symbol::symbol(parts[0], true),
|
||||
parts.slice(1,-1).map(fun(i: string::string):symbol::symbol {
|
||||
return symbol::symbol(i, true);
|
||||
})
|
||||
))
|
||||
})
|
||||
|
||||
|
||||
/*gram.rules.add(rule(symbol::symbol("test", true), vector::vector(symbol::symbol("rhs", true))))*/
|
||||
/*gram.rules.add(rule(symbol::symbol("lhs", true), vector::vector(symbol::symbol("rhs2", true))))*/
|
||||
/*gram.regexs.add(regex::regex("reg"))*/
|
||||
return gram
|
||||
}
|
||||
|
||||
obj grammer (Object) {
|
||||
var rules: vector::vector<rule>
|
||||
var regexs: set::set<regex>
|
||||
var regexs: set::set<regex::regex>
|
||||
|
||||
fun construct(): grammer* {
|
||||
rules.construct()
|
||||
@@ -24,6 +68,21 @@ obj grammer (Object) {
|
||||
rules.destruct()
|
||||
regexs.destruct()
|
||||
}
|
||||
|
||||
fun to_string(): string::string {
|
||||
var result = string::string("grammer rules:")
|
||||
rules.for_each( fun(i : rule) { result += string::string("\n\t") + i.to_string(); } )
|
||||
result += "\nregexs:"
|
||||
regexs.for_each( fun(i : regex::regex) { result += string::string("\n\t") + i.regexString; } )
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
fun rule(lhs: symbol::symbol, rhs: vector::vector<symbol::symbol>): rule {
|
||||
var toRet.construct(): rule
|
||||
toRet.lhs = lhs
|
||||
toRet.rhs = rhs
|
||||
return toRet
|
||||
}
|
||||
|
||||
obj rule (Object) {
|
||||
@@ -38,7 +97,7 @@ obj rule (Object) {
|
||||
position = 0
|
||||
lookahead.construct()
|
||||
}
|
||||
fun copy_construct(old: rule*) {
|
||||
fun copy_construct(other: rule*) {
|
||||
lhs.copy_construct(&other->lhs)
|
||||
rhs.copy_construct(&other->rhs)
|
||||
position = other->position
|
||||
@@ -53,5 +112,11 @@ obj rule (Object) {
|
||||
rhs.destruct()
|
||||
lookahead.destruct()
|
||||
}
|
||||
|
||||
fun to_string(): string::string {
|
||||
var result = lhs.name + " -> "
|
||||
rhs.for_each( fun(i : symbol::symbol) { result += i.name + " "; } )
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,10 @@ obj regex (Object) {
|
||||
mem::safe_recursive_delete(begin, fun(it: regexState*): set::set<regexState*> { return set::from_vector(it->next_states); } )
|
||||
}
|
||||
|
||||
fun operator==(other: regex):bool {
|
||||
return regexString == other.regexString
|
||||
}
|
||||
|
||||
fun operator=(other: regex):void {
|
||||
destruct()
|
||||
construct(other.regexString)
|
||||
|
||||
@@ -81,6 +81,10 @@ obj string (Object) {
|
||||
return ret
|
||||
}
|
||||
|
||||
fun operator+=(character: char): void {
|
||||
data += character
|
||||
}
|
||||
|
||||
fun operator+=(str: char*): void {
|
||||
var newStr.construct(str):string
|
||||
data += newStr.data
|
||||
@@ -99,5 +103,20 @@ obj string (Object) {
|
||||
out[data.size] = 0
|
||||
return out;
|
||||
}
|
||||
|
||||
fun lines(): vector::vector<string> {
|
||||
var out.construct(): vector::vector<string>
|
||||
var current = string("")
|
||||
for (var i = 0; i < data.size; i++;) {
|
||||
if (data[i] == '\n') {
|
||||
out.add(current)
|
||||
current = string("")
|
||||
} else {
|
||||
current += data[i]
|
||||
}
|
||||
}
|
||||
out.add(current)
|
||||
return out
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -60,6 +60,10 @@ obj vector<T> (Object) {
|
||||
return newVec
|
||||
}
|
||||
|
||||
fun operator+=(other: T):void {
|
||||
addEnd(other)
|
||||
}
|
||||
|
||||
fun operator+=(other:vector<T>):void {
|
||||
for (var i = 0; i < other.size; i++;)
|
||||
addEnd(other.get(i))
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# comment
|
||||
a = b ;
|
||||
b = "c" ;
|
||||
b = "c" "d" ;
|
||||
+28
-1
@@ -1,7 +1,34 @@
|
||||
import io
|
||||
import io: something
|
||||
|
||||
//comments
|
||||
|
||||
fun first(): cutomTye {
|
||||
}
|
||||
fun another(): cutomTye<hello, beta>* {
|
||||
|
||||
}
|
||||
|
||||
fun main():int {
|
||||
if (true) {
|
||||
thing;
|
||||
}
|
||||
if ( 3 < 300) {
|
||||
}
|
||||
if ( 3 > 300) {
|
||||
}
|
||||
var hastype: type = 20
|
||||
thingy.other;
|
||||
if ( 3 < 300) {
|
||||
}
|
||||
io::print("hi")
|
||||
wanna.callit(internal, to ,it)
|
||||
var a = 2 + 7;
|
||||
var b = 2 + 7 / 3 - 2 * 7 && 9 || 2 + !g
|
||||
return 0
|
||||
return 11820
|
||||
return 1.1
|
||||
return 1.1f
|
||||
return "hi"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import io:*
|
||||
import grammer:*
|
||||
import string:*
|
||||
|
||||
fun main():int {
|
||||
var a = load_grammer(string("grammer.kgm"))
|
||||
println(a.to_string())
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
fun main():int {
|
||||
var wr: fun():int*
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -9,3 +9,5 @@ a
|
||||
now win!
|
||||
true
|
||||
false
|
||||
2
|
||||
lines
|
||||
|
||||
@@ -22,6 +22,7 @@ fun main(): int {
|
||||
io::println(newWay)
|
||||
io::println( string::string("yes") == string::string("yes") )
|
||||
io::println( string::string("no") == string::string("yes") )
|
||||
string::string("2\nlines").lines().for_each(fun(i: string::string) io::println(i);)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user