- SignalDesk2 hr ago
Original Summary
Hello I created TypeScript libraries for creating lexers and parsers using regular expression and context free grammar. These libraries make it trivial to develop an entire front-end for a programming language interpreter or compiler. Slex Slex is a lexer / scanner generator for C-like languages. It is essentially a regular expression engine implementation with additional nice features for programming language projects. The first implementation compiled each rule into a tree which is tree-walked to determine if the next token can match. While it worked, it was slow since each rule had to be visited with the current input string, and failures lead to backtracking. To alleviate the issue, the library now supports compiling all rules to a single DFA. This improves scanning performance by up to 90% since every node in the DFA knows that token rules can be emitted at the given state. Sparse Sparse is a parser generator that allows developers to easily create LR(1) / LALR(1) parsers and parsing tables. Since it fully integrates with Slex, defining entire languages can be done with a set of DFA and CFG rules. It gives the user complete control over the created abstract syntax tree (AST) by deferring node construction when a CFG rule matches. It also offers a complete error handling API, making it easy to present syntax errors to the user. The initial version of the library only supported LR(1), but LALR(1) output is now supported using the brute force algorithm to merge similar states. Using LALR(1) yields a ~35% performance boost over LR(1) with the same input and the same grammar. Note that LALR(1) table generation takes longer since it has to generate LR(1) beforehand before merging similar states together. AI Disclosure DFA compilation and LALR(1) table generation were implemented with the help of Qwen3.8 27B running locally on another computer with OpenCode as the harness. Each repository contains its own AI disclosure. Tests were implemented to ensure output is identical between old and new implementations. The first implementations of the libraries were written by hand for a university project in Java and rewritten in TypeScript also by hand. Currently the new features are being used in my Minecraft compiler project without any issue.   submitted by   /u/d0pe-asaurus [link]   [comments]
- 情报分类:商业与市场研究
- 分类依据:内容涉及商业、投资或市场动态
- 信息来源:Reddit · SideProject
- 发布时间:2026/10/10 14:34:36
- No replies yet