Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.misty.com!news.iecc.com!.POSTED!nerds-end From: "matzebraun@googlemail.com" Newsgroups: comp.compilers Subject: Re: Compiling expressions Date: Thu, 3 Jan 2013 07:13:13 -0800 (PST) Organization: Compilers Central Lines: 21 Sender: johnl@iecc.com Approved: comp.compilers@iecc.com Message-ID: <13-01-010@comp.compilers> References: <12-12-035@comp.compilers> <12-12-036@comp.compilers> <13-01-006@comp.compilers> NNTP-Posting-Host: news.iecc.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: leila.iecc.com 1357244182 750 64.57.183.58 (3 Jan 2013 20:16:22 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Thu, 3 Jan 2013 20:16:22 +0000 (UTC) Keywords: parse, code Posted-Date: 03 Jan 2013 15:16:22 EST X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:833 > > > 3. Precedences (and possibly associativities) defined in tables. > > I would rather the result is easy to understand but I don't mind too > much how the tables are generated. Search for Shunting-yard algorithm/precedence climbing/precedence parsing these should fulfill your requirements easily if implemented properly. You basically have a pair of parsing function callback and precedence level for each input token, if your ast is perfectly regular and it's only infix operations, then you can leave out the parsing function callback. You may find an implementation in our c compiler (though keep in mind that this is a complete c parser with semantic so there is a lot more code "around"), you may find the relevant pieces here: https://github.com/MatzeB/cparser/blob/master/parser.c (look for parse_subexpression(), init_expression_parser(), struct expression_parser_function_t) Greetings, Matthias Braun