Changed from typedef to obj and def

This commit is contained in:
Nathan Braswell
2015-05-16 12:05:23 -04:00
parent 4bc42bc516
commit 65fd2ed9b7
27 changed files with 55 additions and 47 deletions

View File

@@ -52,7 +52,8 @@ triple_quoted_string = "\"\"\"((\"\"(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i
|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+\"\")|((`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'| |z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+\"\")|((`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'|
|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+))*\"\"\"" ; |z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+))*\"\"\"" ;
identifier = alpha_alphanumeric ; #identifier = alpha_alphanumeric ;
identifier = augmented_alpha_alphanumeric ;
scope_op = ":" ":" ; scope_op = ":" ":" ;
scoped_identifier = scoped_identifier WS scope_op WS identifier | identifier ; scoped_identifier = scoped_identifier WS scope_op WS identifier | identifier ;
@@ -70,7 +71,9 @@ opt_parameter_list = parameter_list | ;
parameter_list = parameter_list WS "," WS parameter | parameter ; parameter_list = parameter_list WS "," WS parameter | parameter ;
parameter = boolean_expression ; parameter = boolean_expression ;
type_def = "typedef" WS identifier WS type | "typedef" WS identifier WS template_dec WS "{" WS declaration_block WS "}" | "typedef" WS identifier WS "{" WS declaration_block WS "}" | "typedef" WS identifier WS template_dec WS traits WS "{" WS declaration_block WS "}" | "typedef" WS identifier WS traits WS "{" WS declaration_block WS "}" ; def_nonterm = "def" ;
obj_nonterm = "obj" ;
type_def = def_nonterm WS identifier WS type | obj_nonterm WS identifier WS template_dec WS "{" WS declaration_block WS "}" | obj_nonterm WS identifier WS "{" WS declaration_block WS "}" | obj_nonterm WS identifier WS template_dec WS traits WS "{" WS declaration_block WS "}" | obj_nonterm WS identifier WS traits WS "{" WS declaration_block WS "}" ;
declaration_block = declaration_statement line_end WS declaration_block | function WS declaration_block | declaration_statement line_end | function | ; declaration_block = declaration_statement line_end WS declaration_block | function WS declaration_block | declaration_statement line_end | function | ;
traits = "\(" WS trait_list WS "\)" ; traits = "\(" WS trait_list WS "\)" ;
@@ -115,7 +118,11 @@ floating_literal = numeric "." numeric ;
bool = "true" | "false" ; bool = "true" | "false" ;
character = "'(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'| character = "'(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'|
|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|\"|Z|X|C|V|B|N|M|<|>|\?| )'" ; |z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|\"|Z|X|C|V|B|N|M|<|>|\?| )'" ;
keywords_also_identifiers = "obj" | "def" ;
alpha_alphanumeric = "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|_)(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|_|0|1|2|3|4|5|6|7|8|9)*" ; alpha_alphanumeric = "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|_)(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|_|0|1|2|3|4|5|6|7|8|9)*" ;
augmented_alpha_alphanumeric = alpha_alphanumeric augmented_alpha_alphanumeric | keywords_also_identifiers augmented_alpha_alphanumeric | alpha_alphanumeric | keywords_also_identifiers ;
numeric = "(0|1|2|3|4|5|6|7|8|9)+" ; numeric = "(0|1|2|3|4|5|6|7|8|9)+" ;
string = triple_quoted_string | "\"(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'| string = triple_quoted_string | "\"(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'|
|z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )*\"" ; |z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )*\"" ;

View File

