From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5412c98a3943e746 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.189.197 with SMTP id gk5mr1691999pbc.1.1331111545815; Wed, 07 Mar 2012 01:12:25 -0800 (PST) Path: h9ni49099pbe.0!nntp.google.com!news1.google.com!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Verified compilers? Date: Wed, 7 Mar 2012 10:12:33 +0100 Organization: cbb software GmbH Message-ID: <4edda5mav3cf$.149pbgyxl1wx5.dlg@40tude.net> References: <9207716.776.1331054644462.JavaMail.geo-discussion-forums@ynaz38> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: FbOMkhMtVLVmu7IwBnt1tw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Date: 2012-03-07T10:12:33+01:00 List-Id: On Wed, 07 Mar 2012 06:33:54 +0100, Yannick Duch�ne (Hibou57) wrote: > Le Tue, 06 Mar 2012 18:43:21 +0100, Dmitry A. Kazakov > a �crit: > >> On Tue, 6 Mar 2012 09:24:04 -0800 (PST), Shark8 wrote: >> >>> I seem to recall someone on this forum doing a table-driven approach, >> >> I do: >> >> http://www.dmitry-kazakov.de/ada/components.htm#Parsers_etc > I did not investigate, so the question may be stupid: why two separate > stacks? Because you need to store arguments some of which appear before the operators that bound them. That is the argument's stack. The operations too may be reordered according to the association priorities. That is the operation's stack. Consider parsing: A + B * C + D A+B*C+D ---> AS: A OS: +B*C+D ---> AS: A OS: + B*C+D ---> AS: A; B OS: + *C+D ---> AS: A; B OS: +; * C+D ---> AS: A; B; C OS: +; * +D ---> pop * AS: A; B*C OS: + +D ---> pop + AS: A+(B*C) OS: + D ---> AS: A+(B*C); D OS: + ---> pop + AS: (A+(B*C))+D OS: > I did a basic expression parser too some long time ago, and it had > a single stack. Well, Turing machine has only one tape, so yes you could do that. The question is why. P.S. This method has nothing to do with being table-driven. Table-driven is the lexer, which recognizes operators using tables. So the engine is same for all expressions. Tables are also used for the recursive descent parser put around infix expression parser. At each level there is a table of expected keywords. The input is matched against the table and parser does something. Some leaves are expressions, for them the described above method is used. Infix expression is only really difficult part here. The rest is just trivial for almost any normal language. I was always wondering why people bother to study grammars, LR, LL parsers and other useless stuff. This is a great example of making a "science" out of nothing and for nothing. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de