Added Parser
- can parse a basic token list to an AST
This commit is contained in:
parent
ea26acce4a
commit
b3fe78fffb
19 changed files with 451 additions and 88 deletions
17
Compiler/Parser/Exceptions/InvalidIdentifierException.cs
Normal file
17
Compiler/Parser/Exceptions/InvalidIdentifierException.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
|
||||
namespace Compiler.Parser.Exceptions
|
||||
{
|
||||
public class InvalidIdentifierException : Exception
|
||||
{
|
||||
private string value { get; set; }
|
||||
|
||||
public override string Message { get; }
|
||||
|
||||
public InvalidIdentifierException(string value)
|
||||
{
|
||||
this.value = value;
|
||||
this.Message = "Unexpected Identifier " + this.value + ".";
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Compiler/Parser/Exceptions/MissingSemicolonException.cs
Normal file
9
Compiler/Parser/Exceptions/MissingSemicolonException.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace Compiler.Parser.Exceptions
|
||||
{
|
||||
public class MissingSemicolonException : Exception
|
||||
{
|
||||
public override string Message { get; }
|
||||
}
|
||||
}
|
||||
20
Compiler/Parser/Exceptions/UnexpectedTokenException.cs
Normal file
20
Compiler/Parser/Exceptions/UnexpectedTokenException.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using Compiler.Lexer;
|
||||
|
||||
namespace Compiler.Parser.Exceptions
|
||||
{
|
||||
public class UnexpectedTokenException : Exception
|
||||
{
|
||||
public TokenType expected { get; set; }
|
||||
public TokenType got { get; set; }
|
||||
|
||||
public override string Message { get; }
|
||||
|
||||
public UnexpectedTokenException(TokenType expected, TokenType got)
|
||||
{
|
||||
this.expected = expected;
|
||||
this.got = got;
|
||||
this.Message = "Unexpected Token " + got + ". Expected: " + expected;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Compiler/Parser/Exceptions/WrongTypeException.cs
Normal file
21
Compiler/Parser/Exceptions/WrongTypeException.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
|
||||
namespace Compiler.Parser.Exceptions
|
||||
{
|
||||
public class WrongTypeException : Exception
|
||||
{
|
||||
private Type expected;
|
||||
private Type got;
|
||||
|
||||
public override string Message { get; }
|
||||
|
||||
public WrongTypeException(Type expected, Type got)
|
||||
{
|
||||
this.expected = expected;
|
||||
this.got = got;
|
||||
|
||||
this.Message = "Expected type " + expected +
|
||||
"but got type " + got + ".";
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue