Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Brizio ! (Registered 2017-08-20) You are not logged in 
CSDb User Forums


Forums > C64 Coding > Anybody know Bison/Yacc?
2017-07-23 15:25
oziphantom

Registered: Oct 2014
Posts: 146
Anybody know Bison/Yacc?

I want to extend the VICE monitor to be able to look up an address in a "bank" on a break.. so something like
break $1234 IF @IO:D010 & $40 = $40
where @IO:D010 looks up the VIC register D010 and get its value.

CMD_BANK BANKNAME end_cmd
                     { mon_bank(e_default_space, $2); }
seems to be the C you can use to change the banks
int monbank = mon_interfaces[mem]->current_bank;/code] seems like it would allow you to save the current bank. And
MEMSPACE src_mem = addr_memspace(start_addr);
WORD start = addr_location(start_addr);
byte1 = mon_get_mem_val(src_mem, start));
could be used to look up the value, its just a matter of putting it all together in a yacc file to glue it together and make it work as part of the condition_expression, so if somebody could help me with the yacc modifications I would greatly appreciate it ;)

For completeness it probably needs to be C: only and making it take the form @C:(bank):Addr to make it clear might be best..
 
... 5 posts hidden. Click here to view all posts....
 
2017-07-26 23:20
knue

Registered: Dec 2012
Posts: 16
ok, this is what you have to do.

In mon_parse.y you need to add sth like this:
compare_operand: register { $$ = new_cond;
                            $$->operation = e_INV;
                            $$->is_parenthized = FALSE;
                            $$->reg_num = $1; $$->is_reg = TRUE;
                            $$->child1 = NULL; $$->child2 = NULL;
                          }
               | number   { $$ = new_cond;
                            $$->operation = e_INV;
                            $$->is_parenthized = FALSE;
                            $$->value = $1; $$->is_reg = FALSE;
                            $$->child1 = NULL; $$->child2 = NULL;
                          }
               | '@' BANKNAME ':' number { 
                            $$ = new_cond;
                            $$->operation = e_INV;
                            $$->is_parenthized = FALSE;
                            $$->bankname = $2; $$->value = $4; $$->is_reg = FALSE;
                            $$->child1 = NULL; $$->child2 = NULL;
               }
               ;

Of course, you'll add a another field bankname to cond_node_s in montypes.h.
Be careful to not read garbage data when you read from this field. All other parts of the code which construct this thing must initialize this field with some default value. Check:
%type<cond_node> opt_if_cond_expr cond_expr compare_operand

Here you can see, which rules create a cond_node and need to initialize this new field.

ah, this code uses the syntax:
@bankname:number
2017-07-26 23:31
knue

Registered: Dec 2012
Posts: 16
speaking of cond_node_s. you can probably put value and reg_num in a union.
2017-07-27 22:07
Count Zero

Registered: Jan 2003
Posts: 769
Phew - thx knue and ozi for going for this. My last small changes on that yacc shice broke a few things and had to be reverted :)

That feature addition would rock a lot!
2017-07-28 12:07
oziphantom

Registered: Oct 2014
Posts: 146
ERROR -- Unexpected token:
  break c253 if @io:$d020 == 0
                 ^


Doesn't like it, I tried adding spaces, no difference


Where banks are defined as
Available banks (some may be equivalent to others):
default *cpu ram rom io ram1 intfunc extfunc cart c64rom vdc
2017-07-28 12:45
oziphantom

Registered: Oct 2014
Posts: 146
maybe the lex file needs some modifications?
2017-07-30 13:35
knue

Registered: Dec 2012
Posts: 16
So these are the important bits in the mon_lex.l:

%{
   if (new_cmd) {
      if (!(asm_mode && opt_asm)) {
         last_len = cur_len = 0;
      }
      if (asm_mode) {
         BEGIN (ASM_MODE);
         opt_asm = 0;
      } else {
         BEGIN (CMD);
      }
      new_cmd = 0;
   }
%}

<CMD>{
//...
        bank            { BEGIN(BNAME);         return CMD_BANK; }
//...
}

//...
<BNAME>[_a-zA-Z0-9]*      { yylval.str = lib_stralloc(yytext); return BANKNAME; }


So, lex is more powerful than just simple regular expressions. Additionally, you can define states. Simple example would be nested comments. Sth you couldn't do with straight regular expressions. Those <FOO> are the states. Read the code as follows:

When we are about to lex a new command that is *not* in asm_mode we begin CMD state.
Then, *only* if we are in CMD mode, lexing 'bank' starts BNAME mode. And only *then* we lex any string as BANKNAME. So this is the only occasion where yacc actually sees the BANKNAME token.

What we would have to do is to add a lex rule which additionally lexes a string as BANKNAME. A simple rule like:

§[_a-zA-Z0-9]*      { yylval.str = lib_stralloc(yytext); return BANKNAME; }

would do the trick. Then, §io would be a BANKNAME token. BTW you can also change the parser to just recognize:

BANKAME ':' number
or even just
BANKNAME number
instead of
'@' BANKNAME ':' number
because '§' is now part of the BANKNAME token.
2017-07-31 10:54
oziphantom

Registered: Oct 2014
Posts: 146
add '§' to the bankname would be bad, as then the char* to bank number functions won't recognise the string, it won't match.. doing a straight ++ on it to skip a char is kind of evil and will probably fail on some system somewhere.

SO I just put
[_a-zA-Z0-0]*	{yylval.str= lib_stralloc(yytext); return BANKNAME; }
at the bottom of
<COND_MODE>{
AND IT WORKS!!!

now onwards to getting labels to work :)
2017-07-31 12:04
oziphantom

Registered: Oct 2014
Posts: 146
and now labels work
2017-07-31 15:21
knue

Registered: Dec 2012
Posts: 16
ah, there is even a COND_MODE. I missed that. Sort of bad to work with that many states in the lexer. Would be better to have that logic in the parser...
2017-08-17 21:13
Count Zero

Registered: Jan 2003
Posts: 769
How is this progressing? Patch upcoming for "upstream"? :)
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
c0zmo/BLiSS
MetalSoftwareService
aNdy/AL/Cosine
Dwangi/Fairlight
Nucleus/Desire
Harpoon
Guests online: 47
Top Demos
1 Uncensored  (9.7)
2 Edge of Disgrace  (9.7)
3 Coma Light 13  (9.6)
4 The Shores of Reflec..  (9.6)
5 Lunatico  (9.6)
6 Comaland 100%  (9.5)
7 Incoherent Nightmare  (9.5)
8 Wonderland XII  (9.5)
9 Comaland  (9.5)
10 Wonderland XIII  (9.5)
Top onefile Demos
1 Veterans of Style  (9.5)
2 Dawnfall V1.1  (9.5)
3 Daah, Those Acid Pil..  (9.5)
4 Treu Love [reu]  (9.4)
5 Dawnfall  (9.3)
6 SidRok  (9.3)
7 F1 Evolution  (9.3)
8 One-Der  (9.2)
9 Tunnel Vision  (9.2)
10 Game of Thrones [2sid]  (9.1)
Top Groups
1 Pond  (10)
2 Booze Design  (9.4)
3 Censor Design  (9.4)
4 Oxyron  (9.4)
5 Crest  (9.3)
Top Crackers
1 Mr. Z  (9.9)
2 Mitch  (9.8)
3 Mr Zero Page  (9.8)
4 Snacky  (9.8)
5 MWS  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2017
Page generated in: 0.321 sec.