Related articles |
---|
Extending REG-EXP to 2-Dimension. mosh@ramanujan.cs.albany.edu (1994-11-21) |
Using inherited attributes within a yacc grammar crpalmer@undergrad.math.uwaterloo.ca (1994-11-25) |
Re: Using inherited attributes within a yacc grammar al@nmt.edu (1994-11-30) |
Re: Using inherited attributes within a yacc grammar ruiter@ruls41.fsw.leidenuniv.nl (1994-12-01) |
Re: Using inherited attributes within a yacc grammar sikkema@hio.tem.NHL.NL (Albert Sikkema) (1994-12-01) |
Re: Using inherited attributes within a yacc grammar peter@merlion.zfe.siemens.de (1994-12-02) |
Re: Using inherited attributes within a yacc grammar al@nmt.edu (1994-12-02) |
Re: Using inherited attributes within a yacc grammar pjj@cs.man.ac.uk (1994-12-05) |
Newsgroups: | comp.compilers |
From: | Albert Sikkema <sikkema@hio.tem.NHL.NL> |
Keywords: | lex, DFA |
Organization: | Compilers Central |
References: | 94-11-137 |
Date: | Thu, 1 Dec 1994 10:48:29 GMT |
Inherited attributes can be used in Yacc by pushing them onto the
semantic stack just before the appearance of the nonterminal on the
rhs In your example it looks like this:
number
:
'x'
{
$$ = 16; /* integer.base = 16 */
}
integer
{
$$ = $3; /* number.value = integer.value */
}
|
{
$$ = 10; /* integer.base = 10 */
}
integer
;
integer
:
digit
{
$$ = $1; /* integer1.value = digit.value */
}
|
{
$$ = $0; /* integer2.base = integer1.base */
}
integer
digit
{
$$ = $2 * $0 + $3;
/* integer1.value = integer2.value * integer1.base + digit.value */
}
;
digit
:
"0"
{
$$ = 0; /* digit.value = 0 */
}
|
.
.
.
|
"f"
{
$$ = 15; /* digit.value = 15 */
}
;
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.