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
4
votes
1 answer

How do parsers handle generic type parameters?

I'm writing a recursive decent parser for an imaginary programming language. It's a C-style language with common operators like ==, <, >, <=, and >=, and it also features generic functions (like those in C#). In languages like C#, to call a generic…
4
votes
2 answers

Recursive descent parser: how to find the FIRST, FOLLOW, and PREDICT sets?

I'm looking for a good explanation of the definitions of the FIRST, FOLLOW, and PREDICT sets of a RDP when given a grammar.
Bryan Denny
  • 27,363
  • 32
  • 109
  • 125
4
votes
1 answer

Error reporting in a recursive descent parser

I am writing a recursive descent parser for config files. These are mostly similar to ini files. Here is the language in some sort of EBNF-like form: document ::= { category } category ::= title {entry} title ::= "["
user836218
4
votes
3 answers

Recursive descent same prefix

I am learning about recursive decent parsing and come up with some scenarios in which I think the algorithm isn't working. One of them is, considering this simple grammar: S → E; E → id | id + id Then the string id + id; is valid in the language of…
4
votes
1 answer

Recursive in BNF grammar

Well, I'm not sure how I should write a function using recursive descent parse to parse a grammer like the below. Actually, I'm not sure if I was doing right it... BNF: A : B | A '!' B : '[' ']' pseudo-code: f() { if(tok is B) …
Jack
  • 16,276
  • 55
  • 159
  • 284
4
votes
1 answer

Examples of recursive descent parser

What are some good examples of recursive descent parsers? Say from open source projects, or particularly good example code. I'm especially looking to compare implementations with and without backtracking. Examples in C, C++, Java, Javascript or…
catphive
  • 3,511
  • 3
  • 31
  • 29
4
votes
3 answers

What is a good tool for automatically calculating FIRST and FOLLOW sets?

I'm currently in the middle of playing with a BNF grammar that I hope to be able to wrangle into a LL(1) form. However, I've just finished making changes and calculating the new FIRST and FOLLOW sets for the grammar by hand for the third time today…
Zxaos
  • 7,791
  • 12
  • 47
  • 61
4
votes
2 answers

Implementing a basic mathematical expression simplifier

I'm working on a side project for my calc class that differentiates simple functions like y=x^2 in Javascript. To do that, I parsed the expression into an Abstract Syntax Tree, and then hardcoded derivative rules like product rule and chain rule.…
scrblnrd3
  • 7,228
  • 9
  • 33
  • 64
4
votes
1 answer

boost::Spirit Grammar for unsorted schema

I have a section of a schema for a model that I need to parse. Lets say it looks like the following. { type = "Standard"; hostname="x.y.z"; port="123"; } The properties are: The elements may appear unordered. All elements that are part of…
Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
4
votes
3 answers

C++ operator overloading in recursive expression classes

I have a recursive class Expression which denotes boolean-like expressions, for instance: (a & b) | (c & ~d) Note that Expression takes care of both unary and binary expressions. Basically, Expression should follow the CFG similar to a boolean…
4
votes
2 answers

Recursive descent parser in Clojure

I'm creating some expert system with Clojure and I need to develop Recursive descent parser for reading rules from a text file and creating clojure functions from it. I have written function which checks if text file is ok with my grammar and it…
dzwonu
  • 119
  • 11
4
votes
1 answer

AST parsing, detect current scope

When parsing AST with visitor, how could visitor detect when scope changes? For example, when we are in Class node, we create Class scope, but how to detect when we leaving a class node, to close the scope? 1: Stmt_Class( type: 0 extends:…
4
votes
1 answer

LL1 First and follow sets rules

I'm looking on building a parse table for an LL(1) grammar, and It all makes sense bar one aspect!? The rules for the follow set seam to conflict. • For each production X → αAβ, put FIRST (β) − {€} in FOLLOW(A) • If € is in FIRST (β) then put…
3
votes
2 answers

ISO human-readable parser for Python in Python

I'm looking for a parser for Python (preferably v. 2.7) written in human-readable Python. Performance or flexibility are not important. The accuracy/correctness of the parsing and the clarity of the parser's code are far more important…
kjo
  • 33,683
  • 52
  • 148
  • 265
3
votes
1 answer

Parser implementations comparison: correctness confirmation and (perhaps) optimization

I've implemented two expression parsers, in recursive descent and operator precedence. They're implemented in Object Pascal. Here's the recursive descent: function ParseFactor: PNode; var Temp: PNode; begin Result := ParsePrimary; if t.Kind in…
LeleDumbo
  • 9,192
  • 4
  • 24
  • 38
1 2
3
13 14