Closed madhavpcm closed 1 year ago
Can you cut the example down a bit so I can understand it more easily please?
Ok, I have this grammar
"INT_T" "MAIN" '(' ')' '{' LDeclBlock BeginBlock '}'
{
...
process($6?) //LDeclBlock
let node = $7?; //BeginBlock
}
;
$6 contains grammar for local variables and process() function generates a table for storing the details of the local variables.
$7 should only be executed after process($6?) has been executed.
However when I run my code, $7 runs before process($6?). I don't know why this happens, is this an LR parsing thing or a mistake from my side? the process() is critical here.
I'm really sorry but I'm going to struggle to debug with this sort of information. Either (preferably) I need a self-contained minimal example or (if that's not possible) a complete repository where I can compile and run code.
https://github.com/madhavpcm/rexpl, here is the repository of the codebase im working on.
try cargo run -- input.expl
in the src folder.
Also, when I use rust-gdb I cant goto the stack frames of the parser rust code.
in parser.y
//this is the intended order of execution
let ldecl_ = $6.map_err(|_| ())?;
__gen_local_symbol_table(&ldecl_, &ParamList::Null);
let body_ = $7.map_err(|_| ())?;
however this gives the same output as the current state in the repo.
I think I see what you're asking for:
$6 contains grammar for local variables and process() function generates a table for storing the details of the local variables.
$7 should only be executed after process($6?) has been executed.
In essence, all of the $
variables are assigned values before the user's code is executed. You can see this by putting log::info!
calls into LDeclBlock
and BeginBlock
.
I think I see what you're asking for:
$6 contains grammar for local variables and process() function generates a table for storing the details of the local variables. $7 should only be executed after process($6?) has been executed.
In essence, all of the
$
variables are assigned values before the user's code is executed. You can see this by puttinglog::info!
calls intoLDeclBlock
andBeginBlock
.
Yes I just noticed it. I misinterpreted some things and apologize for the confusion. I may have figured out a fix for my situation.
In essence, all of the $ variables are assigned values before the user's code is executed. You can see this by putting log::info! calls into LDeclBlock and BeginBlock.
Can we override this somehow ? Otherwise I think this issue can be closed.
Thanks Alot again!,
Can we override this somehow ?
There's no current mechanism, and it would be difficult to do so: grmtools would more-or-less need to read your mind!
FWIW, my preference is not to do as much in action code as you're doing. I prefer to create a minimal Abstract Syntax Tree in action code, and then have a later step which translates the AST into something else. This gives me much more control over evaluation order, and allows me to do things in a different order than dictated by the grammar. You can see a simple example of this in pizauth (https://github.com/ltratt/pizauth/blob/master/src/config.y, https://github.com/ltratt/pizauth/blob/master/src/config_ast.rs, https://github.com/ltratt/pizauth/blob/master/src/config.rs) or a more complex example in yksom (https://github.com/softdevteam/yksom/tree/master/src/lib/compiler).
Best of luck!
I have this grammar to detect main function in a language and BeginBlock($7) contains the statement list. However I have a declaration block just before the beginblock called LDeclBlock($6). The problem which I face with this input is that, BeginBlock's actionbody is being executed before LDeclBlock's action body. Shouldnt LDeclBlocks action body be only called if I use
let body = $7?
in the action body ? So any local definitions are termed invalid while verifying body block (Because those variables are not pushed to the Local Symbol Table of the function). Is this supposed to happen with LR parsers? If not, am I missing something here?