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):
- what task of 'evaluate'. mean, how evaluate expression @ every loop considering value of expression potentially changes @ every step of loop?
- 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
Post a Comment