using System.Collections.Generic;
public static void Main()
Scanner scanner = new Scanner();
List<Token> tokens = scanner.Scan("1.237.5 + 23.4 / 8.8 + x");
foreach (var token in tokens) {
Console.WriteLine(token);
ADDITION, SUBTRACTION, DIVISION, MULTIPLICATION
public Token(string lexeme, TokenType type) {
public override string ToString() {
return Lexeme + " as " + Type.ToString();
public List<Token> Scan(string ogcontent){
tokens = new List<Token>();
switch(content[current]){
case '+' : tokens.Add(new Token("+", TokenType.ADDITION)); break;
case '-' : tokens.Add(new Token("-", TokenType.SUBTRACTION)); break;
case '*' : tokens.Add(new Token("*", TokenType.MULTIPLICATION)); break;
case '/' : tokens.Add(new Token("/", TokenType.DIVISION)); break;
if(IsNumeric(content[current])) {
}else if (IsAlpha(content[current])) {
throw new ArgumentException("Unexpected character " + content[current]);
if(current == content.Length)
private void HandleNumber(){
bool hasfounddecimal = false;
if(current < content.Length-1 && IsNumeric(content[current+1]))
if(content[current] == '.' && !hasfounddecimal)
else if(content[current] == '.' && hasfounddecimal){
tokens.Add(new Token(content.Substring(start, current-start+1), TokenType.NUMBER));
private void HandleIdentifier(){
if(content[current] == 'x')
tokens.Add(new Token(content.Substring(start, current-start+1), TokenType.VARIABLE));
private bool IsNumeric(char c) {
if(c >= '0' && c <= '9' || c == '.')
private bool IsAlpha(char c) {