repl.it
@YoyoGuy/

LexerTest

C#

No description

fork
loading
Files
  • main.cs
  • Lex.cs
  • main.exe
  • outputs.pkg
  • ParsingExample.cs
  • Test.txt
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using Example;

class MainClass {

  // print('hi!');
  static object Test(string inp) {
    Console.WriteLine(inp);
    return null;
  }

  // Wait('????');
  static object Slep(string inp) {
    try {
    System.Threading.Thread.Sleep(int.Parse(inp));
    }
    catch (FormatException) {
      Console.WriteLine("Error: Input Must be in the format of a number, Program Terminated");
      Environment.Exit(1);
    } 
    return null;
  }

  // Exit('0');
  static object noret(string inp) {
    try {
      Environment.Exit(int.Parse(inp));
    }
    catch (FormatException) {
      Console.WriteLine("Error: Input Must be in the format of a number, Program Terminated");
      Environment.Exit(1);
    }

    return null;
  }

  // CErr('???');
  static object CErr(string inp) {
    throw new Exception(inp);
  }

  public static void Main (string[] args) {
    CFunction.Funcs.Add(new CFunction("print", Test));

    CFunction.Funcs.Add(new CFunction("CErr", CErr));

    CFunction.Funcs.Add(new CFunction("Wait", Slep));
  
    CFunction.Funcs.Add(new CFunction("Exit", noret));

    // Operators in strings are not supported yet

    Parser.Parse("var true = 'true'; var false = 'false';");

    Parser.File("Test.txt");
  }
}
Fetching token
?