librelist archives

« back to archive

How to reach a symbol table from the jison file?

How to reach a symbol table from the jison file?

From:
Herman
Date:
2014-01-08 @ 22:10
For example, if i have a simple lexical grammar
[a-z]+    {return 'SYMBOL';}


Then in the language grammar

e : SYMBOL {$$ = ?? // how to grab from a symbol table?}

And if i have

e: SYMBOL '=' e {// how do i set a value in a symbol table?}

Where should I initialize the symbol table? Thanks. I am new to bison, so
it's probably a noob question.

Re: [jison] How to reach a symbol table from the jison file?

From:
Zachary Carter
Date:
2014-01-08 @ 23:51
Symbol tables are out of scope for jison, so you'll have to handle that
yourself. But, you can retrieve the text that was matched by SYMBOL by
using yytext:

e : SYMBOL {$$ = yytext; }

or a dollar sign + the position of SYMBOL in the rule, (e.g. $1 here):

e: SYMBOL '=' e { mySymbolTable[$1] = $3; }



On Wed, Jan 8, 2014 at 2:10 PM, Herman <sorsorday@gmail.com> wrote:

> For example, if i have a simple lexical grammar
> [a-z]+    {return 'SYMBOL';}
>
>
> Then in the language grammar
>
> e : SYMBOL {$$ = ?? // how to grab from a symbol table?}
>
> And if i have
>
> e: SYMBOL '=' e {// how do i set a value in a symbol table?}
>
> Where should I initialize the symbol table? Thanks. I am new to bison, so
> it's probably a noob question.
>



-- 
Zach Carter

Re: [jison] How to reach a symbol table from the jison file?

From:
Herman
Date:
2014-01-09 @ 00:04
Thanks


On Wed, Jan 8, 2014 at 3:51 PM, Zachary Carter <zack.carter@gmail.com>wrote:

> Symbol tables are out of scope for jison, so you'll have to handle that
> yourself. But, you can retrieve the text that was matched by SYMBOL by
> using yytext:
>
> e : SYMBOL {$$ = yytext; }
>
> or a dollar sign + the position of SYMBOL in the rule, (e.g. $1 here):
>
> e: SYMBOL '=' e { mySymbolTable[$1] = $3; }
>
>
>
> On Wed, Jan 8, 2014 at 2:10 PM, Herman <sorsorday@gmail.com> wrote:
>
>> For example, if i have a simple lexical grammar
>> [a-z]+    {return 'SYMBOL';}
>>
>>
>> Then in the language grammar
>>
>> e : SYMBOL {$$ = ?? // how to grab from a symbol table?}
>>
>> And if i have
>>
>> e: SYMBOL '=' e {// how do i set a value in a symbol table?}
>>
>> Where should I initialize the symbol table? Thanks. I am new to bison, so
>> it's probably a noob question.
>>
>
>
>
> --
> Zach Carter
>