Skip to content

Commit

Permalink
Allow referencing semantic values of terminals inside semantic actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
zaach committed Apr 11, 2010
1 parent 5a44239 commit dca9c4e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/jison.js
Expand Up @@ -1087,7 +1087,7 @@ parser.parse = function parse (input) {
shifts++;

stack.push(symbol);
vstack.push(null); // semantic values or junk only, no terminals
vstack.push(this.lexer.yytext); // semantic values or junk only, no terminals
stack.push(a[1]); // push state
if (!preErrorSymbol) { // normal execution/no error
yyleng = this.lexer.yyleng;
Expand Down
6 changes: 3 additions & 3 deletions tests/parser/actions.js
Expand Up @@ -43,7 +43,7 @@ exports["test return null"] = function() {
assert.equal(parser.parse('x'), null, "semantic action");
};

exports["test terminal semantic values are null"] = function() {
exports["test terminal semantic values are not null"] = function() {
var lexData = {
rules: [
["x", "return 'x';"],
Expand All @@ -52,7 +52,7 @@ exports["test terminal semantic values are null"] = function() {
};
var grammar = {
bnf: {
"E" :[ ["E x", "return [$2 === null]"],
"E" :[ ["E x", "return [$2 === 'x']"],
["E y", "return [$2]"],
"" ]
}
Expand All @@ -62,7 +62,7 @@ exports["test terminal semantic values are null"] = function() {
parser.lexer = new RegExpLexer(lexData);

assert.deepEqual(parser.parse('x'), [true], "semantic action");
assert.deepEqual(parser.parse('y'), [null], "semantic action");
assert.deepEqual(parser.parse('y'), ['y'], "semantic action");
};

exports["test Semantic action stack lookup"] = function() {
Expand Down

0 comments on commit dca9c4e

Please sign in to comment.