comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Verified compilers?
Date: Wed, 7 Mar 2012 10:12:33 +0100
Date: 2012-03-07T10:12:33+01:00	[thread overview]
Message-ID: <4edda5mav3cf$.149pbgyxl1wx5.dlg@40tude.net> (raw)
In-Reply-To: op.wascesqrule2fv@douda-yannick

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  
> <mailbox@dmitry-kazakov.de> 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



  reply	other threads:[~2012-03-07  9:12 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-21 15:42 Verified compilers? Yannick Duchêne (Hibou57)
2012-02-24  1:41 ` Shark8
2012-02-24  8:52   ` Georg Bauhaus
2012-02-24 17:36   ` Peter C. Chapin
2012-03-06  1:27 ` Randy Brukardt
2012-03-06 17:24   ` Shark8
2012-03-06 17:43     ` Dmitry A. Kazakov
2012-03-06 19:03       ` Shark8
2012-03-07  5:33       ` Yannick Duchêne (Hibou57)
2012-03-07  9:12         ` Dmitry A. Kazakov [this message]
2012-03-07 17:49           ` Niklas Holsti
2012-03-07 20:17             ` Dmitry A. Kazakov
2012-03-07 23:28               ` Usefulness of Formal Notions in Programming (was: Verified compilers?) Georg Bauhaus
2012-03-08  9:24                 ` Usefulness of Formal Notions in Programming Dmitry A. Kazakov
2012-03-08 10:30                   ` Nasser M. Abbasi
2012-03-08 12:37                     ` Dmitry A. Kazakov
2012-03-08  0:42               ` Verified compilers? Randy Brukardt
2012-03-08  9:25                 ` Dmitry A. Kazakov
2012-03-08 18:10                   ` Niklas Holsti
2012-03-08 20:41                     ` Dmitry A. Kazakov
2012-03-08 18:02               ` Niklas Holsti
2012-03-08 20:40                 ` Dmitry A. Kazakov
2012-03-09  0:44                   ` Georg Bauhaus
2012-03-09 22:13                   ` Niklas Holsti
2012-03-10 10:36                     ` Dmitry A. Kazakov
2012-03-10 20:35                       ` Niklas Holsti
2012-03-11  9:47                         ` Dmitry A. Kazakov
2012-03-11 22:22                           ` Niklas Holsti
2012-03-12  5:12                             ` Niklas Holsti
2012-03-12  9:43                             ` Dmitry A. Kazakov
2012-03-14  8:36                               ` Niklas Holsti
2012-03-14  9:24                                 ` Georg Bauhaus
2012-03-14 11:14                                   ` REAL (was: Verified compilers?) stefan-lucks
2012-03-14 12:59                                     ` REAL Dmitry A. Kazakov
2012-03-14 13:30                                       ` REAL Georg Bauhaus
2012-03-14 13:51                                         ` REAL Dmitry A. Kazakov
2012-03-14 20:37                                           ` REAL Brian Drummond
2012-03-14 21:52                                             ` REAL Dmitry A. Kazakov
2012-03-14 13:52                                         ` REAL georg bauhaus
2012-03-14 17:42                                         ` REAL Jeffrey Carter
2012-03-14 10:14                                 ` Verified compilers? Dmitry A. Kazakov
2012-03-14 20:13                                   ` Niklas Holsti
2012-03-11 10:55                         ` Georg Bauhaus
2012-03-10 13:46                     ` Brian Drummond
2012-03-07  1:00     ` Randy Brukardt
2012-03-07 12:42   ` Stuart
2012-03-08  1:06     ` Randy Brukardt
2012-03-08  9:04       ` Jacob Sparre Andersen
2012-03-08  9:37         ` Dmitry A. Kazakov
2012-03-08 11:23           ` Simon Wright
2012-03-08 12:27             ` Dmitry A. Kazakov
2012-03-08 10:23         ` Brian Drummond
2012-03-08 23:38           ` Bill Findlay
2012-03-09 13:56             ` Brian Drummond
2012-03-09 14:43               ` Shark8
2012-03-09 21:51                 ` Brian Drummond
2012-03-09 15:49               ` Bill Findlay
2012-03-09 20:34                 ` Brian Drummond
2012-03-09 19:40               ` Jeffrey Carter
2012-03-09 20:39                 ` Brian Drummond
2012-03-09 23:59               ` phil.clayton
2012-03-08 15:23         ` Peter C. Chapin
2012-03-09  2:04         ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox