An EBNF-Parser

The file bnf.pl contains a Prolog-parser for the EBNF-notation used to present the concrete syntax in the version 0.99 Draft of the CASL summary.

parse(InFile,OutFile,Print) parses the contents of the file InFile and if successful prints the result in OutFile using the predicate Print.

The parser supports the notations (NT \cup T)+ ... (NT \cup T)+, NT T...T NT, NT ... (as a short form of NT ... NT) and NT* for repetition, where NT is the set of nonterminal- and T the set of terminal symbols. It also supports T/T and T/ for a choice between two terminal symbols and to denote an optional terminal symbol. Two successive newlines separate the grammar rules for one nonterminal.

The parser is intended to provide and easy and quick way to get a machine readable representation of the CASL concrete syntax grammar. It is not that good at debugging the grammar, because, if no parse is found, the parser returns just no, without an indication about the reasons that led to the rejection.

As an example, there are currently two pretty printers for the resulting grammar available. The predicate print/1 outputs the grammar in a form that can be again parsed by parse/3 (cf. result1). The predicate print1/1 generates a Prolog Definite Clause Grammar representation of the input grammar (cf. result2).

The parser is written in SWI-Prolog, which is free for non-commercial use. It does not seem to work with SICStus Prolog, because of the absence of the call meta-predicate.

Concrete Syntax

The file cfg.txt contains the grammar of the concrete syntax extracted from the Web-representation of the CASL 0.99 Draft Summary with minor modifications: Also, some minor corrections of the presentation of the concrete syntax were necessary, like adding quotes around a single occurrence of a dot or replacing ,.., by ,..., etc..

The results of the parsing are result1 and result2.


Contents

Hubert Baumeister
April 17, 1998