Code Monkey home page Code Monkey logo

Comments (7)

ltratt avatar ltratt commented on June 12, 2024

Can you cut the example down a bit so I can understand it more easily please?

from grmtools.

madhavpcm avatar madhavpcm commented on June 12, 2024

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.

from grmtools.

ltratt avatar ltratt commented on June 12, 2024

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.

from grmtools.

madhavpcm avatar madhavpcm commented on June 12, 2024

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.

from grmtools.

ltratt avatar ltratt commented on June 12, 2024

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.

from grmtools.

madhavpcm avatar madhavpcm commented on June 12, 2024

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.

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!,

from grmtools.

ltratt avatar ltratt commented on June 12, 2024

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!

from grmtools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.