Parser generator for Delphi? - delphi

Can anyone recommend a parser generator that will produce win32 Delphi code? What I'm trying to do is create a simple Domain-Specific Language.

How complex is your DSL?
I created a parser (in Delphi) for the new Delphi RIDL language to support some in-house COM generation tools we use.
My approach was to use ANTLR to play around with the syntax rules until I had something that parsed the various test files I had. I then hand-coded a recursive descent parser (based on the Java generated by ANTLR). I was also using the Castalia Delphi Parser in the project, so I based my lexical analyser on that.
Recursive descent parsers are actually really simple (but tedious :-) ) to write manually.

The Delphi versions of Coco/R are quite ok:
http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/
most notably Pat Terry's one:
http://www.scifac.ru.ac.za/coco/

Try this:
http://www.grendelproject.nl/dyacclex/

I have not tried this at all and I just noticed the information while I was reading through the documentation, but FastScript, in their documentation which you can get here, says that you can use their parser to create your own language which you specify in an XML file. This might give you something you can use.

I found Antlr For Delphi 3.1.1.
SharpPlus Antlr For Delphi Target
3.1.1, a language tool that provides a framework for constructing
recognizers, interpreters, compilers
with Delphi!
It is a commercial product. I have no idea what it is like.

Related

Autocomplete punctuation using grammar

I'm working on a tool that is able to autocomplete the necessary literals defined in a grammar. For example: in C# if a programmer enters: for with a space after it, then it's entirely possible to parse the code, determine that the programmer has started a for statement and autocomplete the necessary punctuation: ( ; ; ).
The more I think about the problem, the more I think there must already be a solution for it, because it's such a common use case, but I can't find anything.
Is there a tool that can do this using a given grammar?
If you don't mind using ANTLR v3 instead of v4 you can use Xtext in order to generate an editor that features auto-complete and error-highlighting. This will happen in form of a plugin for eclipse and apparently also for IntelliJ IDEA.
If you want to use a different IDE or simply want to make use of ANTLR v4's powerfull features you could still have a look at the Xtext Sources as they have to do what you are searching for in order to provide the above mentioned features properly...
This package looks very promising at first glance... You might find the respective code in there.
Be aware though that Xtext is mainly written with Xtend so you either have to do so as well or you have to rewrite it a bit

Can I use ANTLR on C++ on XCode?

I am wondering if I can use ANTLR on C++ on Xcode? If not, are there any alternatives?
I need production quality of the 3rd party libraries.
Also see: Integrating ANTLR 4 in a C++ application
ANTLR3 has a C target which you can use in a C++ project, albeit with a bit of hacking (no personal experience with that, I base it by reading the answers there).
If not, are there any alternatives?
Sure, it's even been asked before: C++ parser generator which links to the Wiki list of parser generators, and of course, there's Google that has more than one suggestion.

Multiple language parser generator

Is there a parser generator that can take a single grammar and create a parser in both c# and javascript?
I've tried using ANTLR, but I have yet to get it into Visual Studio (lackluster/outdated documentation and packages).
The end goal is that I can manage a single grammar (for a subset of SQL; specifically select statements and a few new keywords specific to my problem domain) but generate two parsers (c#/javascript).
Any help is much appreciated.
Is there a parser generator that can take a single grammar and create a parser in both c# and javascript?
The only one I am aware of is ANTLR. Note that ANTLR will not generate both a JavaScript- and C# based parser in one go though. You will have to change (at least) one option in the grammar and invoke org.antlr.Tool to generate a parser for your other target language.
I've tried using ANTLR, but I have yet to get it into Visual Studio
Then don't use Visual Studio, but use your favorite text editor (and use org.antlr.Tool from the console), or ANTLRWorks.
There's canopy, which targets javascript, ruby, java, and python from PEG
My AGL parser builder is written in Kotlin common, so it can be used on any Kotlin target (JVM, JavaScript, native code, etc).
https://medium.com/#dr.david.h.akehurst/a-kotlin-multi-platform-parser-usable-from-a-jvm-or-javascript-59e870832a79
Unfortunately, Kotlin does not yet target .net....but maybe it will come in the future.
docopt let you describe your help message in a string respecting some common convention and that's how all commands, options and arguments will be defined.
Docopt has many official implementations: python, bash, C#, rust, ruby, C++, Go, R, Julia, Nim, Hashkell, PHP, C, F#, CoffeeScript, Swift, Scala, D, Java, Clojure, Tcl, Lua

Can Coco/R turn a parsed file into bytecode?

I want to write a simple compiler for educational purposes in Delphi. I have read about Coco/R and found this implementation for Delphi: http://code.google.com/p/dcocor/ . From what I have read, this is a parser for the Delphi 2009 syntax.
What would I have to do to turn the parsed file into a bytecode? Can Coco/R do this?
I know about scripting languages like FastScript or DWS, but I'd like to try and write my own for my own purposes.
Please give me some advice or clarify things a little.
What would I have to do to turn the parsed file into a bytecode?
First, decide what kind of bytecode would you like to have: JVM? LLVM? MSIL? Inventing your own?
Can Coco/R do this?
Coco/R is a parser generator framework, it only generates lexer-parser for a language you define and feed to the generator. Steps after that is your responsibility. Though there might be projects out there that can help generating ast/target code (but I haven't found any for Coco/R ).

llvm-clang: incremental or online parser?

Is there anyway to use the llvm-clang parser in an incremental/online manner?
Say I'm writing an editor and I want to be able to parse the C++ code I have in front of me.
I don't want to write my own hacked up parser.
I'd like to use something full featured, like llvm-clang.
Is there an easy way to hijack the llvm-clang parser? (And is it fast enough to run it continuously in the background)?
Thanks!
I don't think clang can incrementally parse C++ files, but it's one of this project goals: http://clang.llvm.org/features.html
I've written something similar for my final year project. It wasn't C++ editor, but a Visual Studio plugin, which main task was improving C++ intellisense (like Visual Assist X).
When I was writing this project I've been also thinking about C++ incremental parser, but I haven't found any suitable solution. To solve the C++ intellisense problem I used normal C++ parser from GCC. However it was to slow, to parse file after each code completion request (ctrl+space), just try including boost::spirit. To make this project work properly I parsed files in the background and after each code completion request I compared current file with it's previous version (via diff) to detect changes made from last parsing. Having those changes I updated syntax tree, mostly by adding or removing variables.
Except incremental parsing, there is also another problem with projects like this. Mostly you'll be parsing C++ code which is being edited so it's invalid code. Given the complex C++ grammar, sometimes parser won't be able to recover from syntax errors, so it won't detect correctly some symbols in code.
Another issue are C++ parsers / compilers differences. Let's say I'm using working in Visual Studio and I have used some VC++ compiler specific contruction in my code. Clang parser won't be able to parse it correctly.
For writing something similair to IntelliSense, I would advise you to write your own parser using the LALR parsing algorithm. Since you can save its state in each line so you don't have to reparse the whole file when a file has been editted, which is very fast!
Note that C++ can't be fully expressed in BNF, but I think you could get pretty far with some adjustments. It's ofcourse a lot more work than using Clang's frontend, but you could still use Clang for analysing header files in coöperation with you own written parser.

Resources