using System.Collections.Generic;
public class ExpressionParser {
public readonly string Text;
public readonly int Line;
public readonly int Column;
private List<Node> children;
public Node(Symbol token, string text, int line, int column) {
this.children = new List<Node>();
public ExpressionParser.Symbol Symbol {
public static IEnumerable<Node> tokenize(System.IO.StreamReader src)
System.Text.StringBuilder lexeme = new System.Text.StringBuilder();
Symbol token = Symbol.WS;
while (!src.EndOfStream) {
char cur = (char)src.Peek();
} else if (char.IsLetter(cur) || cur == '_') {
yield return new Node(token, lexeme.ToString(), line, column);
yield return new Node(token, lexeme.ToString(), line, column);
yield return new Node(token, lexeme.ToString(), line, column);
yield return new Node(token, lexeme.ToString(), line, column);
if (token != Symbol.WS) {
yield return new Node(token, lexeme.ToString(), line, column);
public static void Main(string[] args){
string testText = "3.14*";
stream = new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes(testText));
foreach (Node n in tokenize(new System.IO.StreamReader(stream))){
Console.WriteLine($"{n.Token,-15}\t{n.Text}");
Console.WriteLine(e.Message);