An open API service indexing awesome lists of open source software.

https://github.com/worksofliam/coolex

Basic lexer attempt
https://github.com/worksofliam/coolex

Last synced: about 1 year ago
JSON representation

Basic lexer attempt

Awesome Lists containing this project

README

          

# Coolex

Coolex will generate two C# classes for you to copy in to your project.

## Usage

1. Language definition (`test.txt`)

```
OPERATORS: "+", "-", "/", "*"

NUMERIC_LITERAL: "/[-0-9]+/"
PLUS: "+"
MINUS: "-"
DIVIDE: "/"
MULTIPLY: "*"
```

2. Calling `coolex.exe`

```
.\coolex test.txt
Notice:: Generating enum Type:
: UNKNOWN
: OPERATOR
: STRING_LITERAL
: NUMERIC_LITERAL
: PLUS
: MINUS
: DIVIDE
: MULTIPLY
Notice: Writing file: test.txt.cs
```

3. Copy class into `namespace` in C# project
4. Invoke the generated class:

```
//ConsoleApp1 main
CoolexLex lexer = new CoolexLex();

lexer.Lex("1324 + 1 / 12 * 6 - 5 + 10");

foreach (var Token in lexer.TokenList)
{
Console.WriteLine(Token.Type.ToString() + " " + Token.Value);
}
```

```
.\ConsoleApp1.exe
NUMERIC_LITERAL 1324
PLUS +
NUMERIC_LITERAL 1
DIVIDE /
NUMERIC_LITERAL 12
MULTIPLY *
NUMERIC_LITERAL 6
MINUS -
NUMERIC_LITERAL 5
PLUS +
NUMERIC_LITERAL 10
```