CS 331 Assignment 1: Analyzing Grammars for CS 331, Spring 2019
VerifiedAdded on 2023/04/21
|6
|1081
|79
Homework Assignment
AI Summary
This document presents the solutions to Assignment 1 for CS 331, a course in theoretical computer science. The assignment focuses on grammar analysis, specifically exploring ambiguous grammars, context-free grammars, BNF (Backus-Naur Form), and EBNF (Extended Backus-Naur Form). The solution analyzes a given ambiguous grammar, demonstrating leftmost and rightmost derivations. It also addresses the construction of a BNF grammar for strings with an odd number of 'a's and 'b's. Furthermore, the assignment explores the application of EBNF in defining grammar functions and methods, including the declaration of methods, access modifiers, return types, and parameter passing. The document provides a comprehensive understanding of grammar concepts relevant to computer science, including the use of terminals, non-terminals, and production rules.

Programming
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Table of Contents
4 (a) Question.............................................................................................................................1
Question 6..................................................................................................................................3
Question 7..................................................................................................................................3
4 (a) Question.............................................................................................................................1
Question 6..................................................................................................................................3
Question 7..................................................................................................................................3

4 (a) Question
The ambiguous grammar can be used for the context free grammar that can be
performed on the string, which can derive the process in two steps, where it can
include the leftmost derivation or the parse tree.
The given equation is,
It is possible to consider the terminal and non-terminal ambiguous variable { x, y, a, b, o, i }.
To find the parse tree, the following is used,
The left associative process is the production of left recursive function and the
right associative process can be considered for the production of the right
recursive function.
The ambiguous grammar is the semantic action, which can be used for adding
the parsers and displays the result on the arithmetic operation.
1
The ambiguous grammar can be used for the context free grammar that can be
performed on the string, which can derive the process in two steps, where it can
include the leftmost derivation or the parse tree.
The given equation is,
It is possible to consider the terminal and non-terminal ambiguous variable { x, y, a, b, o, i }.
To find the parse tree, the following is used,
The left associative process is the production of left recursive function and the
right associative process can be considered for the production of the right
recursive function.
The ambiguous grammar is the semantic action, which can be used for adding
the parsers and displays the result on the arithmetic operation.
1
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

This can be performed on the semantic action, where the expression can be
changed. The imaging of the parse tree can be used for relating the parsed
program.
The ambiguous grammar can be accessed on the possible parses of the strings.
The natural language processing can be used for the parse tree, which can
access each operator on the tree strings.
For example, the ambiguous string from {x, y, a, b, o, i} can enter the string
on the variable. First, consider the ambiguous variable on the following equation,
<s> ::=<ab> <xy> | <o>
A language S is called the BNF Grammar language.
The ambiguous grammar can be used for affecting the ambiguous steps at the same
time for finding the parsing complexity.
Thus, the given grammar is an ambiguous function.
The b string can be the production of the process in X and y, and this function is
also an ambiguous function<s> ::=<ab> <xy> | <o>, because it is available on the
grammar language, which can be used for the two different left most and right most
derivations.
The parser tree of <ab> can be performed on the left most and the right most
derivations. To find the context free language of the given languages, the
performance can be found and all the strings on the given language can be
accessed.
The left most derivation of S can be split into string on <ab> and <xy>, which can
be matched with <ab> b| a b and x <xy> y| a<i> y, respectively. Thus, the given
grammar is an ambiguous function.
The leftmost derivation part includes,
S a <ab> b| x <xy> y
The right most derivation can be used for the strings as,
s s|<o>|a <o> y |a<i> y| b x
i bx
Hence, the given grammar is ambiguous.
2
changed. The imaging of the parse tree can be used for relating the parsed
program.
The ambiguous grammar can be accessed on the possible parses of the strings.
The natural language processing can be used for the parse tree, which can
access each operator on the tree strings.
For example, the ambiguous string from {x, y, a, b, o, i} can enter the string
on the variable. First, consider the ambiguous variable on the following equation,
<s> ::=<ab> <xy> | <o>
A language S is called the BNF Grammar language.
The ambiguous grammar can be used for affecting the ambiguous steps at the same
time for finding the parsing complexity.
Thus, the given grammar is an ambiguous function.
The b string can be the production of the process in X and y, and this function is
also an ambiguous function<s> ::=<ab> <xy> | <o>, because it is available on the
grammar language, which can be used for the two different left most and right most
derivations.
The parser tree of <ab> can be performed on the left most and the right most
derivations. To find the context free language of the given languages, the
performance can be found and all the strings on the given language can be
accessed.
The left most derivation of S can be split into string on <ab> and <xy>, which can
be matched with <ab> b| a b and x <xy> y| a<i> y, respectively. Thus, the given
grammar is an ambiguous function.
The leftmost derivation part includes,
S a <ab> b| x <xy> y
The right most derivation can be used for the strings as,
s s|<o>|a <o> y |a<i> y| b x
i bx
Hence, the given grammar is ambiguous.
2
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

Question 6
The BNF grammar can consider all the strings with the total number of
occurrence of a and b’s character set= {a, b}. The BNF grammar consists of 4 parts,
set of start symbols, set of non-terminal symbols, tokens and productions.
assume the non-terminal symbol is S
The BNF grammer of the set of ALL strings can be consider the equation are, L(G)
is({S,A,B,∈}
SAB
AaA/a
BbB/b
A∈
B∈
We can find the strings on the total number of a’s and b’s is odd number.
Sab
SaAbB
SaAbBa∈b∈ab
We can apply the context free production is A∈ and B∈
∈ Can be denoted as empty strings.
The starting symbol is S. The total number of occurrence of a and b calculated is denoted
with S symbol.
Eliminate the unwanted terms p x and y and I on the BNF grammar,
After that delimiting and calculating the number of occurrence that can be remove the
number terms
The BNF grammar can be specified as the Brackets <S> can be used for starting the
terms. The BNF grammar can the non-terminal interpretation which can find the total
number of occurrence of a and b is odd of the string is ‘a’, ’b’,’ ab’, empty string is
odd.
Question 7
EBNF can be used for declaring the function of the grammar language.
3
The BNF grammar can consider all the strings with the total number of
occurrence of a and b’s character set= {a, b}. The BNF grammar consists of 4 parts,
set of start symbols, set of non-terminal symbols, tokens and productions.
assume the non-terminal symbol is S
The BNF grammer of the set of ALL strings can be consider the equation are, L(G)
is({S,A,B,∈}
SAB
AaA/a
BbB/b
A∈
B∈
We can find the strings on the total number of a’s and b’s is odd number.
Sab
SaAbB
SaAbBa∈b∈ab
We can apply the context free production is A∈ and B∈
∈ Can be denoted as empty strings.
The starting symbol is S. The total number of occurrence of a and b calculated is denoted
with S symbol.
Eliminate the unwanted terms p x and y and I on the BNF grammar,
After that delimiting and calculating the number of occurrence that can be remove the
number terms
The BNF grammar can be specified as the Brackets <S> can be used for starting the
terms. The BNF grammar can the non-terminal interpretation which can find the total
number of occurrence of a and b is odd of the string is ‘a’, ’b’,’ ab’, empty string is
odd.
Question 7
EBNF can be used for declaring the function of the grammar language.
3

SAB
The EBNF can consist of a set of rules that includes the following,
Sid
The terminal symbol s can declare the function of the header and can access the body of the
EBNF grammar.
S:: public static (int ab, int xy)
Sab
SaAbB
S::aAbB|a∈b∈|ab
S ::-> ab
The header of the methods can specify the access modifiers as public static and also uses the
return type (int, real, char). The process of methods can pass the parameters (int a, int b).
<s> ::=ab|<A><statement><B><statement> |<s><ab>
<Letter>:: =a|b|c|d|....|<a><b>
<Id>:: =0|1|2|3|....|9
The execution of the methods can display the statement. The left parenthesis of the keyword
can use the expression for separating the left parenthesis, where the identifier is denoted as
the blank empty. The blank is denoted as visualizing the argument for separating the list. The
parameters of the identifier can be used for passing the argument syntax structure of the
identifier, it can be used for non-optional function for accessing the actual parameters and it
can match with the formal parameters. The declared identifier can be used for the met
symbols (+,*,/, {).
4
The EBNF can consist of a set of rules that includes the following,
Sid
The terminal symbol s can declare the function of the header and can access the body of the
EBNF grammar.
S:: public static (int ab, int xy)
Sab
SaAbB
S::aAbB|a∈b∈|ab
S ::-> ab
The header of the methods can specify the access modifiers as public static and also uses the
return type (int, real, char). The process of methods can pass the parameters (int a, int b).
<s> ::=ab|<A><statement><B><statement> |<s><ab>
<Letter>:: =a|b|c|d|....|<a><b>
<Id>:: =0|1|2|3|....|9
The execution of the methods can display the statement. The left parenthesis of the keyword
can use the expression for separating the left parenthesis, where the identifier is denoted as
the blank empty. The blank is denoted as visualizing the argument for separating the list. The
parameters of the identifier can be used for passing the argument syntax structure of the
identifier, it can be used for non-optional function for accessing the actual parameters and it
can match with the formal parameters. The declared identifier can be used for the met
symbols (+,*,/, {).
4
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 6

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.