Questions tagged [parsing]

43 questions
17
votes
6 answers

Does an abstract syntax tree have to be a tree?

Does the output of a parser have to be a tree or could it also be general graph? Moreover, is there any existing language or a plausible one that uses general graphs representation instead of trees for their syntax?
10
votes
1 answer

Shift-resolve parsing - questions

I've recently came across a paper describing the parsing technique mentioned in the title. Unfortunately, the terminology used in said paper is somewhat beyond my comprehension, so I've been attempting to grasp the construction algorithm more…
Jakub Lédl
  • 233
  • 1
  • 8
7
votes
1 answer

Determining whether a CFG is $LL(k)$ for any $k$?

In Knuth's original paper on $LR(k)$ grammars, he proved that the decision problem "Given a CFG $G$, is there a $k$ such that $G$ is an $LR(k)$ grammar?" is undecidable. Is there a similar result showing that it is undecidable whether a given CFG is…
7
votes
1 answer

Can this CFG be written into an equivalent LL(1) grammar?

I have the following CFG which I suspect cannot be rewritten to one which is LL(1): $S \rightarrow \epsilon\ |\ aSbS\ |\ bSaS\ |\ cSdS\ |\ dScS$ I've thought about it for a while, and can't seem to make any progress. I know that the simpler grammar…
7
votes
1 answer

Is the Syntax of C Language completely defined by CFGs?

I think the Question is self sufficient. Is the syntax of C Language completely defined through Context Free Grammars or do we have Language Constructs which may require non-Context Free definitions in the course of parsing? An example of non CFL…
4
votes
0 answers

Parsing family of grammars, determine if LR(k)

Consider the family of grammars $G_n,~n\geq2$. $$S \rightarrow A_ib_i~,~for~~1\leq i \leq n$$ $$A_i \rightarrow a_jA_i~|~a_j~,~for~~1 \leq i,j \leq n~~and~~i \neq j$$ where multiple alternative right sides result from different values of $i,j$ while…
Ethan
  • 321
  • 1
  • 5
4
votes
1 answer

How to make a parse tree for the following propositional logic formula?

I have a formula $ \neg((q \implies \neg q) \vee p \vee (\neg q \implies (r \wedge p))) $. As it contains 3 subformulas between the $\vee$'s, how can i put it into a parse tree, as a parse tree contains 2 branches from each node.
AkshaiShah
  • 163
  • 2
  • 4
4
votes
2 answers

Understanding LEADING and TRAILING operations of an operator precedence grammar

I want to understand what the LEADING and TRAILING of non-terminal in an operator precedence grammar physically mean. I am confused by the various definitions I have read on them. I understand that the LEADING of a non-terminal is the first…
Likhit
  • 143
  • 1
  • 1
  • 3
4
votes
1 answer

Is this phrase structure grammar from my textbook correct?

I just started reading "Parsing Techniques, A Practical Guide", Second Edition, by Dick Grune and Ceriel J.H. Jacobs. On page 12, the authors start describing a set of rules that can be used to generate the set of all enumerations of names of the…
Aky
  • 225
  • 1
  • 8
4
votes
1 answer

Expressive power of lexer + parser

Most modern compilers split their syntax analysis into a lexical phase that is followed by a parsing phase. The lexical phase is given by a regular expression, while parsing is guided by a context-free grammar. What class of languages can be…
Martin Berger
  • 8,358
  • 28
  • 47
4
votes
1 answer

Building Simple Parse Trees

I am trying to learn how to build parse trees. I have watched videos and tried to do some on my own, but am a little lost. In this example, I am given the following: $$ \begin{align*} &S\to(L) \\ &S\to a \\ &L\to L,S \\ &L\to S \end{align*} $$ and…
user17445
  • 41
  • 3
4
votes
2 answers

Binary operators with higher precedence than unary operators

Generally (perhaps always) in programming languages, unary operators have the highest precedence. In some langauges, such as Standard ML, one can dynamically change the precedence of binary operators at run time. But what if we have a language…
Ray Toal
  • 287
  • 1
  • 7
4
votes
2 answers

Priority in formal grammar

From my recitation class, I have the following exercise: $\mathrm{EXP} = 0 \mid 1 \mid b \mathrm{EXP} \mid \mathrm{EXP} a \mid \mathrm{EXP} m \mathrm{EXP}$ The above grammar is ambiguous. Make an unambiguous grammar which produce same language as…
URL87
  • 765
  • 2
  • 8
  • 14
3
votes
1 answer

How to define at least one occurrence of a string between two tokens in bottom up LALR(1) parser grammar

I am trying to define a non terminal symbol in a LALR(1) grammar (with CUP parser). It is requested that the token must appear exactly twice, while the token must appear at least once. In the end I came up with this…
gc5
  • 151
  • 4
3
votes
1 answer

LR(1) - Items, Look Ahead

I am having diffuculties understanding the principle of lookahead in LR(1) - items. How do I compute the lookahead sets ? Say for an example that I have the following grammar: S -> AB A -> aAb | b B -> d Then the first state will look like this: S…
mrjasmin
  • 586
  • 1
  • 5
  • 12
1
2 3