Re: Mini-C example
Frank Hein <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <OFF97D35D3.1EE1C10D-ONC1258004.005900FA-C1258004.005B0E32@maxence.de> |
Florian Klemme <[email protected]> wrote on 03.08.2016 17:34:21: > From: Florian Klemme <[email protected]> > To: [email protected], > Date: 03.08.2016 17:36 > Subject: [Spirit-general] Mini-C example > > On 03.08.2016 01:59, Frank Hein wrote: > Regarding your compiler implementation did you examine the mini-c > example provided with qi? Inspiring. > Oh, it is! I haven't seen it before. I see, there is a lot of > refactorization for me to do. ;-) > I've seen that Joel uses multiple grammars to parse the source, but > I can only find the instantiation of the function-parser in main(). You can understand grammars as a container for rules. You can use them to give some structure (by topic, for example) to your rule set. A grammar is also a nonterminal parser. When you define a grammer, you provide a start rule, which is one of the rules defined within the grammar. That's not all about grammars but enough to get a basic understanding. If you phrase_parse an input with a grammar provided as parser, then qi applies the rules defined in the grammer starting with the defined start rule. This may depend on other rules. > Where are the others instantiated? Or how does this chain of grammars work? > Also, what does this "body" member do? > template <typename Iterator> > function<Iterator>::function(error_handler<Iterator>& error_handler) > : function::base_type(start), body(error_handler) Above function::base_type(start) makes the rule named 'start' the start rule of the grammar 'function'. So if you would phrase_parse( x,y, function, skipper) rule evalution starts at the 'start' rule. > name = > !body.expr.keywords > >> raw[lexeme[(alpha | '_') >> *(alnum | '_')]] > ; You can even make a grammar known from another grammar. Take a look at the declaration of body. It's statement<Iterator> body. This is the statement grammar declared in statement.hpp. The statement grammar again has a member, which is the expression grammar. That way the mini-c grammars have a top-down knowledge of each other. In main only the top level grammar is explicitly, the others are instantiated as a (chain of) members of the outer grammar. Regards, Frank > Florian > ------------------------------------------------------------------------------ > _______________________________________________ > Spirit-general mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/spirit-general ------------------------------------------------------------------------------ _______________________________________________ Spirit-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/spirit-general
smime.p7s
(application/pkcs7-signature, 5.1 KB) - not displayed