jastrachan | 6 Apr 12:59 2004
Picon

Re: Extensible parser.

On 6 Apr 2004, at 10:49, Chris Poirier wrote:
> Hi Neil,
>
>> use grammar SQL;
>>
>> I haven't seen this in another language; are there examples of this
>> around? There must be some major drawbacks otherwise this would have 
>> been
>> done elsewhere wouldn't it?
>
> Don't know.  It's been on my list of things to do for most of a decade.
> :-)

:)

> It certainly complicates writing the parser for the framework
> language, and you still have to write the parser/ast builder/class
> library for the DSL.  The primary reason it hasn't been done, I think,
> is that languages don't tend to well share object models.  The way
> to solve that is to build a machine-level object model, which we
> just happen to already have.
>
>
>> One thought that occured is that you could simply use bracketed areas 
>> for
>> the different grammar.
>>
>> myName= "";
>>
>> grammar SQL {
>>   SELECT * FROM employee WHERE employee.name = myName
>> }
>
> I've been thinking that something like this would fit into java/groovy
> nicely:
>
>
> language( sql )
> {
>    SELECT * FROM employee WHERE employee.name = myName;
> }

Incidentally Xen/X#/Omega is worth a look - they've just about included 
core SQL syntax into a C#-like language.

results = select * from foo where x > 123
for (y in results) {
     ...
}

> language( pop3 )
> {
>     CONNECT TO $server, $port
>
>     USER $name
>     PASS $password
>     RETR 1 => $message
>     QUIT
> }
>
>
> database = ...
> language( prolog )
> {
>     set database = $database.
>
>     big( elephant ).
>     big( house ).
>     small( mouse ).
>
>     grey( elephant ).
>     brown( house ).
>     grey( mouse ).
>
>     light( Z ) :- grey( Z ).
>
>     $answers <= light( X ), big( X ).
> }
>
> println "all things big and light in colour:"
> $answers.each { println it }

Neat! :)

I can imagine bob liking the above for writing drools without angle 
brackets :)

James
-------
http://radio.weblogs.com/0112098/

Gmane