Questions tagged [parsers]

Questions about algorithms that decide whether a given string belongs to a fixed formal language.

443 questions
76
votes
1 answer

Language theoretic comparison of LL and LR grammars

People often say that LR(k) parsers are more powerful than LL(k) parsers. These statements are vague most of the time; in particular, should we compare the classes for a fixed $k$ or the union over all $k$? So how is the situation really? In…
Raphael
  • 73,212
  • 30
  • 182
  • 400
24
votes
1 answer

Is there any nongeneral CFG parsing algorithm that recognises EPAL?

EPAL, the language of even palindromes, is defined as the language generated by the following unambiguous context-free grammar: $S \rightarrow a a$ $S \rightarrow b b$ $S \rightarrow a S a$ $S \rightarrow b S b$ EPAL is the 'bane' of many parsing…
Alex ten Brink
  • 9,206
  • 3
  • 36
  • 63
20
votes
2 answers

What is an IELR(1)-parser?

I try to teach myself the usage of bison. The manpage bison(1) says about bison: Generate a deterministic LR or generalized LR (GLR) parser employing LALR(1), IELR(1), or canonical LR(1) parser tables. What is an IELR-parser? All relevant articles…
fuz
  • 913
  • 6
  • 20
20
votes
3 answers

Parsing arbitrary context-free grammars, mostly short snippets

I want to parse user-defined domain specific languages. These languages are typically close to mathematical notations (I am not parsing a natural language). Users define their DSL in a BNF notation, like this: expr ::= LiteralInteger | ( expr…
Gilles 'SO- stop being evil'
  • 44,159
  • 8
  • 120
  • 184
18
votes
2 answers

For every 'evil' regex, does there exist a non-evil alternative, or is the devil in the grammar?

Apparently, ReDos attacks exploit characteristics of some (otherwise useful) regular expressions ... essentially causing an explosion of possible paths through the graph defined by the NFA. Is it possible to avoid such problems by writing an…
David Bullock
  • 281
  • 1
  • 3
17
votes
2 answers

Removing left-recursion in grammar while maintaining left-association of operator

I have a problem with this exercise: Let G be the following ambiguous grammar for the λ-calculus: E → v | λv.E | EE | (E) where E is the single non-terminal symbol, λv.E represents abstraction w.r.t. the variable v in E, and EE represents…
Marco DallaG
  • 173
  • 1
  • 5
17
votes
2 answers

Are regular expressions $LR(k)$?

If I have a Type 3 Grammar, it can be represented on a pushdown automaton (without doing any operation on the stack) so I can represent regular expressions by using context free languages. But can I know if a type 3 grammar is $LR(1)$, $LL(1)$,…
16
votes
3 answers

What would you get if you add parameters to context free grammars?

I was thinking of grammars for indendation-sensitive languages and it looks like CF grammars would do the trick if combined with parameters. As an example, consider this fragment for simplified Python grammar in ANTLR-like format: // on top-level…
Aivar
  • 285
  • 1
  • 7
16
votes
1 answer

Why separate lexing and parsing?

It's possible to parse a document using a single pass from a state machine. What is the benefit of having two passes, ie. having a lexer to convert text to tokens, and having a parser to test production rules on those tokens? Why not have a single…
Brent
  • 2,583
  • 3
  • 16
  • 23
15
votes
2 answers

Does the language of Regular Expressions need a push down automata to parse it?

I want to convert a user entered regular expression into an NFA so that I can then run the NFA against a string for matching purposes. What is the minimum machine that can be used to parse regular expresssions? I assume it must be a push down…
15
votes
5 answers

How is non-ambuiguity different from determinism?

I am trying to understand what is meant by "deterministic" in expressions such as "deterministic context-free grammar". (There are more deterministic "things" in this field). I would appreciate an example more then the most elaborate explanation! If…
wvxvw
  • 1,388
  • 9
  • 13
14
votes
1 answer

When did $LR(k)$ acquire the meaning "left-to-right scan, rightmost derivation?"

According to the Wikipedia article, the L in $LR(k)$ means "left-to-right scan", and the "R" means "rightmost derivation." However, in Knuth's original paper on $LR(k)$ grammars, he defines $LR(k)$ (on page 610) as a language that is "translatable…
13
votes
3 answers

Why is using a lexer/parser on binary data so wrong?

I often work with lexer/parsers, as opposed to a parser combinator and see people who never took a class in parsing, ask about parsing binary data. Typically the data is not only binary but also context sensitive. This basically leads to having only…
Guy Coder
  • 5,181
  • 2
  • 30
  • 65
13
votes
3 answers

How is this grammar LL(1)?

This is a question from the Dragon Book. This is the grammar: $S \to AaAb \mid BbBa $ $A \to \varepsilon$ $B \to \varepsilon$ The question asks how to show that it is LL(1) but not SLR(1). To prove that it is LL(1), I tried constructing…
Vinayak Garg
  • 457
  • 1
  • 7
  • 18
13
votes
2 answers

Is there any way to distinguish between LL(k) and LR(k) grammar?

I am recently studying about Compilers designing. I came to know about two types of grammar one is LL grammar and other is LR grammar. We also know the facts that every LL grammar is LR that is LL grammar is a proper subset of LR grammar. First one…
Debabratta Jena
  • 359
  • 1
  • 3
  • 9
1
2 3
29 30