Questions tagged [recursive-descent]

Recursive Descent Parser is a kind of top-down parser built as a set of recursive procedures each implementing a production rule of the grammar.

Recursive descent parsers can be hand-written or generated. Examples of parser generators producing recursive descent parsers include ANTLR, Coco/R, and JavaCC.

207 questions
0
votes
1 answer

Invalid grammar for a top-down recursive parser

I am trying to create grammar for a naive top-down recursive parser. As I understand the basic idea is to write a list of functions (top-down) that correspond to the productions in the grammar. Each function can call other functions (recursive). The…
JFreeman
  • 974
  • 1
  • 10
  • 26
0
votes
1 answer

Realize precedence climbing in Haskell

I am trying to realise precedence climbing in Haskell, following this specific algorithm: compute_expr(min_prec): result = compute_atom() while cur token is a binary operator with precedence >= min_prec: prec, assoc = precedence and…
0
votes
1 answer

Unambiguous Grammar for Regular Expressions

I'm trying to develop a recursive decent parser for regular expressions for a homework assignment. I just wanted to ask the community if the grammar I've developed is correct or if I'm on the right track: -= Regex Grammar (EBNF) =- ->…
certifiedNoob
  • 365
  • 2
  • 6
  • 15
0
votes
0 answers

Recursive descend parser for evalutating math expressions throws an error and I do not how to fix it

I'm new here and have a generall question. I'm trying to create a recursive descent parser for the evaluation of mathematic expressions, and the parser I have crafted until now also works very good for integers and floategers. But now I am trying to…
Lucy
  • 1
  • 2
0
votes
2 answers

Please, help me to understand parsing trees example from craftinginterpreters.com

I'm trying to build a C compiler from scratch. Googling took me to the https://craftinginterpreters.com/ site. There are a lot of explanations how source code parsers work in detail. I've reached "Parsing expressions" chapter and stuck in this. They…
IC_
  • 1,624
  • 1
  • 23
  • 57
0
votes
1 answer

Recursive descent parser - dealing with closing brackets

I'm trying to build a recursive descent parser that builds an AST as it goes. The language is fairly simple; x >/
Omri. B
  • 375
  • 1
  • 13
0
votes
1 answer

StringTokenizer replacement in Java

I'm trying to write a recursive descent parser. I need a method that converts the string to a stream, so I can use a next method. Everywhere I read, it says that StreamTokenizer is outdated and unnecessary, but I can't find any…
Omri. B
  • 375
  • 1
  • 13
0
votes
0 answers

An erroneous successful parsing in a recursive descent parser

I have the following code. It's a recursive descent parser with backtracking. /*\ /*\ |*|--------------|*| |*| Grammar: |*| |*| A -> ( A ) B |*| |*| | [ A ] B |*| |*| | n B |*| |*| | B |*| |*| |*| |*|…
Aphrontos
  • 25
  • 4
0
votes
1 answer

Does a Recursive Predictive Descent Parser NEEDS to construct a complete syntax tree and store in memory?

I've been thinking and a question has arisen. Does this type of compiler really need the complete syntax tree in memory?
0
votes
1 answer

Cannot get LL(1) form of grammar for recursive descent parser

I have grammar: S -> bU | ad | d U -> Ufab | VSc | bS V -> fad | f | Ua To contruct recursive descent parser I need LL(1) form. Best I got is: S -> bU | ad | d U -> fY | bSX Y -> adScX | ScX X -> fabX | aScX | ε Removed left recursions and done…
0
votes
1 answer

How can I simplify a recursive-descent parser?

I have the following simple LL(1) grammar, which describes a language with only three valid sentences: "", "x y" and "z x y": S -> A x y | ε . A -> z | ε . I have constructed the following parsing table, and from it a "naive" recursive-descent…
0
votes
1 answer

Recursive descent Parser: infix to RPN [2]

this the continuation of me trying to make a recursive descent parser--LL(1)-- that takes in infix expressions and outputs RPN. Here is a link to my first question to which @rici did an amazing job of answering and i hope i do his answer justice…
AM429
  • 306
  • 3
  • 11
0
votes
1 answer

Recursive descent: infix to postfix conversion repeating operators

We recently learned about converting infix to postfix using stacks during our programming course at uni. And I have meaning to write my parser for a while, so I decided to it using recursive descent. I am following along with this: Parsing…
AM429
  • 306
  • 3
  • 11
0
votes
1 answer

How does gcc/clang parse c++ if it can't be parsed by a LR(1) parser?

GCC/Clang are handwritten parsers. I read a post saying that C++ can't be parsed by an LR(1) parser (Why can't C++ be parsed with a LR(1) parser?). If so, how come GCC/Clang are handwritten recursive descent parsers, when LR(1) is more powerful than…
xilpex
  • 3,097
  • 2
  • 14
  • 45
0
votes
0 answers

LALR parser being slower than recursive descent parser

Recently I wrote a (highly optimized) LALR(1) parser (that could handle ambiguous grammars) and supplied it a very ambiguous grammar. After that, I wrote a recursive descent parser for the same grammar, but with all the ambiguity taken out. I've…
xilpex
  • 3,097
  • 2
  • 14
  • 45