This commit is contained in:
Tristan B. Kildaire 2021-03-29 21:06:37 +02:00
parent 2cf88b01be
commit 9c829302a5
4 changed files with 83 additions and 20 deletions

View File

@ -43,10 +43,10 @@ void beginCompilation(string[] sourceFiles)
gprintln("Parsing tokens...");
Parser parser = new Parser(currentLexer.getTokens());
Program program = parser.parse();
Module modulle = parser.parse();
gprintln("Type checking and symbol resolution...");
TypeChecker typeChecker = new TypeChecker(program);
typeChecker.check();
TypeChecker typeChecker = new TypeChecker(modulle);
// typeChecker.check();
}
}

View File

@ -658,7 +658,7 @@ public final class Parser
/* TODO: Leave the token here */
/* TODO: Just leave it, yeah */
// expect("poes");
toAdd = new Expression();
toAdd = new VariableExpression(identifier);
}
/* TODO: Change this later, for now we doing this */
@ -921,11 +921,11 @@ public final class Parser
* one to define classes within functions
*/
/* TODO: Variables should be allowed to have letters in them and underscores */
public Program parse()
public Module parse()
{
gprintln("parse(): Enter", DebugType.WARNING);
Program program;
Module modulle;
/* TODO: Do parsing here */
@ -941,8 +941,8 @@ public final class Parser
expect(SymbolType.SEMICOLON, getCurrentToken());
nextToken();
/* Initialize Program */
program = new Program(programName);
/* Initialize Module */
modulle = new Module(programName);
/* TODO: do `hasTokens()` check */
/* TODO: We should add `hasTokens()` to the `nextToken()` */
@ -971,7 +971,7 @@ public final class Parser
}
/* Add this statement to the program's statement list */
program.addStatement(varFunc);
modulle.addStatement(varFunc);
}
/* If it is an accessor */
else if (isAccessor(tok))
@ -979,7 +979,7 @@ public final class Parser
Statement statement = parseAccessor();
/* TODO: Tets case has classes which null statement, will crash */
program.addStatement(statement);
modulle.addStatement(statement);
}
/* If it is a class */
else if (symbol == SymbolType.CLASS)
@ -987,7 +987,7 @@ public final class Parser
Clazz clazz = parseClass();
/* Add the class definition to the program */
program.addStatement(clazz);
modulle.addStatement(clazz);
}
else
{
@ -997,7 +997,7 @@ public final class Parser
gprintln("parse(): Leave", DebugType.WARNING);
return program;
return modulle;
}
}
@ -1045,7 +1045,7 @@ unittest
isUnitTest = true;
string sourceFile = "source/tlang/testing/basic2.t";
string sourceFile = "source/tlang/testing/basic1.t";
File sourceFileFile;
sourceFileFile.open(sourceFile); /* TODO: Error handling with ANY file I/O */

View File

@ -507,6 +507,11 @@ public class Container : Entity
super(name);
}
public void addStatement(Statement statement)
{
this.statements ~= statement;
}
public void addStatements(Statement[] statements)
{
this.statements ~= statements;
@ -518,6 +523,13 @@ public class Container : Entity
}
}
public class Module : Container
{
this(string moduleName)
{
super(moduleName);
}
}
public class Clazz : Container
{
@ -644,10 +656,12 @@ public class Variable : TypedEntity
public class Expression : Statement
{
/* TODO: Everything must implement this */
import compiler.typecheck;
/* TODO: Takes in symbol table? */
public string evaluateType()
public string evaluateType(TypeChecker typechecker, Statement[] stateexpression)
{
/* TODO: Go through here evaluating the type */
return null;
}
@ -659,6 +673,8 @@ public class Expression : Statement
/* TODO: Evalute this expression's type */
}
/* TODO: Look into arrays later */
public class StringExpression : Expression
{
@ -718,26 +734,70 @@ public class VariableAssignment
this(Expression)
{
this.expression = expression;
}
public Expression getExpression()
{
return expression;
}
}
public class Call : Expression
public class IdentExpression : Expression
{
/* name */
private string name;
this(string name)
{
this.name = name;
}
public string getName()
{
return name;
}
}
public class VariableExpression : IdentExpression
{
this(string identifier)
{
super(identifier);
}
import compiler.typecheck;
public override string evaluateType(TypeChecker typeChecker, Statement[] startingPoint)
{
string type;
/* Get all names and see if i am in it firstly */
Entity entity = typeChecker.isValidEntity(startingPoint, getName());
return type;
}
}
public class Call : IdentExpression
{
this(string ident)
{
super(ident);
}
}
public final class FunctionCall : Call
{
/* Function name */
private string functionName;
/* Argument list */
private Expression[] arguments;
this(string functionName, Expression[] arguments)
{
this.functionName = functionName;
super(functionName);
this.arguments = arguments;
}
}

View File

@ -5,8 +5,11 @@ int x;
ubyte y;
int a;
int b = a.a;
int b = a;
int c = b;
int l;
int o = a.a;
int f = f.L(f(1+f.d.d.d()));
int p = f2p.j2.p;