https://github.com/worksofliam/coolex
Basic lexer attempt
https://github.com/worksofliam/coolex
Last synced: about 1 year ago
JSON representation
Basic lexer attempt
- Host: GitHub
- URL: https://github.com/worksofliam/coolex
- Owner: worksofliam
- Created: 2017-12-31T18:12:09.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-08-22T13:24:48.000Z (almost 6 years ago)
- Last Synced: 2025-03-15T01:14:18.875Z (over 1 year ago)
- Language: C#
- Size: 40 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
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
```