if(!list) list = eInstance_New(c);
list.Add(e);
}
- if(sep && peekToken().type == sep)
+ peekToken();
+ if(sep && nextToken.type == sep)
readToken();
- else if(sep || peekToken().type == '}')
+ else if(sep || nextToken.type == '}' || !nextToken.type)
break;
}
return list;
import "externals"
-/*
-public class MembersInit : struct
+public class ASTMemberInit : ASTNode
{
public:
- MembersInit prev, next;
- Location loc;
- MembersInitType type;
- union
- {
- OldList * dataMembers;
- ClassFunction function;
- };
- //bool coloned;
-};
-
-public class MemberInit : struct
-{
-public:
- MemberInit prev, next;
- Location loc;
Location realLoc;
- OldList * identifiers;
- // Expression exp;
- Initializer initializer;
+ List<ASTIdentifier> identifiers;
+ ASTInitializer initializer;
// COMPILE DATA
bool used;
bool variable;
bool takeOutExp;
+
+ ASTMemberInit ::parse()
+ {
+ ASTMemberInit init { };
+ while(true)
+ {
+ ASTIdentifier id = ASTIdentifier::parse();
+ if(id)
+ {
+ if(!init.identifiers) init.identifiers = { };
+ init.identifiers.Add(id);
+ if(peekToken().type != '.')
+ break;
+ }
+ }
+ if(peekToken().type == '=')
+ {
+ readToken();
+ init.initializer = ASTInitializer::parse();
+ }
+ return init;
+ }
+
+ void print()
+ {
+ if(identifiers)
+ {
+ Iterator<ASTIdentifier> it { identifiers };
+ while(it.Next())
+ {
+ it.data.print();
+ if(identifiers.GetNext(it.pointer))
+ Print(".");
+ }
+ }
+ Print(" = ");
+ if(initializer) initializer.print();
+ }
};
-*/
-/*
-public class ASTClassDefinition : struct
+public class MemberInitList : ASTList<ASTMemberInit>
{
-public:
- ASTSpecifier _class;
- SpecsList baseSpecs;
- SpecsList definitions;
- Symbol symbol;
- Location blockStart;
- Location nameLoc;
- int endid;
- AccessMode declMode;
- bool deleteWatchable;
-};
-*/
+ MemberInitList ::parse()
+ {
+ MemberInitList list = (MemberInitList)ASTList::parse(class(MemberInitList), ASTMemberInit::parse, ',');
+ if(peekToken().type == ';')
+ readToken();
+ return list;
+ }
+}
-/*
-public class PropertyDef : struct
+public class ASTPropertyDef : ASTNode
{
-public:
- PropertyDef prev, next;
- Location loc;
- OldList * specifiers;
+ SpecsList specifiers;
ASTDeclarator declarator;
- Identifier id;
- Statement getStmt;
- Statement setStmt;
- Statement issetStmt;
+ ASTIdentifier id;
+ ASTStatement getStmt;
+ ASTStatement setStmt;
+ ASTStatement issetStmt;
Symbol symbol;
bool conversion;
bool isWatchable;
- Expression category;
+ ASTExpression category;
};
-*/
public class ClassDefList : ASTList<ASTClassDef>
{
void printSep()
{
- PrintLn("");
}
}
ASTClassDef ::parse()
{
- SpecsList specs = SpecsList::parse();
- InitDeclList decls = InitDeclList::parse();
+ SpecsList specs = null;
+ InitDeclList decls = null;
+ int a = -1;
+
+ peekToken();
+ if(nextToken.type == '}')
+ return null;
+
+ if(nextToken.type == IDENTIFIER)
+ a = pushAmbiguity();
- if(peekToken().type == '{')
+ specs = SpecsList::parse();
+ decls = InitDeclList::parse();
+ peekToken();
+ if(nextToken.type == '{' || (decls && decls[0] && decls[0].declarator && decls[0].declarator._class == class(DeclFunction)))
return ClassDefFunction::parse(specs, decls);
- else if(specs || decls)
+ else if((specs || decls) && (nextToken.type != '.' && nextToken.type != '='))
+ {
+ if(a > -1) clearAmbiguity();
return ClassDefDeclaration::parse(specs, decls);
- else
+ }
+ else if(a > -1)
{
- readToken(); // Error
- return null;
+ ClassDefInitialization init;
+ popAmbiguity(a);
+
+ init = ClassDefInitialization::parse();
+ if(init)
+ return init;
}
+ readToken(); // Error
+ return null;
}
};
{
printIndent();
if(decl) decl.print();
+ PrintLn("");
}
}
{
ASTClassFunction function = ASTClassFunction::parse(specs, decls);
if(function)
- {
return { function = function };
- }
return null;
}
}
}
-/*
- List<ASTMemberInit> defProperties;
+public class ClassDefInitialization : ASTClassDef
+{
+ MemberInitList defValues;
+
+ ClassDefInitialization ::parse()
+ {
+ MemberInitList defValues = MemberInitList::parse();
+ if(defValues)
+ return { defValues = defValues };
+ return null;
+ }
+
+ void print()
+ {
+ if(defValues)
+ {
+ printIndent();
+ defValues.print();
+ PrintLn(";");
+ }
+ }
+}
+
+public class ClassDefProperty : ASTClassDef
+{
ASTPropertyDef propertyDef;
+}
+
+public class ClassDefPropertyWatch : ASTClassDef
+{
ASTPropertyWatch propertyWatch;
+}
+
+public class ClassDefDesigner : ASTClassDef
+{
String designer;
+}
+
+public class ClassDefDefaultProperty : ASTClassDef
+{
ASTIdentifier defaultProperty;
-*/
+}
Print("*");
if(qualifiers) qualifiers.print();
if(pointer) pointer.print();
- }
+ }
ASTPointer ::parse()
{
}
}
+public class TypeNameList : ASTList<ASTTypeName>
+{
+ TypeNameList ::parse()
+ {
+ TypeNameList list = null;
+ int a = pushAmbiguity();
+ while(true)
+ {
+ ASTTypeName e = ASTTypeName::parse();
+ peekToken();
+ if(e && (nextToken.type == ',' || nextToken.type == ')'))
+ {
+ if(!list) list = { };
+ list.Add(e);
+
+ clearAmbiguity();
+ if(nextToken.type == ',')
+ {
+ readToken();
+ a = pushAmbiguity();
+ }
+ else
+ break;
+ }
+ else
+ {
+ if(list)
+ list.Add({});
+ popAmbiguity(a);
+ break;
+ }
+ }
+ return list;
+ // return (TypeNameList)ASTList::parse(class(TypeNameList), ASTTypeName::parse, ',');
+ }
+}
+
public class DeclFunction : ASTDeclarator
{
public:
DeclFunction decl { declarator = d };
readToken();
if(peekToken().type != ')') decl.parameters = TypeNameList::parse();
- if(peekToken().type == ')') readToken();
+ if(peekToken().type == ')')
+ readToken();
return decl;
}
}
void print()
{
Print("(");
- if(declarator) declarator.print();
+ if(declarator) declarator.print();
Print(")");
}
void print()
{
- if(declarator) declarator.print();
+ if(declarator) declarator.print();
Print("[");
- if(exp) exp.print();
+ if(exp) exp.print();
Print("]");
}
public class DeclStruct : ASTDeclarator
{
ASTDeclarator declarator;
- Expression exp;
- Expression posExp;
- Attrib attrib;
+ ASTExpression exp;
+ ASTExpression posExp;
+ ASTAttrib attrib;
DeclStruct ::parse()
{
}
}
-/*
- union
- {
- struct
- {
- } structDecl;
- struct
- {
- ExtDecl extended;
- } extended;
- };
-*/
+public class DeclExtended : ASTDeclarator
+{
+ ExtDecl extended;
+}
public class ASTInitializer : ASTNode
{
{
SpecsList specs = SpecsList::parse();
ASTDeclarator decl = ASTDeclarator::parse();
- return { qualifiers = specs, declarator = decl };
+ if(specs || decl)
+ return { qualifiers = specs, declarator = decl };
+ return null;
}
void print()
}
};
-public class TypeNameList : ASTList<ASTTypeName>
-{
- TypeNameList ::parse()
- {
- return (TypeNameList)ASTList::parse(class(TypeNameList), ASTTypeName::parse, ',');
- }
-}
-
// Expressions
public class ASTExpression : ASTNode
{
*/
}
-public class ListExp : ASTList<ASTExpression>
+public class ExpList : ASTList<ASTExpression>
{
- ListExp ::parse()
+ ExpList ::parse()
{
- return (ListExp)ASTList::parse(class(ListExp), ASTExpression::parse, ',');
+ return (ExpList)ASTList::parse(class(ExpList), ASTExpression::parse, ',');
}
}
{
ExpBrackets exp { };
readToken();
- exp.list = ListExp::parse();
+ exp.list = ExpList::parse();
if(peekToken().type == ')')
readToken();
return exp;
readToken();
return ExpOperation { op = token.type, exp2 = ExpCast::parse() };
}
- /*else if(nextToken == SIZEOF)
- {
- readToken();
- return ExpSizeof { };
- }
- else if(nextToken == ALIGNOF)
- {
- readToken();
- return ExpSizeof { };
- }*/
+ /*
+ else if(nextToken.type == SIZEOF)
+ return ExpSizeof::parse();
+ else if(nextToken.type == ALIGNOF)
+ return ExpAlignOf::parse();
+ */
else
return parsePostfixExpression();
}
public class ExpBrackets : ASTExpression
{
public:
- ListExp list;
+ ExpList list;
void print()
{
{
public:
ASTExpression condition;
- ListExp expList;
+ ExpList expList;
ASTExpression elseExp;
void print()
ASTExpression exp = ExpOperation::parse(numPrec-1);
if(peekToken().type == '?')
{
- exp = ExpConditional { condition = exp, expList = ListExp::parse() };
+ exp = ExpConditional { condition = exp, expList = ExpList::parse() };
if(peekToken().type == ':')
((ExpConditional)exp).elseExp = ExpConditional::parse();
}
public class ExpIndex : ASTExpression
{
ASTExpression exp;
- ListExp index;
+ ExpList index;
void print()
{
{
ExpIndex exp;
readToken();
- exp = ExpIndex { exp = e, index = ListExp::parse() };
+ exp = ExpIndex { exp = e, index = ExpList::parse() };
if(peekToken().type == ']')
readToken();
return exp;
public class ExpCall : ASTExpression
{
ASTExpression exp;
- ListExp arguments;
+ ExpList arguments;
// Location argLoc;
void print()
{
ExpCall exp;
readToken();
- exp = ExpCall { exp = e, arguments = ListExp::parse() };
+ exp = ExpCall { exp = e, arguments = ExpList::parse() };
if(peekToken().type == ')')
readToken();
return exp;
}
}
-/* union
+public class ExpInstance : ASTExpression
+{
+ ASTInstantiation instance;
+}
+/*
+public class ExpSizeOf : ASTExpression
+{
+ ASTTypeName typeName;
+
+ ExpSizeOf ::parse()
+ {
+
+ }
+}
+
+public class ExpAlignOf : ASTExpression
+{
+ ASTTypeName typeName;
+
+ ExpAlignOf ::parse()
+ {
+ }
+}
+*/
+/*
+ union
{
- Instantiation instance;
struct
{
OldList * specifiers;
};
*/
-/*
- Instantiation inst;
- struct
- {
- Identifier id;
- Expression exp;
- };
- Specifier extStorage;
- Symbol symbol;
- AccessMode declMode;
-*/
-/*
-public class Instantiation : struct
+public class InstanceInit : ASTNode { }
+
+public class InstInitMember : InstanceInit
+{
+ MemberInitList members;
+}
+
+public class InstInitFunction : InstanceInit
+{
+ ASTClassFunction function;
+}
+
+public class ASTInstantiation : ASTNode
{
public:
- Instantiation prev, next;
- Location loc;
- Specifier _class;
- Expression exp;
- OldList * members;
+ ASTSpecifier _class;
+ ASTExpression exp;
+ List<InstanceInit> members;
Symbol symbol;
bool fullSet;
bool isConstant;
Location nameLoc, insideLoc;
bool built;
};
-*/
{
public:
DeclarationType type;
+ // ASTSpecifier extStorage;
+ // Symbol symbol;
+ // AccessMode declMode;
ASTDeclaration ::parse(SpecsList specs, InitDeclList decls)
{
}
}
+public class DeclarationInstance : ASTDeclaration
+{
+ ASTInstantiation inst;
+}
+
+public class DeclarationDefine : ASTDeclaration
+{
+ ASTIdentifier id;
+ ASTExpression exp;
+}
+
public class ASTFunctionDefinition : ASTNode
{
public:
void print()
{
- PrintLn("");
+ // PrintLn("");
printIndent();
if(specifiers)
{
/*
union
{
- FunctionDefinition function;
- ClassDefinition _class;
- Declaration declaration;
- char * importString;
- Identifier id;
+ ASTFunctionDefinition function;
+ SpecClass _class;
+ ASTDeclaration declaration;
+ String importString;
+ ASTIdentifier id;
DBTableDef table;
};
- ImportType importType;
};
*/
+/*
+class External
+{
+ ImportType importType;
+}
+*/
+
public class AST : ASTList<ASTNode>
{
ASTNode ::ParseExternalDeclaration()
if(tokenStack.size > stackPos)
memmove(tokenStack.array, tokenStack.array + stackPos, (tokenStack.size - stackPos) * sizeof(Token));
tokenStack.size -= stackPos;
- stackPos = 0;
+ stackPos = 0;
}
}
// Specifiers
public class ASTSpecifier : ASTNode
{
-public:
- /* struct
- {
- //ExtDecl extDecl;
- //Symbol symbol;
- //OldList * templateArgs;
- };
- Expression expression;
- NewSpecifier _class;
- TemplateParameter templateParameter;
- };
- */
};
+public class SpecTypeOf : ASTSpecifier
+{
+ Expression expression;
+}
+
+public class SpecSubClass : ASTSpecifier
+{
+ ASTSpecifier _class;
+}
+
+public class SpecTemplateType : ASTSpecifier
+{
+ TemplateParameter templateParameter;
+}
+
public class SpecsList : ASTList<ASTSpecifier>
{
void printSep()
while(true)
{
peekToken();
- if(nextToken.type == STRUCT || nextToken.type == UNION)
+ if(nextToken.type == STRUCT || nextToken.type == UNION || nextToken.type == CLASS || nextToken.type == ENUM)
{
ASTSpecifier s = SpecClass::parse();
if(s)
public class SpecName : ASTSpecifier
{
String name;
+ //ExtDecl extDecl;
+ //Symbol symbol;
+ //List<ClassTemplateArgument> templateArgs;
void print()
{
}
}
-public class ASTEnumerator : struct
-{
-public:
- ASTIdentifier id;
- ASTExpression exp;
-};
-
public class SpecClass : ASTSpecifier
{
TokenType type;
ASTIdentifier id;
- List<ASTEnumerator> enumerators;
SpecsList baseSpecs;
ClassDefList definitions;
+
+ //ASTSpecifier _class;
+ // Symbol symbol;
+ //Location blockStart;
+ //Location nameLoc;
+ //bool deleteWatchable;
+ //int endid;
+ //AccessMode declMode;
bool addNameSpace;
Context ctx;
// ExtDecl extDeclStruct;
SpecClass ::parse()
{
- SpecClass spec { };
+ SpecClass spec = (peekToken().type == ENUM) ? SpecEnum { } : SpecClass { };
spec.type = readToken().type;
if(peekToken().type == IDENTIFIER)
spec.id = ASTIdentifier::parse();
+ if(peekToken().type == ':')
+ {
+ readToken();
+ spec.baseSpecs = SpecsList::parse();
+ }
if(peekToken().type == '{')
{
readToken();
spec.definitions = ClassDefList::parse();
+ if(!spec.definitions)
+ spec.definitions = { };
if(peekToken().type == '}')
readToken();
}
type.print();
Print(" ");
if(id) id.print();
+ if(baseSpecs)
+ {
+ Print(" : ");
+ baseSpecs.print();
+ }
if(definitions)
{
PrintLn("\n{");
indent++;
definitions.print();
indent--;
- Print("\n}");
+ Print("}");
}
}
}
-/*
-public class Attribute : struct
+public class ASTEnumerator : ASTNode
{
public:
- Attribute prev, next;
- Location loc;
+ ASTIdentifier id;
+ ASTExpression exp;
+};
+
+public class EnumeratorList : ASTList<ASTEnumerator>
+{
+}
+
+public class SpecEnum : SpecClass
+{
+ EnumeratorList enumerators;
+}
+
+public class ASTAttribute : ASTNode
+{
String attr;
- Expression exp;
+ ASTExpression exp;
}
-public class Attrib : struct
+public class ASTAttrib : ASTNode
{
-public:
- Location loc;
- int type;
- OldList * attribs;
+ TokenType type;
+ List<ASTAttribute> attribs;
+}
+
+public class ASTExtDecl : ASTNode { }
+
+public class ExtDeclString : ASTExtDecl
+{
+ String s;
}
-public class ExtDecl : struct
+public class ExtDeclAttrib : ASTExtDecl
{
-public:
- Location loc;
- ExtDeclType type;
- union
- {
- String s;
- Attrib attr;
- };
+ ASTAttrib attr;
}
-*/
public class StmtExpression : ASTStatement
{
- ListExp expressions;
+ ExpList expressions;
void print()
{
StmtExpression ::parse()
{
- ListExp exp = ListExp::parse();
+ ExpList exp = ExpList::parse();
if(exp)
{
StmtExpression stmt { expressions = exp };
public class StmtIf : ASTStatement
{
- ListExp exp;
+ ExpList exp;
ASTStatement stmt;
ASTStatement elseStmt;
if(elseStmt._class != class(StmtCompound)) elseStmt.print();
if(elseStmt._class == class(StmtExpression)) PrintLn("");
indent--;
- }
+ }
}
StmtIf ::parse()
if(peekToken().type == '(')
{
readToken();
- stmt.exp = ListExp::parse();
+ stmt.exp = ExpList::parse();
if(peekToken().type == ')') readToken();
stmt.stmt = ASTStatement::parse();
if(peekToken().type == ELSE)
public class StmtSwitch : ASTStatement
{
- ListExp exp;
+ ExpList exp;
ASTStatement stmt;
void print()
if(peekToken().type == '(')
{
readToken();
- stmt.exp = ListExp::parse();
+ stmt.exp = ExpList::parse();
if(peekToken().type == ')') readToken();
stmt.stmt = ASTStatement::parse();
}
public class StmtWhile : ASTStatement
{
- ListExp exp;
+ ExpList exp;
ASTStatement stmt;
StmtWhile ::parse()
if(peekToken().type == '(')
{
readToken();
- stmt.exp = ListExp::parse();
+ stmt.exp = ExpList::parse();
if(peekToken().type == ')') readToken();
stmt.stmt = ASTStatement::parse();
}
public class StmtDoWhile : ASTStatement
{
- ListExp exp;
+ ExpList exp;
ASTStatement stmt;
StmtDoWhile ::parse()
if(peekToken().type == '(')
{
readToken();
- stmt.exp = ListExp::parse();
+ stmt.exp = ExpList::parse();
if(peekToken().type == ')') readToken();
}
if(peekToken().type == ';') readToken();
{
ASTStatement init;
ASTStatement check;
- ListExp increment;
+ ExpList increment;
ASTStatement stmt;
void print()
readToken();
stmt.init = ASTStatement::parse();
stmt.check = ASTStatement::parse();
- stmt.increment = ListExp::parse();
+ stmt.increment = ExpList::parse();
if(peekToken().type == ')')
{
readToken();
stmt.stmt = ASTStatement::parse();
- }
+ }
}
return stmt;
}
public class StmtReturn : ASTStatement
{
- ListExp exp;
+ ExpList exp;
void print()
{
Print("return");
{
StmtReturn stmt { };
readToken();
- if(peekToken().type != ';') stmt.exp = ListExp::parse();
+ if(peekToken().type != ';') stmt.exp = ExpList::parse();
if(peekToken().type == ';') readToken();
return stmt;
}
public class StmtForEach : ASTStatement
{
Identifier id;
- ListExp exp;
- ListExp filter;
+ ExpList exp;
+ ExpList filter;
Statement stmt;
}
+class Form1 : Window
+{
+ void OnCreate(
+
+ caption = "Form1";
+ background = formColor;
+ borderStyle = sizable;
+ hasMaximize = true;
+ hasMinimize = true;
+ hasClose = true;
+ clientSize = { 632, 438 };
+}
+
struct InventoryItem
{
- float price;
+ float price = 5;
String name;
- void Print()
- {
- int a;
- PrintLn(a + 4);
- }
+ price = 10.0f;
} item, * itemPtr;
class SomeClass
typedef int bla;
+// import "ecere"
+
int SomeFunction(int * p)
{
int b[3][4] =