60 lines
1.2 KiB
C#
60 lines
1.2 KiB
C#
using System;
|
|
using lexer.match;
|
|
using lexer.buffer;
|
|
namespace lexer
|
|
{
|
|
public class MainClass
|
|
{
|
|
|
|
public static void Main(String[] args)
|
|
{
|
|
Grammar grammar = new Grammar();
|
|
grammar.Load("fundamentals.xml");
|
|
grammar.Load("TestGrammar.xml");
|
|
|
|
|
|
Sequence num = grammar.getSequence("number");
|
|
|
|
String[] tests = new string[]{
|
|
"32",
|
|
"032",
|
|
"-189463738.34gdts"
|
|
};
|
|
|
|
Console.WriteLine("Number Defintion: {0}",num.ToString());
|
|
|
|
foreach (string l in tests){
|
|
Console.WriteLine("Matching {0}",l);
|
|
MatchedPart[] mp = num.Match(new CharacterBuffer(l));
|
|
if (mp == null){
|
|
Console.WriteLine("Did not Match!");
|
|
} else {
|
|
Console.WriteLine("Matched: {0}",mp.MatchingCharacters().AsString());
|
|
}
|
|
}
|
|
|
|
Console.WriteLine("------------------------------------");
|
|
|
|
String testsource = @"1
|
|
2
|
|
""Hallo Welt""
|
|
3
|
|
15.4
|
|
13.765
|
|
-3
|
|
-14.3
|
|
123456.7890
|
|
IchBinEinSymbol";
|
|
|
|
|
|
Sequence testseq = grammar.getSequence("numbersandstrings");
|
|
MatchedPart[] testmp = testseq.MatchNoticeable(new CharacterBuffer(testsource));
|
|
testmp.Notice( (matchedPart) => Console.WriteLine("Found {0:-10} = {1}",matchedPart.Matchable.Name,matchedPart.MatchedString) );
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|