@@ -35,7 +35,8 @@ Importer::Importer(Parser* parserIn, std::vector<std::string> includePaths, std:
removeSymbols.push_back(Symbol("__if_comp__", true)); removeSymbols.push_back(Symbol("__if_comp__", true));
removeSymbols.push_back(Symbol("simple_passthrough", true)); removeSymbols.push_back(Symbol("simple_passthrough", true));
removeSymbols.push_back(Symbol("comp_simple_passthrough", true)); removeSymbols.push_back(Symbol("comp_simple_passthrough", true));
removeSymbols.push_back(Symbol("typedef", true)); removeSymbols.push_back(Symbol("def_nonterm", false));
removeSymbols.push_back(Symbol("obj_nonterm", false));
removeSymbols.push_back(Symbol("template", true)); removeSymbols.push_back(Symbol("template", true));
removeSymbols.push_back(Symbol("\\|", true)); removeSymbols.push_back(Symbol("\\|", true));
//collapseSymbols.push_back(Symbol("scoped_identifier", false)); //collapseSymbols.push_back(Symbol("scoped_identifier", false));

View File

@@ -1,7 +1,7 @@
import vector; import vector;
import mem; import mem;
typedef string (Destructable) { obj string (Destructable) {
var data: vector::vector<char>; var data: vector::vector<char>;
fun construct(): string* { fun construct(): string* {
data.construct(); data.construct();

View File

@@ -1,6 +1,6 @@
import io; import io;
typedef trivialContainer<T> { obj trivialContainer<T> {
var data: T; var data: T;
fun print(): void { fun print(): void {
io::print(data); io::print(data);

View File

@@ -2,7 +2,7 @@ import mem:*;
import util:*; import util:*;
import io:*; import io:*;
typedef vector<T> (Destructable) { obj vector<T> (Destructable) {
var data: T*; var data: T*;
var size: int; var size: int;
var available: int; var available: int;

View File

@@ -1,7 +1,7 @@
var sameVar: int; var sameVar: int;
fun sameFun(): int { return 5; } fun sameFun(): int { return 5; }
typedef classTester { obj classTester {
fun method(): int { return 8; } fun method(): int { return 8; }
} }

View File

@@ -1,6 +1,6 @@
var sameVar: int; var sameVar: int;
fun sameFun(): int { return 6; } fun sameFun(): int { return 6; }
typedef classTester { obj classTester {
fun method(): int { return 9; } fun method(): int { return 9; }
} }

View File

@@ -1,7 +1,7 @@
var qualified_variable: int = 7; var qualified_variable: int = 7;
fun qualified_func(): int { return 9; } fun qualified_func(): int { return 9; }
typedef qualified_class { obj qualified_class {
var number: int; var number: int;
fun construct(num: int): qualified_class* { fun construct(num: int): qualified_class* {
number = num; number = num;
@@ -12,7 +12,7 @@ typedef qualified_class {
} }
}; };
typedef qualified_container<T> { obj qualified_container<T> {
var data: T; var data: T;
fun construct(dataIn: T): qualified_container<T>* { fun construct(dataIn: T): qualified_container<T>* {
data = dataIn; data = dataIn;

View File

@@ -1,7 +1,7 @@
var unqualifed_variable: int = 8; var unqualifed_variable: int = 8;
fun unqualified_func(): int { return 10; } fun unqualified_func(): int { return 10; }
typedef unqualified_class { obj unqualified_class {
var number: int; var number: int;
fun construct(num: int): unqualified_class* { fun construct(num: int): unqualified_class* {
number = num; number = num;
@@ -12,7 +12,7 @@ typedef unqualified_class {
} }
}; };
typedef unqualified_container<T> { obj unqualified_container<T> {
var data: T; var data: T;
fun construct(dataIn: T): unqualified_container<T>* { fun construct(dataIn: T): unqualified_container<T>* {
data = dataIn; data = dataIn;

View File

@@ -1,6 +1,6 @@
import io:*; import io:*;
typedef Vec2 { obj Vec2 {
var x: int; var x: int;
var y: int; var y: int;

View File

@@ -1,7 +1,7 @@
import io:*; import io:*;
import mem:*; import mem:*;
typedef ClassWithConstructor { obj ClassWithConstructor {
var data: int; var data: int;
fun construct(inData: int): ClassWithConstructor* { fun construct(inData: int): ClassWithConstructor* {
data = inData; data = inData;

View File

@@ -1,6 +1,6 @@
import io:* import io:*
typedef FuncObj { obj FuncObj {
fun operator()(a:int, b:char*): void { fun operator()(a:int, b:char*): void {
println(a) println(a)
println(b) println(b)

View File

@@ -1,7 +1,7 @@
import mem:*; import mem:*;
import io:*; import io:*;
typedef AnObject { obj AnObject {
var a: int; var a: int;
var b: int; var b: int;
var c: char*; var c: char*;

View File

@@ -1,6 +1,6 @@
import io:*; import io:*;
typedef firstObject { obj firstObject {
var objectNum: int; var objectNum: int;
var other: int; var other: int;
fun print(): void { fun print(): void {
@@ -11,7 +11,7 @@ typedef firstObject {
} }
}; };
typedef Int int; def Int int;
var aliasNum: Int; var aliasNum: Int;

View File

@@ -1,7 +1,7 @@
import io:*; import io:*;
import trivial_container:*; import trivial_container:*;
typedef RegularObject { obj RegularObject {
var num: int; var num: int;
var innerContainer: trivialContainer<char*>; var innerContainer: trivialContainer<char*>;
fun set(message: char*, number: int): void { fun set(message: char*, number: int): void {
@@ -17,7 +17,7 @@ typedef RegularObject {
} }
}; };
typedef MyIntContainer trivialContainer<int>; def MyIntContainer trivialContainer<int>;
var roundabout: MyIntContainer; var roundabout: MyIntContainer;
var outsideDec: RegularObject; var outsideDec: RegularObject;

View File

@@ -1,6 +1,6 @@
typedef Swapper<T> { obj Swapper<T> {
fun doit(a: T*, b: T*) : void { fun doit(a: T*, b: T*) : void {
var temp: T = *a; var temp: T = *a;
*a = *b; *a = *b;

View File

@@ -1,10 +1,10 @@
import io:*; import io:*;
typedef objectA { obj objectA {
var a: int; var a: int;
}; };
typedef BigObject { obj BigObject {
var a: objectA; var a: objectA;
var b: objectB; var b: objectB;
fun add(): int { fun add(): int {
@@ -12,7 +12,7 @@ typedef BigObject {
} }
}; };
typedef objectB { obj objectB {
var b: int; var b: int;
}; };

View File

@@ -5,7 +5,7 @@ import sameNameTwo
var sameVar: int; var sameVar: int;
fun sameFun(): int { return 4; } fun sameFun(): int { return 4; }
typedef classTester { obj classTester {
fun method(): int { fun method(): int {
return 7 return 7
} }

View File

@@ -1,7 +1,7 @@
import io; import io;
typedef TemplateTest<T,J> { obj TemplateTest<T,J> {
var a: T; var a: T;
var b: J; var b: J;
fun print(): void { fun print(): void {

View File

@@ -1,7 +1,7 @@
import io; import io;
typedef TemplateTest<T> { obj TemplateTest<T> {
var a: int; var a: int;
var b: T; var b: T;
fun print(): void { fun print(): void {

View File

@@ -1,6 +1,6 @@
import io; import io;
typedef FirstObject { obj FirstObject {
var objectNum: int; var objectNum: int;
fun PrintSelf(a: int): void { fun PrintSelf(a: int): void {
io::print(objectNum); io::print(objectNum);

View File

@@ -2,7 +2,7 @@ import io:*
import mem:* import mem:*
import vector:* import vector:*
typedef pair<T, U> { obj pair<T, U> {
var first: T var first: T
var second: U var second: U
} }

View File

@@ -1,7 +1,7 @@
import io:*; import io:*;
import trivial_container:*; import trivial_container:*;
typedef TemplateTest<T> { obj TemplateTest<T> {
var a: int; var a: int;
var b: T; var b: T;
var c: trivialContainer<T>; var c: trivialContainer<T>;
@@ -17,7 +17,7 @@ typedef TemplateTest<T> {
} }
}; };
typedef MyInt int; def MyInt int;
var c: MyInt; var c: MyInt;

View File

@@ -1,11 +1,11 @@
import io:*; import io:*;
typedef NoTraits {}; obj NoTraits {};
typedef Trait1 (FirstTrait) {}; obj Trait1 (FirstTrait) {};
typedef Trait2 (SecondTrait) {}; obj Trait2 (SecondTrait) {};
typedef TwoTrait (FirstTrait, SecondTrait) {}; obj TwoTrait (FirstTrait, SecondTrait) {};
typedef AlreadySpecilized (FirstTrait, SecondTrait) {}; obj AlreadySpecilized (FirstTrait, SecondTrait) {};
fun OneTwoFunc<T>(obj: T): void { fun OneTwoFunc<T>(obj: T): void {
println("No Traits"); println("No Traits");
@@ -30,12 +30,12 @@ template <AlreadySpecilized> |void| OneTwoFunc(|AlreadySpecilized| obj) {
//This should work for objects too! //This should work for objects too!
//To test, we cycle the mapping of traits //To test, we cycle the mapping of traits
typedef OneTwoObj<T> (FirstTrait) {}; obj OneTwoObj<T> (FirstTrait) {};
typedef OneTwoObj<T(FirstTrait)> (SecondTrait) {}; obj OneTwoObj<T(FirstTrait)> (SecondTrait) {};
typedef OneTwoObj<T(SecondTrait)> (FirstTrait, SecondTrait) {}; obj OneTwoObj<T(SecondTrait)> (FirstTrait, SecondTrait) {};
typedef OneTwoObj<T(FirstTrait, SecondTrait)> {}; obj OneTwoObj<T(FirstTrait, SecondTrait)> {};
/* /*
*typedef template<AlreadySpecilized> OneTwoObj { *obj template<AlreadySpecilized> OneTwoObj {
* void proveSpecilized() { * void proveSpecilized() {
* println("I'm specilized!"); * println("I'm specilized!");
* } * }

View File

@@ -1,6 +1,6 @@
import io; import io;
typedef ClassWithConstructor { obj ClassWithConstructor {
var data: int; var data: int;
fun construct(inData: int): ClassWithConstructor* { fun construct(inData: int): ClassWithConstructor* {
data = inData; data = inData;

View File

@@ -7,11 +7,11 @@ fun retMessage(): char* {
} }
fun id<T>(in: T): T { return in; } fun id<T>(in: T): T { return in; }
typedef CustomObj { obj CustomObj {
var data: int; var data: int;
} }
typedef CustomObjTmplt<T> { obj CustomObjTmplt<T> {
var data: T; var data: T;
} }
fun inFun<T>(in: T):T { fun inFun<T>(in: T):T {

View File

@@ -2,7 +2,7 @@ import io:*;
import mem:*; import mem:*;
import vector:*; import vector:*;
typedef AbleToBeDestroyed (Destructable) { obj AbleToBeDestroyed (Destructable) {
fun destruct(): void { fun destruct(): void {
println("Destroyed!"); println("Destroyed!");
} }