Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-05

Parser Generator

10 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Torsten Bonde Christiansen

Hi.

I am currently looking into integrating a custom language parser into my program and have been
searching the web for parser generators that can create Pascal code from a custom language.

So far in my search i have found the following "options":

* GOLD Parser: http://www.goldparser.org/
Was last updated in sept. 2012 and the lastest pascal implementation is not for the lastest version of the program!

* COCO/R: http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/ Same as with the GOLD parser - last updated in 2014 and lastest pascal implementation is for an older version of the program.

* TP Yacc/Lex: (included in Free Pascal)
Is included with Free Pascal, but the generated code is non-OO, and seems to rely on text-files for input.

So if there is anyone out there who knows of such a generator I would be glad to know.

Kind regards,
Torsten Bonde Christiansen.

leledumbo
to Torsten Bonde Christiansen
I am currently looking into integrating a custom language parser into my program and have been searching the web for parser generators that can create Pascal code from a custom language.

No parser generator that I know includes a code generator, you must write that part would write a handwritten transpiler instead, though. Easier maintenance and maximum flexibility, no rules or restrictions as imposed by every parser generator implementations. At the worst, I would pick Coco/R since it generates a recursive descent parser instead of table driven one, still possible for hand editing.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Parser-Generator-tp5725357p5725358.html Sent from the Free Pascal - General mailing list .
Marc Santhoff
to Torsten Bonde Christiansen: Hi. I am currently looking into integrating a custom language parser into my program and…
Torsten Bonde Christiansen wrote 14 lines
* GOLD Parser: http://www.goldparser.org/ Was last updated in sept. 2012 and the lastest pascal implementation is not for the lastest version of the program! * COCO/R: http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/ Same as with the GOLD parser - last updated in 2014 and lastest pascal implementation is for an older version of the program. * TP Yacc/Lex: (included in Free Pascal) Is included with Free Pascal, but the generated code is non-OO, and seems to rely on text-files for input. So if there is anyone out there who knows of such a generator I would be glad to know.

There is a german learning programm named AtoCC. It can generate Object Pascal Code:

http://www.atocc.de/cgi-bin/atocc/site.cgi?lang=en&site=main

Sorry, I had no time to test it yet.

Marc

Mark Morgan Lloyd
to Marc Santhoff
Marc Santhoff wrote 11 lines
On Do, 2016-05-19 at 13:10 +0200, Torsten Bonde Christiansen wrote: > * GOLD Parser: http://www.goldparser.org/ > * COCO/R: http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/ > * TP Yacc/Lex: (included in Free Pascal) http://www.atocc.de/cgi-bin/atocc/site.cgi?lang=en&site=main Sorry, I had no time to test it yet.

"For target code generation you need to specify code fragments for each rule in VCC."

I think the important thing for all of these is that they still assume a lot of hard work from the person defining the custom syntax. They're not a magic bullet.

For the last 30 years or so I've been using a compiler compiler originally written in 1964, the implementation has matured as different pascal compilers have become available. I'm not suggesting that this is usable in the general case, but looked at objectively it does allow me to make gross behavioural changes fairly easily, e.g. to define novel string properties and to embed pragmata in comments.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Carlo Kok
to Torsten Bonde Christiansen: Hi. I am currently looking into integrating a custom language parser into my program and…
Torsten Bonde Christiansen wrote 24 lines
Hi. I am currently looking into integrating a custom language parser into my program and have been searching the web for parser generators that can create Pascal code from a custom language. So far in my search i have found the following "options": * GOLD Parser: http://www.goldparser.org/ Was last updated in sept. 2012 and the lastest pascal implementation is not for the lastest version of the program! * COCO/R: http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/ Same as with the GOLD parser - last updated in 2014 and lastest pascal implementation is for an older version of the program. * TP Yacc/Lex: (included in Free Pascal) Is included with Free Pascal, but the generated code is non-OO, and seems to rely on text-files for input. So if there is anyone out there who knows of such a generator I would be glad to know.

It's been my experience that all the compiler compilers have one or more flaws that make it more work in the end to use them than to just write a parser by hand.

