Added support for variable assignments
parent
07c0eb3718
commit
87e4cd2fe6
|
@ -216,6 +216,30 @@ public final class Parser
|
||||||
tokenPtr--;
|
tokenPtr--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Assignment parseAssignment()
|
||||||
|
{
|
||||||
|
/* Generated Assignment statement */
|
||||||
|
Assignment assignment;
|
||||||
|
|
||||||
|
/* The identifier being assigned to */
|
||||||
|
string identifier = getCurrentToken().getToken();
|
||||||
|
nextToken();
|
||||||
|
nextToken();
|
||||||
|
|
||||||
|
/* Expression */
|
||||||
|
Expression assignmentExpression = parseExpression();
|
||||||
|
|
||||||
|
assignment = new Assignment(identifier, assignmentExpression);
|
||||||
|
|
||||||
|
/* TODO: Support for (a=1)? */
|
||||||
|
/* Expect a semicolon */
|
||||||
|
expect(SymbolType.SEMICOLON, getCurrentToken());
|
||||||
|
nextToken();
|
||||||
|
|
||||||
|
|
||||||
|
return assignment;
|
||||||
|
}
|
||||||
|
|
||||||
public Statement parseName()
|
public Statement parseName()
|
||||||
{
|
{
|
||||||
Statement ret;
|
Statement ret;
|
||||||
|
@ -246,6 +270,12 @@ public final class Parser
|
||||||
previousToken();
|
previousToken();
|
||||||
ret = parseTypedDeclaration();
|
ret = parseTypedDeclaration();
|
||||||
}
|
}
|
||||||
|
/* Assignment */
|
||||||
|
else if(type == SymbolType.ASSIGN)
|
||||||
|
{
|
||||||
|
previousToken();
|
||||||
|
ret = parseAssignment();
|
||||||
|
}
|
||||||
/* Any other case */
|
/* Any other case */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -92,6 +92,18 @@ public enum FunctionType
|
||||||
STATIC, VIRTUAL
|
STATIC, VIRTUAL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Assignment : Statement
|
||||||
|
{
|
||||||
|
private string identifier;
|
||||||
|
private Expression assignmentExpression;
|
||||||
|
|
||||||
|
this(string identifier, Expression assignmentExpression)
|
||||||
|
{
|
||||||
|
this.identifier = identifier;
|
||||||
|
this.assignmentExpression = assignmentExpression;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Declared variables, defined classes and fucntions */
|
/* Declared variables, defined classes and fucntions */
|
||||||
public class Entity : Statement
|
public class Entity : Statement
|
||||||
{
|
{
|
||||||
|
|
|
@ -91,7 +91,7 @@ public final class TypeChecker
|
||||||
* Classes being declared before Functions and
|
* Classes being declared before Functions and
|
||||||
* Functions before Variables
|
* Functions before Variables
|
||||||
*/
|
*/
|
||||||
checkContainer(modulle);
|
checkContainer(modulle); /* TODO: Rename checkContainerCollision */
|
||||||
|
|
||||||
checkIt(modulle);
|
checkIt(modulle);
|
||||||
}
|
}
|
||||||
|
@ -401,6 +401,11 @@ public final class TypeChecker
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the first occurring Entity with the provided
|
||||||
|
* name based on Classes being searched, then Functions
|
||||||
|
* and lastly Variables
|
||||||
|
*/
|
||||||
public Entity findPrecedence(Container c, string name)
|
public Entity findPrecedence(Container c, string name)
|
||||||
{
|
{
|
||||||
foreach(Entity entity; getContainerMembers(c))
|
foreach(Entity entity; getContainerMembers(c))
|
||||||
|
|
|
@ -9,6 +9,8 @@ int b = a;
|
||||||
int c = myModule.x;
|
int c = myModule.x;
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
|
l=2;
|
||||||
|
|
||||||
|
|
||||||
int o = myModule.l;
|
int o = myModule.l;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue