How to eliminate left recursion for the following grammar?
E := EE+|EE-|id
Using the common procedure:
A := Aa|b
translates to:
A := b|A'
A' := ϵ| Aa
Applying this to the original grammar we get:
A = E, a = (E+|E-) and b = id
Therefore:
E := id|E'
E' := ϵ|E(E+|E-)
But this grammar seems incorrect because
ϵE+ -> ϵ id +
w...
I think my program should be able to recognize the following as a function declaration
int fn(int i) { int n; return; }
but it doesn't.
Here's the relevant part of my yacc file
program : declaration_list ;
declaration_list : declaration_list declaration | declaration ;
declaration : var_declaration
| fun_declaration
...
I have a question from a test in a Programming Languages class that is confusing me.
Give a context-free grammar to generate the following language
L = { aibjck | 0 <= i <= j <= i + k }
I am completely unfamiliar with this notation. I cant seem to find anything in the book or my notes about it, and I have no idea how to query google f...
Hello,
I cannot understand decidability really well. I have been reading from books and internet, but I am little bit confused.
According to the book (as I understood), we can decide on decidability of a problem by constructing Turing Machines. Let us say that we want to decide whether an NFA is a decidable language. First, we need to c...
In compiler class we made a parser for a made up language that is a simplified version of C. All the parser does is make a symbol table based on the input and exit with an error message if the syntax is incorrect. Now we need to take an input file that is written in this language, and convert it into mips code (actually spim code which ...
I have a grammar defined as follows:
A -> aA*b | empty_string
Is A a regular expression? I'm confused as to how to interpret a BNF grammar.
...
I'm currently in the middle of playing with a BNF grammar that I hope to be able to wrangle into a LL(1) form. However, I've just finished making changes and calculating the new FIRST and FOLLOW sets for the grammar by hand for the third time today and I'm getting tired of it. There has to be a better way!
Can someone suggest a tool tha...
how to define a grammar (context-free) for a new programming language (imperative programming language) that you want to design from scratch.
In other words : how do you proceed when you want to create a new programming language from scratch.
...
I'm working on a project in which I have to read in a Grammar file (breaking it up into my data structure), with the goal of being able to generate a random "DearJohnLetter".
My problem is that when reading in the .txt file, I don't know how find out whether the file was supposed to be a completely blank line or not, which is detriment...
Hello,
I am quite new to ANTLR, so this is likely a simple question.
I have defined a simple grammar which is supposed to include arithmetic expressions with numbers and identifiers (strings that start with a letter and continue with one or more letters or numbers.)
The grammar looks as follows:
grammar while;
@lexer::header {
pack...
Is there a way to specify custom class name (meaning independent of the grammar name) for the ANTLRv3 generated Parser and Lexer classes?
So in the case of
grammar MDD;
//other stufff
Automatically it would crate MDDParser and MDDLexer, but i would like to have them for example as MDDBaseParser and MDDLexer.
...
I'm reviewing my notes for my course on theory of computation and I'm having trouble understanding how to complete a certain proof. Here is the question:
A = {0^n 1^m 0^n | n>=1, m>=1} Prove that A is not regular.
It's pretty obvious that the pumping lemma has to be used for this. So, we have
|vy| >= 1
|vxy| <= p (p being the pu...
Hi, I was just putting some thought into different languages (as I'm reviewing for final exams coming up) and I can not think of a valid pushdown automata to handle the language A = {0^n 1^n 0^n | n >= 0}. This is not a context-free language, am I correct?
...
I'm trying to learn about shift-reduce parsing. Suppose we have the following grammar, using recursive rules that enforce order of operations, inspired by the ANSI C Yacc grammar:
S: A;
P
: NUMBER
| '(' S ')'
;
M
: P
| M '*' P
| M '/' P
;
A
: M
| A '+' M
| A '-' M
;
And we want to parse ...
Hello. I have this problem where i need to convert the following CFG to CFG in CNF.
S-> ABa
A-> aab
B-> Ac
I know the steps are as follows.
Remove epsilon transitions - Done
remove unit productions
convert to CNF by:
introduce a new non terminal for each term
replace terminals in the productions rules with the new nonterminal
i...
Hello everyone,
I have to check if the following language is context free:
L2={a^n * b^m * c^n * d^(n+m) :m>=0 n>=0 }
Please help, I am totally stuck and I have to hand it over on Monday.
...
hello
i have the following sentence
a language L1={a^n * b^n : n>=0} and L2={b^n * a^n : n>=0} are context free languages so they are close a=under the L1L2 so L={a^n * b^2n A^n : n>=0} must be context free too because it is generated by a close property
I have to prove if this sentence is true or not
so i check the L language and i do...
Hello
I am trying to prove that the language L={a^n * b^2n A^n : n>=0} is not context free but i tried the pumping theory but i can not find one state that if i pump then it is out of the language
...
If you're given a language, how do you figure out if it's regular, CF but not regular, or phrase-structure but not CF? Is there a good way to attack this problem? I could randomly try to make FAs or PDAs, but I feel like there's a better way to do it.
Classic example:
L = { a^n b^n c^n | n >= 0 }
Where would one start?
Thanks.
...
Does the standard specify the official C++ grammar?
I searched, but did not find it anywhere.
Also, I wish to read a bit about C++ grammar in detail, like which category of grammars it falls in, etc. Any links pointing me in the right direction would be helpful.
By category, I mean
taken from here.
...