From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: OpenToken: Handling the empty word token
Date: Mon, 30 Jan 2012 19:34:06 +0100
Date: 2012-01-30T19:34:06+01:00 [thread overview]
Message-ID: <1r5s26c6dmfh2$.190wc38zc11v2.dlg@40tude.net> (raw)
In-Reply-To: 7756ad67-4ce1-4fb8-a4a1-f8136815ac9b@p13g2000yqd.googlegroups.com
On Mon, 30 Jan 2012 08:28:57 -0800 (PST), mtrenkmann wrote:
> I am wondering if that behavior cannot be implemented in the table-
> lookup procedure. That is when I call Action_For with an unexpected
> token, while there is the epsilon as one of the expected tokens, then
> this epsilon could be accepted automatically, the parser changes its
> state accordingly, and the unexpected token is checked again. Don't
> know if that is possible, since I am not yet familiar with the
> internals of table-driven parsing.
You have tables of token for states where there are alternatives. You match
the source against the table:
Get (Source, Statements_Table, Token, Got_It);
if Got_It then -- One of the tokens has been matched
case Token is
when If_Token =>
Do_If;
when For_Token =>
Do_For;
when ... =>
...
end case;
else -- Nothing matched, this is the "epsilon" choice
...
end if;
This is basically a recursive descent parser. You would also have to define
a pair useful subprograms like Skip_Blanks, Get_Identifier, Get_Literal,
Get_Keyword.
The only difficult part is infix expressions. For these there are
ready-to-use means, which match the expression evaluating it or producing a
tree as byproduct.
The problem as you described it just does not exist. You get the keyword,
if it is not there, you do something in reaction. That is.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2012-01-30 18:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-27 16:22 OpenToken: Handling the empty word token mtrenkmann
2012-01-27 16:48 ` Dmitry A. Kazakov
2012-01-28 3:42 ` Randy Brukardt
2012-01-29 17:45 ` Stephen Leake
2012-01-31 0:56 ` Randy Brukardt
2012-01-31 9:09 ` Georg Bauhaus
2012-01-31 12:16 ` Stephen Leake
2012-02-02 1:39 ` Randy Brukardt
2012-01-28 10:46 ` Stephen Leake
2012-01-30 16:28 ` mtrenkmann
2012-01-30 18:34 ` Dmitry A. Kazakov [this message]
2012-01-31 12:58 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox