



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to the principles of programming languages, focusing on grammar and building parse trees. It explains the concept of a grammar as a formalism that describes valid sequences of terminals in a programming language. The document also covers context-free grammars, backus naur form (bnf), and recursive rules. Additionally, it discusses left and right recursive grammars and their implications on evaluation and associativity.
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Acknowledgement: Some of the material in these lectures are base d on material by Prof. Diane Horton & Prof. Anthony Bonner
e.g ::= a | b |
The order of recursion has implications on the order ofThe order of recursion has implications on the order of evaluation and associativity.evaluation and associativity.
< assign > : : = < identifier > = < expression > < identifier > : : = A|B|C < expression > : : = < expression > + < expression > | < expression > - < expression > | ( < expression > ) | < identifier >
< assign > : : = < identifier > = < expression > < identifier > : : = A|B|C < expression > : : = < expression > + < expression > | < expression > - < expression > | ( < expression > ) | < identifier > Yes, because the sentence A = B - C - A has two different parse trees The grammar does not force "normal" left-to-right evaluation of addition and subtraction.
The multiply operation is also associative.
Therefore one might say the previous ambiguous grammar would be satisfactory for addition and multiplication.
But would it? Computer arithmetic is not exact, and one might want be able to control the order …
< assign > : : = < identifier > = < expression > < identifier > : : = A|B|C < expression > : : = < expression > + < term > | < expression > - < term > | < term > < term > : : = < term >*< factor > | < factor > < factor > : : = ( < expression > ) | < identifier >
Tree for A = B + C * A