Recent

Author Topic: A language grammar parser and parse tree generator, similar to ANTLR.  (Read 1597 times)

ExSystem

  • New Member
  • *
  • Posts: 19
Hi,

Introducing a simple language grammar parser and parse tree generator with basic and essential features finished while still in developing:
https://github.com/exsystem/MyFormatter

Just started the project not long time ago, and only working on it in leisure time, So there is no fancy/hard parsing algorithms, but naive or easy understanding implementations. Now, I've just finished the last piece for the most essential features, so, it is still not for serious production purpose. At first, I just want to make a specific pascal language parser, then I changed my mind for implementing with user defined grammars and source code, something like ANTLR, though mine is native executable without any dependencies :) Since just pure plain pascal is used, easily passed the test on some different platforms ranges from PowerPC MacOS X to modern M1 MacOS, Windows 3.x to Windows 11  :D

I am implementing this in a hurry, and initially want to make a code formatter based on generating a parse tree first, so I randomly choosed the project name 'MyFormatter', maybe thinking about an appropriate name later.

How to have a try: Just git clone the repo, compile the project using Lazarus, and run the program. Follow the prompts to give the grammar file name (eg: pascal.xg) and the source code (eg: test.pp) file name, and the parse tree will be printed out. You will notice that the grammar file format is quite similar to ANTLR's.

After basic functionalities finished, I will refactor my code, maybe using some advanced algorithms for the parser and the lexer, and add some grammar syntax, such as 'fragment', comment, and so on.

Thaddy

  • Hero Member
  • *****
  • Posts: 18666
  • Jungle wars. And failing health it seems.
Why? It is already incuded.....
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
@Thaddy
Presumably ExSystem wants to improve on the shortcomings of the Pascal formatters already available.

Sometimes it is easier to write your own code to achieve a task rather than try to understand someone else's code and debug and extend their work. For instance, the existing code design may not allow for easy incorporation of newer syntax introduced long after the basic formatter code was written.


Code maintainability, code extensibility, and code readability are all factors that need to be weighed in addresing existing formatting code that falls over when it encounters something now valid but unexpected in terms of the syntax prevailing at the time the formatter was first written.
« Last Edit: May 05, 2023, 09:09:00 am by howardpc »

 

TinyPortal © 2005-2018