15 questions
-1
votes
3
answers
106
views
Curly Braces (scope) related unexpected output of if-elseif loop in C++
I have used a normal if-elseif ladder to update some variables depending upon conditions. The condition can be either a, b or c. That's why I am using an if-elseif ladder.
But, when I use the if-...
1
vote
1
answer
320
views
How does the latest ANTLR4 resolve the "dangling else" ambiguity?
I am using antlr 'org.antlr:antlr4:4.9.2' and come across the "dangling else" ambiguity problem; see the following grammar IfStat.g4.
// file: IfStat.g4
grammar IfStat;
stat : 'if' expr '...
0
votes
0
answers
88
views
Bison Difficult Dangling Else Removal
I am trying to get rid of dangling else in my grammar. Terminals are capital-letter words. I have:
statement:
expression_statement (not important now )
| compound_statement (not important now ...
0
votes
1
answer
224
views
Beaver parser generator shift-reduce conflicts connected to dangling else
I am feeding a (generated) grammar to Beaver parser generator. Multiple shift-reduce conflicts are caused by it seems like the dangling else problem in this rules:
Condition
= IF LPAR Expression....
0
votes
1
answer
121
views
Bison Flex reduce/reduce conflict on dangling else with mid action
I am currently moving a fun-project of mine over to bison/flex as parser and have trouble solving a reduce/reduce conflict:
// https://github.com/X39/yaoosl/blob/master/code-gen/yaoosl.y#L761-L766
...
1
vote
1
answer
384
views
Solving dangling if, elsif, and else in Bison without associativity declarations
I am implementing a parser for a language that has if-elsif-else statements and can't seem to make my grammar unambiguous. Our compilers class was given a handout on solving the dangling else problem ...
-7
votes
1
answer
238
views
What is exactly dangling-else problem in c? [closed]
How can the code work like this?
Which if-else statements are linked with each other?
So why is the output like that "$$$$$"?
#include <stdio.h>
int main() {
int x = 11;
int y = 9;
...
-1
votes
2
answers
94
views
Dangling else query (or an excercise in reading bad code) [closed]
The book I'm reading (C How to Program with an into to C++ Global Edition, Deitel&Dietel, 2016) gives the following code: Note that this is how the book presents the code in the exercise section, ...
-1
votes
1
answer
279
views
Dangling else in Kotlin
I have this doubt guys, I don't know; any example to understand will be great.
Does the Kotlin programming language suffer from the "dangling else" problem?
If the problem is there then what is the ...
2
votes
2
answers
1k
views
Removing Ambiguity Caused By Dangling Else For LL(1) Grammars
In the case of the dangling else problem for compiler design, is there a reason to left factor it before removing ambiguity?
We are transforming a CFG into an LL(1) grammar so my professor is asking ...
0
votes
1
answer
350
views
How to solve dangling else in Coco/R?
I have a dangling-else problem in Coco/R. I try to understand the Coco/R User Manual and I ask Google, but I can't solve the problem on my own.
I simplified my problem to the following Coco/R grammar ...
1
vote
0
answers
765
views
Dangling else grammar for Lex and Yacc
I'm writing a small parser to recognize a subset of Java and I've run into an issue that I believe is called the dangling else problem.
My grammar for matching if-else statements started off like ...
2
votes
0
answers
1k
views
LL1 and unambiguous grammar for dangling else
I am trying to write a simple compiler using Flex for scanner and a special tool named PGen to define grammars.
Now, I am trying to solve unambiguous grammar for dangling else.
I have searched for ...
3
votes
1
answer
3k
views
LL(1) grammar for dangling else
In compiler construction, one of the main ambiguity problems is dangling else.
As mentioned in Compilers: Principles, Techniques, and Tools book by Aho, Lam, Sethi and Ullman, the grammar for the ...
1
vote
1
answer
1k
views
If statement to tree representation in ANTLR
I have the following if statement that parses correctly:
ifStatement
: 'IF' expression 'THEN' statementBlock
(options {greedy=true;}
: 'ELSE' statementBlock)?
;
Now, I ...