Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Objectives To describe a language using Context - Free Grammar ( CFG ) To describe an Abstract Syntax Tree ( AST ) for a small
Objectives
To describe a language using ContextFree Grammar CFG
To describe an Abstract Syntax Tree AST for a small language.
To contrast an Abstract Syntax Tree from a Concrete Syntax Tree CST
To demonstrate how Abstract Syntax Trees can be used my compilers to identify and
describe syntactical errors.
Requirements:
Create a ContextFree Grammar
Consider the following operations from boolean relational operators:
Less Than Less Than or Equal
to
Greater than Greater Than or
Equal to
Equal to Not Equal
Using the following as a basis, create a contextfree grammar for the boolean
expressions.
S S S
S S S
S S S
S S S
S S S
S S S
S numerical negative infinity to positive infinity
Replace the s with your answer.
Create a Concrete Syntax Tree
Along with your solution from question add the following to include mathematical
operations in your CFG
S S S
S S S
S S S
S S S
S S
Use this CFG to create a concrete syntax tree for the following expression:
Convert to Abstract Syntax Tree
Using your Concrete Syntax Tree from question create an equivalent abstract syntax
tree.
Explain the error in terms of an AST
Consider the following boolean expression:
With the subtraction operation having no value to subtract from the this is a clear
syntax error.
Draw the Abstract Syntax Tree as far as you can, and stop when you can go no further.
Explain how this process of creating the AST demonstrates how it can leads to better
descriptions of syntax errors.
Abstract Syntax Tree
Explanation of error finding
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started