recursive-descent

boost::Spirit Grammar for unsorted schema

怎甘沉沦 提交于 2019-12-07 10:46:30
问题 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 the schema must appear, and no other. All of the elements' synthesised attributes go into a struct. (optional) The schema might in the future depend on the type field -- i.e., different fields based on type -- however I am not concerned about this at the

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

非 Y 不嫁゛ 提交于 2019-12-06 05:25:06
问题 I'm looking for a good explanation of the definitions of the FIRST, FOLLOW, and PREDICT sets of a RDP when given a grammar. 回答1: Try Programming Language Pragmatics , by Michael L. Scott (Morgan Kaufmann). Parsing is covered in chapter 2. Recursive-descent parsing is described in section 2.2.3; first and follow sets in 2.2.5. 回答2: You can automatically calculate first, follow, and predict sets using Calculate Predict, First, and Follow Sets from BNF (Backus Naur Form) Grammar Specification

boost::Spirit Grammar for unsorted schema

五迷三道 提交于 2019-12-05 17:52:22
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 the schema must appear, and no other. All of the elements' synthesised attributes go into a struct. (optional) The schema might in the future depend on the type field -- i.e., different fields based on type -- however I am not concerned about this at the moment. According to the Spirit forums, the following is the answer. You might want to have a look at the

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

爱⌒轻易说出口 提交于 2019-12-04 12:50:30
I'm looking for a good explanation of the definitions of the FIRST, FOLLOW, and PREDICT sets of a RDP when given a grammar. Try Programming Language Pragmatics , by Michael L. Scott (Morgan Kaufmann). Parsing is covered in chapter 2. Recursive-descent parsing is described in section 2.2.3; first and follow sets in 2.2.5. You can automatically calculate first, follow, and predict sets using Calculate Predict, First, and Follow Sets from BNF (Backus Naur Form) Grammar Specification without having to download anything. It's a good way to verify answers or automate the tedium. If you want to do it

Is it possible to use Recursive Descent Parser to both verify the grammar AND build the parse tree at the same time?

坚强是说给别人听的谎言 提交于 2019-12-04 11:00:25
问题 Is it possible to generate a parse tree at the same time as I use recursive descent parser to check if the data matches grammar? If so, what approach would I use to build a tree as I recursively descent? Thanks, Boda Cydo. Note: I am new to parsing. (Asked several questions on SO already, and I am getting better with it.) 回答1: Yes, it's possible. How to do so will depend on the implementation you want. Here's a sample that might work for you: First, define your node: class ParseTreeNode {

Recursively dir() a python object to find values of a certain type or with a certain value

血红的双手。 提交于 2019-12-04 06:33:15
I have a complex Python data structure (if it matters, it's a large music21 Score object) which will not pickle due to the presence of a weakref somewhere deep inside the object structure. I've debugged such problems with the stack trace and python debugger before, but it's always a big pain. Is there a tool which runs dir() recursively on all attributes of an object, finding objects hidden in lists, tuples, dicts, etc., and returns those that match a certain value (a lambda function or something like that). A big problem is recursive references, so some sort of memo function (like copy

Resources for writing a recursive descent parser by hand

蓝咒 提交于 2019-12-03 12:13:05
问题 I'm looking to write a recursive descent parser by hand and I'm looking for good resources on how to structure it, algorithms, etc. 回答1: There is a good tutorial on codeproject under "Compiler Patterns". Lately, you can even just Google "compiler patterns". http://www.codeproject.com/Articles/286121/Compiler-Patterns The article covers most aspects of building a simple compiler (the back-end, the BNF, and the patterns used to implement the various BNF rules), but is not very heavy on theory,

Resources for writing a recursive descent parser by hand

喜夏-厌秋 提交于 2019-12-03 03:25:48
I'm looking to write a recursive descent parser by hand and I'm looking for good resources on how to structure it, algorithms, etc. There is a good tutorial on codeproject under "Compiler Patterns". Lately, you can even just Google "compiler patterns". http://www.codeproject.com/Articles/286121/Compiler-Patterns The article covers most aspects of building a simple compiler (the back-end, the BNF, and the patterns used to implement the various BNF rules), but is not very heavy on theory, or even on why a recursive descent compiler works to convert language input into code. I can suggest

Rename files to lowercase in Powershell

允我心安 提交于 2019-12-02 20:33:04
I am trying to rename a bunch of files recursively using Powershell 2.0. The directory structure looks like this: Leaflets + HTML - File1 - File2 ... + HTMLICONS + IMAGES - Image1 - Image2 - File1 - File2 ... + RTF - File1 - File2 ... + SGML - File1 - File2 ... I am using the following command: get-childitem Leaflets -recurse | rename -newname { $_.name.ToLower() } and it seems to rename the files, but complains about the subdirectories: Rename-Item : Source and destination path must be different. I reload the data monthly using robocopy, but the directories do not change, so I can rename them

Is there an easy way to chunk a text file into brace-balanced sections?

纵饮孤独 提交于 2019-12-02 01:51:58
I'm trying to parse some data out of a file using Perl & Parse::RecDescent. I can't throw the full data file at the perl script because RecDescent will take days poring over it. So I split up the huge datafile into RD-sized chunks to reduce the runtime. However, I need to extract sections within balanced brackets and the routine I have now is not robust (it depends too much on the position of the final close-bracket from a newline). Example: cell ( identifier ) { keyword2 { }; ... keyword3 { keyword4 { } }; } ...more sections... I need to grab everything from cell ... { to the matching closing