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
0 answers

Writing a recursive descent parser with nested if-conditions

I am writing a recursive descent parser for parsing a specific grammar, and I have to do the nested if/else in that grammar. The grammar is as follows: ::= if In the parseStmt we have to do the following: basically…
0
votes
1 answer

Partition the upper part for the given key

I would like to implant recursive search using python, it will partition the upper part for the given key example: list[2, 4, 6, 9, 10] for the key is 6 case, the return index is 3 for the key is 4 case, the return index is 2 if the key is not in…
0
votes
0 answers

What About Abstract Syntax Tree Recursivity In Javascript?

I am trying to build a compiler in javascript and until now I've managed to build a lexer that creates tokens based on input: = Test Input (with optional semicolon): data myVariable = 4 data myVariable2 = "myName"; task Eat { receives…
0
votes
2 answers

Are there PEG-based parser generators that support left recursion?

Left recursion seems to be a big problem for many parser generators that are built upon the foundations of recursive descent parsing. I'm looking for a PEG-based parser generator that supports it - in whatever language.
0
votes
1 answer

Recursive descent parser that counts the number of 'a' and 'b' characters not counting correctly

I'm writing a simple recursive descent parser that takes standard input and counts the number of 'a' and 'b' characters. The grammar for this is as follows: S -> A B '\n' A -> a A | empty B -> b B | empty int lookahead; int nontermA(); int…
0
votes
2 answers

How to code nextToken() function for a descent recursive parser LL(1)

I'm writting a recursive descent parser LL(1) in C++, but I have a problem because I don't know exactly how to get the next token. I know I have to use regular expressions for getting a terminal but I don't know how to get the largest next…
Briko
  • 19
  • 5
0
votes
1 answer

Converting a grammar to LL(1)

I have this grammar: program ::= expr_list expr_list ::= {LF} [expr {LF {LF} expr}] {LF} lvalue ::= [expr DOT] NAME call_param ::= [[NAME COLON] expr {COMMA [NAME COLON] expr}] func_param ::= [NAME [COLON expr] {COMMA NAME [COLON expr]}] expr…
mtk358
  • 565
  • 1
  • 7
  • 20
0
votes
1 answer

Given a recursive descent parser, how should I modify it for Syntax Analysis?

I have just finished coding a recursive descent parser for C Minus that simply prints "ACCEPT" if the input text file can be parsed or "REJECT" if not. I have a function for each rule in the grammar that just returns true or false. Here are some of…
user10950989
0
votes
1 answer

Recursive descent parsing and abstract syntax trees

I'm hard-coding a recursive decent parser, mostly for learning purposes and, I've run into some trouble. I'll use this short excerpt from the CSS3 grammar as an example: simple_selector = type_selector | universal; type_selector = […
John Leidegren
  • 59,920
  • 20
  • 131
  • 152
0
votes
1 answer

Tokenize abstract terminals in LL grammar

I am currently writing a basic parser for an XML flavor. As an exercise, I am implementing an LL table-driven parser. This is my example of BNF grammar: %token name data string %% /* LL(1) */ doc : elem elem : "<"…
explogx
  • 1,159
  • 13
  • 28
0
votes
0 answers

Pseudo-code of a recursive descent parser

We got this context-free grammar that looks relatively simple and we are required to write a pseudo code of a recursive descent parser for that CFG. We need to use getToken()/nextToken() and unreadToken(Token) procedures. I have never done anything…
0
votes
1 answer

Does Boost Spirit X3 support left recursion?

One of the shortcomings/implementation challenges of recursive-descent parsers is dealing with left recursion, e.g. := '+' | The parser needs to parse an expr before it can parse an expr... Now,…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
2 answers

Validating a "break" statement with a recursive descent parser

In Crafting Interpreters, we implement a little programming language using a recursive descent parser. Among many other things, it has these statements: statement → exprStmt | ifStmt | printStmt | whileStmt |…
brandizzi
  • 26,083
  • 8
  • 103
  • 158
0
votes
0 answers

Multi-threaded compiler returning different outputs upon fastly repeated executions

I have a multi-threaded compiler developed in Java. It receives n filepaths and starts one thread for each filepath received. Everything works fine if I do multiple executions with a single file. However, when I input multiple files and execute it…
0
votes
2 answers

Java: Understanding a Recursive Descent Parser Implementation

Let's say we have a simple grammar: Program ::= Expression Expression ::= Number ::= - ( Expression , Expression ) With this expression: -(-(8,3)4) Returning 1. My token stream(I splice parens and commas out) looks like this (MINUS -) (MINUS…
James
  • 15
  • 6