Cleaned up variable declaring
Also declared variables when assignment is completedparser_exception_before
parent
0445534cda
commit
5f6c9b5f57
|
@ -4,7 +4,7 @@ import gogga;
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
import compiler.lexer;
|
import compiler.lexer;
|
||||||
import std.stdio : File;
|
import std.stdio : File;
|
||||||
import compiler.parser;
|
import compiler.parsing.core;
|
||||||
import compiler.symbols.check;
|
import compiler.symbols.check;
|
||||||
import compiler.symbols.data;
|
import compiler.symbols.data;
|
||||||
import compiler.typecheck.core;
|
import compiler.typecheck.core;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module compiler.parser;
|
module compiler.parsing.core;
|
||||||
|
|
||||||
import gogga;
|
import gogga;
|
||||||
import std.conv : to;
|
import std.conv : to;
|
|
@ -6,7 +6,7 @@ import std.conv : to;
|
||||||
import std.string;
|
import std.string;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
import gogga;
|
import gogga;
|
||||||
import compiler.parser;
|
import compiler.parsing.core;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Parser only makes sure syntax
|
* The Parser only makes sure syntax
|
||||||
|
@ -149,6 +149,15 @@ public final class TypeChecker
|
||||||
Variable variable = cast(Variable)statement;
|
Variable variable = cast(Variable)statement;
|
||||||
gprintln("Declaring variable"~variable.getName());
|
gprintln("Declaring variable"~variable.getName());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To check if a name is taken we check if the current one equals the
|
||||||
|
* first match (if so, then declare, if not, then taken)
|
||||||
|
*/
|
||||||
|
if(getEntity(c, variable.getName()) != variable)
|
||||||
|
{
|
||||||
|
Parser.expect("Duplicate name tried to be declared");
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if this variable has an expression, if so check that */
|
/* Check if this variable has an expression, if so check that */
|
||||||
if(variable.getAssignment())
|
if(variable.getAssignment())
|
||||||
{
|
{
|
||||||
|
@ -162,25 +171,12 @@ public final class TypeChecker
|
||||||
Parser.expect("Expression type fetch failed: "~variable.getName());
|
Parser.expect("Expression type fetch failed: "~variable.getName());
|
||||||
}
|
}
|
||||||
gprintln("ExpressionTYpe in VarAssign: "~type);
|
gprintln("ExpressionTYpe in VarAssign: "~type);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/* If not then go ahead and attempt to declare it */
|
|
||||||
else
|
/* Set the variable as declared */
|
||||||
{
|
markEntity(variable);
|
||||||
/**
|
|
||||||
* To check if a name is taken we check if the current one equals the
|
|
||||||
* first match (if so, then declare, if not, then taken)
|
|
||||||
*/
|
|
||||||
if(getEntity(c, variable.getName()) != variable)
|
|
||||||
{
|
|
||||||
import compiler.parser;
|
|
||||||
Parser.expect("Duplicate name tried to be declared");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
markEntity(variable);
|
|
||||||
// declareName(path~variable.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -399,7 +395,6 @@ public final class TypeChecker
|
||||||
private bool checkDuplicateTopLevel()
|
private bool checkDuplicateTopLevel()
|
||||||
{
|
{
|
||||||
import misc.utils;
|
import misc.utils;
|
||||||
import compiler.parser : Parser;
|
|
||||||
|
|
||||||
/* List of names travsersed so far */
|
/* List of names travsersed so far */
|
||||||
string[] names;
|
string[] names;
|
||||||
|
@ -429,7 +424,7 @@ unittest
|
||||||
import std.file;
|
import std.file;
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
import compiler.lexer;
|
import compiler.lexer;
|
||||||
import compiler.parser;
|
import compiler.parsing.core;
|
||||||
|
|
||||||
// isUnitTest = true;
|
// isUnitTest = true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue