I’ve pulled all the Antlr parse tree editing routines into its own library yesterday. This library fills a gap between what is offered in the Antlr runtime (a psuedo XPath library, AddChild and Parent accessors for ParserRuleContext), and a full-blown transformation system like ASF+SDF. This library contains: a beefed-up XPath version 2 library; a tree …
Author Archives: kaby76
A command-line approach to transforms of Antlr grammars
This is just a note to myself regarding some ideas on a command-line tool for Antlr grammars. It should be clear to anyone: grammars, especially Antlr grammars, are first-class objects that can be manipulated and changed to improve readability or performance. Antlrvsix now incorporates almost two dozen transformations, ranging from unfold, fold, sort rules, remove …
Continue reading “A command-line approach to transforms of Antlr grammars”
Adding text editor highlighting rules in a dynamic manner
This is a note of an idea I posted in two Twitter threads (here, here, and here). I think it’s important to capture the idea before it gets lost when blogs and Twitter disappear. The problem with “semantic highlighting”, or what I would just call syntactic highlighting because there are really many levels of highlighting …
Continue reading “Adding text editor highlighting rules in a dynamic manner”
Tree transformations via XPath and S-expressions
I’ve finally have the right tools to now implement transforms over an Antlr parse tree. The first part of a transform is identifying what nodes in the tree that are going to be replaced. It turns out that the best tool to do that is an XPath engine, which I’ve rewritten in C# from Java …
Continue reading “Tree transformations via XPath and S-expressions”
Converting Bison precedence and associativity rules to Antlr
As noted in the Bison guide: The associativity of an operator op determines how repeated uses of the operator nest: whether â€x op y op z’ is parsed by grouping x with y first or by grouping y with z first. %left specifies left-associativity (grouping x with y first) and %right specifies right-associativity (grouping y with z first). %nonassoc specifies no associativity, which means that â€x op y op z’ is considered a syntax error.%precedence gives only precedence to the symbols, and defines no associativity at all. Use this …
Continue reading “Converting Bison precedence and associativity rules to Antlr”
Finding direct left recursion in an Antlr grammar via XPath
“//parserRuleSpec[RULE_REF/text() = ruleBlock/ruleAltList/labeledAlt/alternative/[name()=’element’][1]/atom/ruleref/[1]/text()]” This XPath expression is the first important rule I wrote for Antlr grammars, which finds all rules that have direct left recursion. Finding direct left recursion is an important step for removing indirect left recursion. My efforts for getting XPath working with Antlr are starting to finally pay off. –Ken
XPath 3.1 engine with Antlr parse trees — Update
It’s taken a few weeks, but the daily grind has resulted in a new grammar in Antlr for XPath version 3.1, and a translation of the Eclipse engine to search the Antlr parse trees (code). This will come in handy to partially replace the hardwired code in C# in Antlrvsix to perform grammar refactorings. There …
Continue reading “XPath 3.1 engine with Antlr parse trees — Update”
XPath and Piggy
I’ve made another release of Antlrvsix, version 7.3, last week and I’m almost ready to release 7.4 with a few more fixes. The changes I’ve been making since last year in August have greatly enhanced what Antlrvsix can do over version 1. But, there is more work to be done. I’m now working on updating …
The next step
What is the next step in Antlrvsix to help improve a grammar? To answer that, I decided to go back and take a look at where this all began, with the comparison of the Java grammars in Antlr. Java9 is derived from version 9 of the Java spec. Parr’s Java is derived from an unknown, …
Version 7 of Antlrvsix released
I’ve made a release of Antlrvsix yesterday which includes recursion removal for Antlr grammars. There are two types of recursion that I can work with: direct (aka immediate) and indirect. The algorithm that I use for direct and indirect recursion removal are the ones that Aho et al. (2006) describe. In addition, the extension provides …