https://github.com/grz0zrg/jsb
fast lexical analyser
https://github.com/grz0zrg/jsb
Last synced: 3 months ago
JSON representation
fast lexical analyser
- Host: GitHub
- URL: https://github.com/grz0zrg/jsb
- Owner: grz0zrg
- Created: 2017-10-28T20:05:46.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-28T20:08:28.000Z (over 7 years ago)
- Last Synced: 2025-01-29T12:28:35.559Z (5 months ago)
- Language: JavaScript
- Size: 37.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
JSB
=========### fast lexical analyser ###
Fast lexical analyser done for fun, this take a JSON lexical grammar as input, produce a finite state automaton data structure which can be used to do fast lexical analysis of a string input.
The original goal was to do the simplest & fastest lexical analyser.
The JSON lexical grammar is made of a "token" array containing a list of tokens and a "syntax" object containing regular expression rules with associated token identifier (the position of the token in the "token" array), rules can contain sub-rules.
You can find grammar examples for C and Pure Basic in the "json" folder.
The demo let you load the examples and/or change source-code/grammar and see the complete ouput of the lexer along with benchmarking result.
The REGEX system is custom and does not use any libraries.
How to use :
`var lexer = new JSB.Lexer(json_lexical_grammar); // build the finite state automaton`
`var result = lexer.perform(string_to_analyse); // use it`
**result** will contain an array of lexeme objects which will contain **value**, **token**, **line**, **column** properties
All the lexer code is contained in the **lexer.js** file.
### License ###
Do what you want.