Parsing and compiling using Prolog
- 20 March 1987
- journal article
- Published by Association for Computing Machinery (ACM) in ACM Transactions on Programming Languages and Systems
- Vol. 9 (2) , 125-163
- https://doi.org/10.1145/22719.22946
Abstract
This paper presents the material needed for exposing the reader to the advantages of using Prolog as a language for describing succinctly most of the algorithms needed in prototyping and implementing compilers or producing tools that facilitate this task. The available published material on the subject describes one particular approach in implementing compilers using Prolog. It consists of coupling actions to recursive descent parsers to produce syntax-trees which are subsequently utilized in guiding the generation of assembly language code. Although this remains a worthwhile approach, there is a host of possibilities for Prolog usage in compiler construction. The primary aim of this paper is to demonstrate the use of Prolog in parsing and compiling. A second, but equally important, goal of this paper is to show that Prolog is a labor-saving tool in prototyping and implementing many non-numerical algorithms which arise in compiling, and whose description using Prolog is not available in the literature. The paper discusses the use of unification and nondeterminism in compiler writing as well as means to bypass these (costly) features when they are deemed unnecessary. Topics covered include bottom-up and top-down parsers, syntax-directed translation, grammar properties, parser generation, code generation, and optimizations. Newly proposed features that are useful in compiler construction are also discussed. A knowledge of Prolog is assumed.Keywords
This publication has 14 references indexed in Scilit:
- Describing Prolog by its interpretation and compilationCommunications of the ACM, 1985
- Automating control for logic programsThe Journal of Logic Programming, 1985
- Some global optimizations for a PROLOG compilerThe Journal of Logic Programming, 1985
- Parser generation and grammar manipulation using prolog's infinite treesThe Journal of Logic Programming, 1984
- Automatic Derivation of Code Generators from Machine DescriptionsACM Transactions on Programming Languages and Systems, 1980
- Evaluating and Improving Recursive Descent ParsersIEEE Transactions on Software Engineering, 1979
- Automatic error recovery for LR parsersCommunications of the ACM, 1978
- A technique for generating almost optimal Floyd-Evans productions for precedence grammarsCommunications of the ACM, 1970
- An efficient context-free parsing algorithmCommunications of the ACM, 1970
- On the relative efficiencies of context-free grammarCommunications of the ACM, 1965