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
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Compiler.Lexer;
|
||||
using Compiler.Parser;
|
||||
|
||||
namespace Compiler
|
||||
{
|
||||
|
|
@ -8,29 +10,44 @@ namespace Compiler
|
|||
{
|
||||
public static void Main()
|
||||
{
|
||||
TestCompiler("../../../../tests/week_1/valid");
|
||||
TestCompiler("../../../../tests/week_1/invalid");
|
||||
List<List<Token>> tokensValid = TestLexer("../../../../tests/week_1/valid");
|
||||
List<List<Token>> tokensInvalid = TestLexer("../../../../tests/week_1/invalid");
|
||||
|
||||
TestParser(tokensValid[0]);
|
||||
TestParser(tokensInvalid[0]);
|
||||
}
|
||||
|
||||
static void TestCompiler(String path)
|
||||
static List<List<Token>> TestLexer(String path)
|
||||
{
|
||||
List<List<Token>> tokenLists = new List<List<Token>>();
|
||||
String[] files = Directory.GetFiles(path);
|
||||
Lexer lexer = new Lexer();
|
||||
Lexer.Lexer lexer = new Lexer.Lexer();
|
||||
|
||||
foreach (String filename in files)
|
||||
{
|
||||
StreamReader file = new StreamReader(filename);
|
||||
String contents = file.ReadToEnd();
|
||||
|
||||
|
||||
List<Token> tokens = lexer.Lex(contents);
|
||||
|
||||
tokenLists.Add(tokens);
|
||||
|
||||
Console.WriteLine("-----------" + filename + "-----------");
|
||||
foreach (Token token in tokens)
|
||||
{
|
||||
Console.WriteLine(token.ToString());
|
||||
}
|
||||
|
||||
Console.WriteLine("--------------------------------------");
|
||||
}
|
||||
|
||||
return tokenLists;
|
||||
}
|
||||
|
||||
static void TestParser(List<Token> tokenList)
|
||||
{
|
||||
Parser.Parser p = new Parser.Parser();
|
||||
|
||||
p.Parse(ref tokenList, NodeType.ProgramNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue