Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Modular grammars and parsing?

0 views
Skip to first unread message

Charles Lakos

unread,
Jan 3, 1992, 9:19:16 PM1/3/92
to
I wish to write a parser to handle an imperative language in a modularised
way. It should reflect three distinct sub-grammars - the statements, the
declarations and the expressions. The "statements" part should "call" the
"declarations" and the "expressions" parts.

The reason for this desire is to be able to cater for different variants
of the language with, say, different forms of expressions. Also, I wish
to use the expressions grammar with a simplified intermediate form of the
language.

I can obviously do the above with a top-down recursive parser, but I was
hoping to be able to do it by modifying an existing yacc + lex (flex)
grammar. Can anyone suggest how it might be done?
--
Charles Lakos. C.A....@cs.utas.edu.au
Computer Science Department, cha...@probitas.cs.utas.edu.au
University of Tasmania, Phone: +61 02 20 2959
Australia. Fax: +61 02 20 2913
--
Send compilers articles to comp...@iecc.cambridge.ma.us or
{ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.

Jan Rekers

unread,
Jan 7, 1992, 6:03:30 AM1/7/92
to

In article <92-0...@comp.compilers>, cha...@probitas.cs.utas.edu.au

(Charles Lakos) writes:
|> I wish to write a parser to handle an imperative language in a modularised
|> way. It should reflect three distinct sub-grammars - the statements, the
|> declarations and the expressions. The "statements" part should "call" the
|> "declarations" and the "expressions" parts.
|>
|> I can obviously do the above with a top-down recursive parser, but I was
|> hoping to be able to do it by modifying an existing yacc + lex (flex)
|> grammar. Can anyone suggest how it might be done?

I cannot help you with a clean-cut yacc + lex solution, but you might be
interested in a paper I wrote on parser generation for modular grammars.

I have implemented the syntax definition formalism SDF in which the
grammar can be subdivided in different modules which may import each
other. There is no limmitation on the import graph, except that it may not
be cyclic. It is allowed to define rules for one non-terminal in different
modules. It is possible to select any module and to parse according to the
rules valid in that module and the modules it imports. The implementation
is in LISP and part of the centaur system.

The paper is just sent in for publication, so I do not have an easy
reference. If you are interested in this technique, please drop me a note
with your surface address.

Jan Rekers (Jan.R...@cwi.nl) Centrum voor Wiskunde en Informatica (CWI)
P.O. Box 4079, 1009 AB Amsterdam, The Netherlands

0 new messages