Related articles |
---|
[8 earlier articles] |
Re: regular expression operators in CF grammars nospam@snafu.de (Sönke Kannapinn) (2002-08-10) |
Re: regular expression operators in CF grammars cfc@shell01.TheWorld.com (Chris F Clark) (2002-08-23) |
Re: regular expression operators in CF grammars tbandrow@unitedsoftworks.com (tj bandrowsky) (2002-09-03) |
Re: regular expression operators in CF grammars cfc@shell01.TheWorld.com (Chris F Clark) (2002-09-12) |
Re: regular expression operators in CF grammars cfc@TheWorld.com (Chris F Clark) (2002-09-14) |
RE: regular expression operators in CF grammars qjackson@shaw.ca (Quinn Tyler Jackson) (2002-09-14) |
RE: regular expression operators in CF grammars qjackson@shaw.ca (Quinn Tyler Jackson) (2002-09-14) |
From: | "Quinn Tyler Jackson" <qjackson@shaw.ca> |
Newsgroups: | comp.compilers |
Date: | 14 Sep 2002 16:35:59 -0400 |
Organization: | Compilers Central |
References: | 02-05-142 02-05-151 02-06-024 02-06-056 02-06-090 02-07-010 02-07-025 02-07-043 02-08-035 02-08-078 02-09-018 02-09-070 <20020912232254.48B8712D0@0lsen.net> 02-09-094 |
Keywords: | parse |
Posted-Date: | 14 Sep 2002 16:35:59 EDT |
Kannapinn to Clark:
> After all, we attach semantics to the detailed grammar structure
> of an EBNF when targeting compiler construction, don't we? If,
> for example, I write down a simple EBNF rule
>
> S := 'if' E 'then' S ['else' S 'end']
>
> I want to attach semantic code depending on whether the
> optional part has actually been seen by the parser or not.
One way to do that in Meta-S:
S ::= "if" E "then" S [$x("else") S "end"];
Reduction code:
if($MATCHED()) // since reductions are fired on failure to match as
well
{
if($CAST("x").GetLength()) // non empty; will == "else" if that
portion matched
{
// we now know that the else portion matched, and know
// that the appropriate tree nodes (the second S) are
// available for traversal
}
else
{
// we have the simple form
}
}
Since $x(expr) is a local cast, and since x is not referenced in S,
this is a safe bind that doesn't
change the semantics of G.
--
Quinn Tyler Jackson
http://members.shaw.ca/qjackson/
Return to the
comp.compilers page.
Search the
comp.compilers archives again.