Precedences for conctypes

We consider again a user defined syntax feature, the conc-type, which is a new datatype construction. An embedded language can easily be introduced into a programming language using conctypes, and computations are easily expressed using the concrete syntax and a special pattern matching form. Context-free grammars serve as a basis for the definition of the new syntax. A problem that is investigated in this paper is how to use precedences to resolve ambiguity. The way precedences are used in LR-parsers is sometimes unnatural and is hard to translate to other parsing techniques. We isolate one kind of ambiguity which can be resolved with precedence rules and show that it is easy for a user to augment a grammar with precedence rules. We define the generated language for such a grammar in terms of an attribute grammar and show that it is easy to automatically construct a parser that recognizes the language. 1 Conctypes In a previous paper [APS88] we described a user defined syntax feature, the concrete datatypes or conctypes. A conctype is a new kind of datatype, the elements of which can have a flexible syntax. Elements of datatypes in most programming languages can usually only be written in a very restricted form. When such elements become large they soon become unreadable, and the user is often forced to write a parser which transforms a string to an element of the datatype. The strings can be seen as a concrete representation of the abstract syntax that the datatype defines. Elements of conc-types are much more readable since the programmer defines their concrete syntax. Let us compare two datatype definitions, an ordinary one and a conctype, and their elements. Both define a small functional language. All examples are written in LML [AJ87, AJ89]. First the ordinary version: type expr = Id String + NmII Int + App expr expr + f4ul expr expr Permission to copy without fee all or part of this material is granted provided thet the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of tha publication and ite date appear, and notica is given that copying ie by permission of the Association for Computing Machinery. To copy otharwiae, or to republish, raquiras a fee and/or specific permission.

[1]  Robin Milner,et al.  Principal type-schemes for functional programs , 1982, POPL '82.

[2]  J. Berstel,et al.  Context-free languages , 1993, SIGA.

[3]  John W. Backus,et al.  The syntax and semantics of the proposed international algebraic language of the Zurich ACM-GAMM Conference , 1959, IFIP Congress.

[4]  Annika Aasa,et al.  User Defined Syntax , 1992 .

[5]  Annika Aasa,et al.  Precedences in Specifications and Implementations of Programming Languages , 1991, Theor. Comput. Sci..

[6]  Roland Carl Backhouse,et al.  Syntax of Programming Languages: Theory and Practice , 1979 .

[7]  Thomas Johnsson,et al.  The Chalmers Lazy-ML Compiler , 1989, Computer/law journal.

[8]  Robin Milner,et al.  Definition of standard ML , 1990 .

[9]  Donald E. Knuth,et al.  backus normal form vs. Backus Naur form , 1964, CACM.

[10]  Annika Aasa,et al.  Concrete syntax for data objects in functional languages , 1988, LISP and Functional Programming.

[11]  John McCarthy,et al.  Recursive functions of symbolic expressions and their computation by machine, Part I , 1959, Commun. ACM.

[12]  Donald E. Knuth,et al.  On the Translation of Languages from Left to Right , 1965, Inf. Control..

[13]  David G. Cantor,et al.  On The Ambiguity Problem of Backus Systems , 1962, JACM.

[14]  Friedrich L. Bauer,et al.  Revised report on the algorithm language ALGOL 60 , 1963, CACM.

[15]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[16]  Robin Milner,et al.  A Theory of Type Polymorphism in Programming , 1978, J. Comput. Syst. Sci..

[17]  Alfred V. Aho,et al.  The Theory of Parsing, Translation, and Compiling , 1972 .

[18]  Alfred V. Aho,et al.  Deterministic parsing of ambiguous grammars , 1975, Commun. ACM.

[19]  Robert W. Floyd,et al.  On ambiguity in phrase structure languages , 1962, CACM.

[20]  Jay Earley,et al.  An efficient context-free parsing algorithm , 1970, Commun. ACM.