Carlo Kok
Marc Santhoff
to Mark Morgan Lloyd: "For target code generation you need to specify code fragments for each rule in VCC." I…
Mark Morgan Lloyd wrote 15 lines
Marc Santhoff wrote: > On Do, 2016-05-19 at 13:10 +0200, Torsten Bonde Christiansen wrote: > >> * GOLD Parser: http://www.goldparser.org/ >> * COCO/R: http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/ >> * TP Yacc/Lex: (included in Free Pascal) > http://www.atocc.de/cgi-bin/atocc/site.cgi?lang=en&site=main > > Sorry, I had no time to test it yet. "For target code generation you need to specify code fragments for each rule in VCC."

Örks. Didn't read that.

I think the important thing for all of these is that they still assume a lot of hard work from the person defining the custom syntax. They're not a magic bullet.

There are some tools I liked very much when dealing with language translation in the past, but they don't fit her. None of them generates Pascal Code out of the box.

ANTLR3 was my favourite, generating tree walkers with little extra work (iirc). But it generates Java code.

Show quoted text 6 lines
For the last 30 years or so I've been using a compiler compiler originally written in 1964, the implementation has matured as different pascal compilers have become available. I'm not suggesting that this is usable in the general case, but looked at objectively it does allow me to make gross behavioural changes fairly easily, e.g. to define novel string properties and to embed pragmata in comments.

Beautiful. Would you mind disclosing the name of that fine tool? ;)

Marc

Marc Santhoff
to Marc Santhoff
Marc Santhoff wrote
There are some tools I liked very much when dealing with language translation in the past, but they don't fit her. None of them generates

^e
"they don't fit here."

Fatal typo. I know Torsten is not a girls name.

Marc

Mark Morgan Lloyd
to Marc Santhoff: Örks. Didn't read that. There are some tools I liked very much when dealing with language
Marc Santhoff wrote 8 lines
> For the last 30 years or so I've been using a compiler compiler > originally written in 1964, the implementation has matured as different > pascal compilers have become available. I'm not suggesting that this is > usable in the general case, but looked at objectively it does allow me > to make gross behavioural changes fairly easily, e.g. to define novel > string properties and to embed pragmata in comments. Beautiful. Would you mind disclosing the name of that fine tool? ;)

Meta-II, by Val Schorre. Wikipedia has an adequate description, I first implemented it in the days of Pascal MT+ and since then have ported it to Turbo, Topspeed, Delphi and FPC. I'm not saying I've done a particularly good job, and will probably redo it for UTF16 (whatever the correct FPC type is for that) at some point- possibly adding support for Smalltalk-style keywords.

Obvious changes included saving more state to allow backtracking. Less obvious was parsing comments as part of the syntax (which allows things like XML and SNMP descriptions to be parsed), allowing string delimiters to be specified and keeping the string delimiter as a string property. Those last allow runtime behaviour of strings to vary depending on delimiter, so for example a string expression using / as delimiter can be used as a regex while a string lvalue using / as delimiter can be a backref into a pattern.

Schorre or his coworkers later defined something called Tree Meta which accumulates parsed source into a tree, and also has rules for how the tree can be manipulated and "unparsed". I don't believe that anybody's reimplemented it, but I'm occasionally tempted...

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Torsten Bonde Christiansen
to Carlo Kok: It's been my experience that all the compiler compilers have one or more flaws that make…
Carlo Kok wrote 31 lines
On 2016-05-19 13:10, Torsten Bonde Christiansen wrote: > Hi. > > I am currently looking into integrating a custom language parser into my > program and have been > searching the web for parser generators that can create Pascal code from > a custom language. > > So far in my search i have found the following "options": > > * GOLD Parser: http://www.goldparser.org/ > Was last updated in sept. 2012 and the lastest pascal implementation is > not for the lastest version of the program! > > * COCO/R: http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/ > Same as with the GOLD parser - last updated in 2014 and lastest pascal > implementation is for an older version of the program. > > * TP Yacc/Lex: (included in Free Pascal) > Is included with Free Pascal, but the generated code is non-OO, and > seems to rely on text-files for input. > > So if there is anyone out there who knows of such a generator I would be > glad to know. > It's been my experience that all the compiler compilers have one or more flaws that make it more work in the end to use them than to just write a parser by hand.

Previously I have worked with TP Lex/Yacc and it works fine with limitations it has. And yes, using a parser generator is not a magic wand that creates code to run without modification, but on most occations I find that the post-processing required with this approach is far less than writing my own parser.

kind regards,
Torsten Bonde Christiansen.