[fpc-pascal] Parser Generator

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Fri May 20 11:19:44 CEST 2016


Marc Santhoff wrote:

>> 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]



More information about the fpc-pascal mailing list