Introduction to Syntax/Exercise 1: Difference between revisions
From Wiki**3
< Introduction to Syntax
No edit summary |
|||
Line 13: | Line 13: | ||
== Solution == | == Solution == | ||
The terminal symbols are all the symbols not defined by a rule: '''<tt>or</tt>''', '''<tt>and</tt>''', '''<tt>not</tt>''', '''<tt>(</tt>''', '''<tt>)</tt>''', '''<tt>true</tt>''', '''<tt>false</tt>'''. | |||
[[category:Compilers]] | [[category:Compilers]] | ||
[[category:Teaching]] | [[category:Teaching]] |
Revision as of 11:48, 11 April 2008
The Problem
Consider the following grammar:
bexpr -> bexpr or bexpr | bterm bterm -> bterm and bterm | bfactor bfactor -> not bfactor | ( bexpr ) | true | false
- Identify the terminal and non-terminal symbols of the grammar.
- Show that the grammar is ambiguous by deriving two different trees for the same input sequence.
- Write a non-ambiguous grammar for the same language.
- Build the tree corresponding to the analysis of the following input sequence: not ( true or false and true )
Solution
The terminal symbols are all the symbols not defined by a rule: or, and, not, (, ), true, false.