Closed purpleidea closed 7 years ago
yes, ofcourse, you may derive a new class of Lexer, just call it type NewLexer struct { *yyLexer; myAST interface{}, }
pass the NewLexer instance into yyParse
so, in the parser.y, you should write lines like below: top: prog { myLexer, _ := yylexer.(*NewLexer) myLexer.myAST = $1.prog }
@wolfkdy Thanks for your response. I tried this sort of thing, but due my stupidity, I seem to have failed. Is there a full working example somewhere that I can try? I couldn't get the above integrated and compiling.
Thanks!
@wolfkdy Still haven't figured this out, since while I could define a new struct, how do I pass in the stdin, etc...
Okay, figured it out. Will post a full solution if I remember to shortly. There's a broken example in https://github.com/blynn/nex/tree/master/tacky which I modified to use .parseResult
instead of .p
in my code, and got it all working. I assume that @blynn didn't test his code before committing the example, but it looks as if the parseResult
is meant for this usage, since it isn't used elsewhere.
Is this possible? Currently I have to do something like:
in parser.y:
in main.go:
I know it's not directly nex related, but I was hoping someone here might know! Thanks :)