c - For loop semantics in Bison/Yacc -


i'm trying write own scripting language using flex , bison. have basic parser , add statement similar c language statement. not clear me how code action associated statement

suppose have following production 'for' statement:

forstatement: '(' expr ';' expr ';' expr ')' statements end; {} 

it not clear me in action associated production.

intuitively understand should something, in action associated previous statement, such :

evaluate($3); while(evaluate($5)) { execute($9); evaluate($7); } evaluate($7); 

where evaluate , execute 2 c functions.

so have 2 questions (suppose write c code action associated grammar production):

  1. what task of 'evaluate'. mean, how evaluate expression @ every loop considering value of expression potentially changes @ every step of loop?
  2. what task of 'execute'. mean, how evaluate statements inside loop considering each statement has different outcome @ every step of loop.

the values of 3 expressions 'expr' changes @ runtime , same true statements inside body.

looking @ 2 questions, seem miss execution engine (a kind of software cpu) needed. engine needs remember state of variables, return 'addresses' of loops, ... (depending on implementation method chosen).

so parsing first step. think creating data structure each statement , expression, , have these executed engine.

have @ stack-based systems.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -