An attribute grammar with common attributes and its evaluator in prolog

Attribute grammars (AGs) have been championed in the literature as a potential basis for language-analysis systems. However, there is a well-known copy rule problem, that is, 50–70 percent of semantic rules within an AG are copy rules. In this paper, we introduce common attributes into AGs. Common attributes provide a solution to the copy rule problem, reducing copy rules to only about 10 percent. The semantics of common attributes are defined by translating them into synthesized attributes and inherited attributes. The value of these derived attributes are copied from left to right if not defined explicitly. Based on the extended attribute grammar, we have developed a specification language, named PANDA. A prototype system has been constructed to generate Prolog programs from PANDA programs automatically. Our current system is limited to process PANDA programs which belong to L-attribute grammar (L-AGs), a subclass of AGs. For a givn grammar G, a necessary and sufficient condition is used to determine whether or not G is an L-AG. Some optimization strategies are applied to generate faster-running Prolog programs.