Prove the grammar are Ambiguous - grammar

Can anyone please tell me how to prove this grammar are Ambiguous ? thanks in advance.
I cannot find the string which shows the grammar are Ambiguous :(
G2 = { {S}, {a,b}, {S->ab|ba|SS}, S }

Related

Tips on writing own CFG

Can you give me some tips about writing own grammar given the answer? I mean for example:
Given 00101, create your own BNF grammar

Why is this grammar not LL(1)?

I am doing some homework, and was asked to show that the grammar A -> aAa | ε is not LL(1). From everything that I have seen, the answer I have so far is that since the First and the Follow sets of A contain a. Is this correct or am I thinking about something the wrong way?

ANTLR Paraphrase, what does it do?

Just starting to write my first lexer and i've come across this:
RPAREN options { paraphrase = ")"; } : ")";
I'd like to know what paraphrase actually does, does it mean that in this case RPAREN can also be used as simply ) in the parser?
thanks!
EDIT - just found this online
We can use paraphrases in Rules to make error messages user-friendly
is this correct?
paraphrase is not a valid option in ANTLR 3 or ANTLR 4. Including it would either produce a warning or error, and it would not have any impact on behavior.

Regular expression does not find a particular string

A weird problem with a regular expression.
The following regular expression
NSString* expression = #"^.*?(\bSKC|CLR|NSC|FEW|SCT|BKN|OVC|VV|CAVOK\b).*?$";
finds the string BKN in expression BKN007 and BKN007CLR002, but does not find the String CAVOK in 110V270 CAVOK 03/M01.
Can someone please help? Thanks!
P.S. The code is in Objective C but I do not think it matters as there is something wrong with the expression itself...
It is probably due to \b after CAVOK which means word boundary.
Try this regex:
NSString* expression = #"^.*?(SKC|CLR|NSC|FEW|SCT|BKN|OVC|VV|CAVOK).*$";

When ParseKit tries to recognize my Grammar, it enters an infinite loop. What's wrong?

Hi I am creating grammar for some formula which is using recursion. The formula is much more complicated but for now I test only some part of it. After calling parse method it crashes on allMatchesFor method. The stack trace is full of allMatchesFor invocations so it looks like it is in infinite loop
Where is the problem. Is it in my grammar construction logic or else ? How can I accomplish similar thing to avoid this crash
My grammar is like:   
#start = formula;
formula = valueTypeResult;
valueTypeResult = (value | concept | arithmeticStatement);
arithmeticStatement = valueTypeResult (arithmeticOperator valueTypeResult)+;
value = 'V';
concept = 'C';
arithmeticOperator = 'A';
Can you please tell me how to create grammars which use recursion ?
Thanks
Developer of ParseKit here.
ParseKit has no problem with recursion, but your grammar is incorrect. This is more of a BNF grammar problem than a ParseKit problem.
Here's the correct version of what I believe you are attempting with your grammar above:
#start = formula;
formula = arithmeticStatement;
arithmeticStatement = valueTypeResult (arithmeticOperator valueTypeResult)+;
valueTypeResult = (value | concept);
value = 'V';
concept = 'C';
arithmeticOperator = 'A';