recursive-descent

Difference between an LL and Recursive Descent parser?

房东的猫 提交于 2019-11-29 18:41:36
I've recently being trying to teach myself how parsers (for languages/context-free grammars) work, and most of it seems to be making sense, except for one thing. I'm focusing my attention in particular on LL(k) grammars , for which the two main algorithms seem to be the LL parser (using stack/parse table) and the Recursive Descent parser (simply using recursion). As far as I can see, the recursive descent algorithm works on all LL(k) grammars and possibly more, whereas an LL parser works on all LL(k) grammars. A recursive descent parser is clearly much simpler than an LL parser to implement,

Recursive descent parser implementation

戏子无情 提交于 2019-11-28 20:41:54
I am looking to write some pseudo-code of a recursive descent parser. Now, I have no experience with this type of coding. I have read some examples online but they only work on grammar that uses mathematical expressions. Here is the grammar I am basing the parser on. S -> if E then S | if E then S else S | begin S L | print E L -> end | ; S L E -> i I must write methods S() , L() and E() and return some error messages, but the tutorials I have found online have not helped a lot. Can anyone point me in the right direction and give me some examples?. I would like to write it in C# or Java syntax

How to do recursive descent of json using json.net?

百般思念 提交于 2019-11-27 23:05:29
I am trying to parse a json file using json.net. The file looks like this {X: { Title:"foo", xxxx:xxxx } } {Y: {ZZ: {Title: "bar",...} } } I am trying to recurse down this structure processing all objects with a Title attribute. But I am confused about JToken , JProperty , JContainer , JValue , JObject . Reading the source code has not left me much wiser and none of the samples help. I want something along the lines of WalkNode(node, Action<Node> action) { foreach(var child in node.Children) { Action(child); WalkNode(child); } } Parse() { WalkNode(root, n=> { if(n["Title"] != null) { ... } });

Converting EBNF to BNF

喜你入骨 提交于 2019-11-27 19:32:55
It's been a few years since my computer-language class and so I've forgotten the finer points of BNF's and EBNF's and I don't have a textbook next to me. Specifically, I've forgotten how to convert an EBNF into BNF. From what little I remember, I know that one of the main points is to convert { term } into <term> | <many-terms> . But I don't remember the other rules. I've tried to look this up online but I can only find links to either homework questions, or a small comment about converting terms with curly braces. I can't find an exhaustive list of rules that define the translation. 500 -

How do you write an arithmetic expression parser in JavaScript, without using eval or a constructor function?

不想你离开。 提交于 2019-11-27 16:41:54
问题 Given a string: var str1 = "25*5+5*7"; Without using eval or the constructor function in JavaScript, how would I be able to write a function called "output" that takes in the string and outputs the arithmetic value of the string, which in this case is 160? 回答1: Here's a full precedence expression evaluator following the recursive parsing idea I linked-to in a comment on the OP's question. To do this, first I wrote a simple BNF grammar for the expressions I wanted to process: sum = product |

Recursive descent parser implementation

半腔热情 提交于 2019-11-27 13:05:01
问题 I am looking to write some pseudo-code of a recursive descent parser. Now, I have no experience with this type of coding. I have read some examples online but they only work on grammar that uses mathematical expressions. Here is the grammar I am basing the parser on. S -> if E then S | if E then S else S | begin S L | print E L -> end | ; S L E -> i I must write methods S() , L() and E() and return some error messages, but the tutorials I have found online have not helped a lot. Can anyone

Converting EBNF to BNF

岁酱吖の 提交于 2019-11-26 19:46:50
问题 It's been a few years since my computer-language class and so I've forgotten the finer points of BNF's and EBNF's and I don't have a textbook next to me. Specifically, I've forgotten how to convert an EBNF into BNF. From what little I remember, I know that one of the main points is to convert { term } into <term> | <many-terms> . But I don't remember the other rules. I've tried to look this up online but I can only find links to either homework questions, or a small comment about converting

How to do recursive descent of json using json.net?

∥☆過路亽.° 提交于 2019-11-26 14:29:52
问题 I am trying to parse a json file using json.net. The file looks like this {X: { Title:"foo", xxxx:xxxx } } {Y: {ZZ: {Title: "bar",...} } } I am trying to recurse down this structure processing all objects with a Title attribute. But I am confused about JToken , JProperty , JContainer , JValue , JObject . Reading the source code has not left me much wiser and none of the samples help. I want something along the lines of WalkNode(node, Action<Node> action) { foreach(var child in node.Children)