Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] Help me converting a Parser

Author
Message
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 25th Nov 2018 17:19 Edited at: 25th Nov 2018 17:25
Hi so I'm trying to convert a parser using this tutorial and I stuck.
Maybe I don't understand Phyton enough or the Parser itself anyway I fling my converted code at you and hope here is somebody who can make sense of it /the tutorial/phyton or parser in genral.
My lexer works and I'm stuck at line ~73 for the operation recursion
I know this is a broad quest and it might even fit better in another forum, anyhow...now you know what i'm at lately

The author of this post has marked a post as an answer.

Go to answer

puzzler2018
User Banned
Posted: 25th Nov 2018 17:45 Edited at: 25th Nov 2018 18:01
Hi

Im not fully understanding the code too , but id thought to share some thoughts


What it is not doing - is it hanging? is it giving bad results? - is it stopping with an error?

The function NextExpression needs to have some data in the 2nd parameter maybe
and the EmptyToken doesnt seems to gain any info but TempTokenArray does



The one before it



Sends ResultToken in - which has data assigned in the type

Maybe perhaps change EmptyToken to TempTokenArray

i might be totally wrong, but just giving some thoughts

EDIT - I tried to use your whole snippet and i just get hundreds of compilation errors too.
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 25th Nov 2018 18:07 Edited at: 25th Nov 2018 18:13
Oh thanks, well
Quote: "What it is not doing - is it hanging? is it giving bad results? - is it stopping with an error?"

Nothing of the above.

There is this line in Phyton: return self.next_expression(("operation", value, prev, nxt))
It has 4 parameters but the function should only take the "self" and "prev" parameter...I just stopped converting there as I couldn't get my head around it(now/since the last 3 days)
I tried to cover "self" with the Parser Parameter.

Also this line: arg_parser = Parser(self.tokens, (sep, end))
It clearly creates an object of the class "Parser" so it calls the constructor of the class but this again only takes (self, tokens, stop_at).
I guess the braces around (sep, end) combine the two parameters ?!?
Is "stop_at" optional ?
I probably should look into phyton ..but maybe you can save me from that
puzzler2018
User Banned
Posted: 25th Nov 2018 20:10
A possible version that i can interpret




Maybe not what your looking for but hope it helps in some way
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 26th Nov 2018 09:06 Edited at: 26th Nov 2018 09:11
Maybe you can find something useful in here, it's quite old and can be simplified at some points.


+1 if we could get an actual implemented parser with c++ speed. At least over a plugin
May I ask why you need a parser?

[/url]
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 26th Nov 2018 11:41 Edited at: 26th Nov 2018 11:43
Yeah I also thought about wrapping the gnu parser for agk but I also like the idea to provide ALL the code for my project.
That said I want to takle the node based shader editor idea.
And I also want to being able to import shader code and create the nodes from it.
Not sure if other node shader editors have this feature.
I tried to create a parseer already thats why the creation date is 2015
But again not promise anything.

I had no time looking at the code but i will today.
Thanks
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Nov 2018 11:46
On the issues with self.next_expression(("operation", value, prev, nxt))
I thought it might be passing a structure/class because there are double brackets. Still doesn't fit because it requires two parameters
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 27th Nov 2018 02:08
Quote: "self.next_expression"


One of the more wacky things about python:

Do include self in the method declaration
Don't include self in the method call (it is injected internally)

So even though it is defined with 2 parameters, you are only expected to pass it one, because it will add the first, a reference to the calling object,
automatically and internally.

def next_expression(self, prev):

You would call this with just prev: "next_expression takes one argument, prev, that represents the progress we have made parsing so far. "

So, it looks like it is expecting a subset of tokens which have already been processed.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 27th Nov 2018 15:35 Edited at: 27th Nov 2018 16:36
So self "is already there"... and in my code i tried to represent "self" with "Parser" and thought "prev" is of type token but it doesn't need 4 "attributes" as in the phyton code.
Am I missing something ? can you make an example how you would create the datatype and function call then ?
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 27th Nov 2018 23:06 Edited at: 27th Nov 2018 23:22
So it looks like what it needs from self is the list of tokens and the stop character these can be passed as arguments directly,

prev appears to be a tuple, an arbitrary list of arbitrary objects and datatypes whose contents can change between recursive calls. Agk doesn't really have a good translation of this data structure and how it is used here, but I think we can work it out. I will play around with it a bit tonight
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 28th Nov 2018 05:16 Edited at: 28th Nov 2018 05:32
This post has been marked by the post author as the answer.
Here is some progress I think. it needs to be cleaned up and i left the multiple expressions as a stub, but it is producing the basic nested tree structure

i have a feeling that from here, rather than trying to emulate a tuple, it may be easier to parse everything into json which could possibly be converted to an agk typed array, and will definitely be easier to work with for further text processing evauluations



http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.

Attachments

Login to view attachments
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 28th Nov 2018 16:46
Its Great !
You even adopted the coding style for me
Didn't expect to get actually working code I will bear the json array in mind , thanks Ortu.
And thanks everyone else of course

Login to post a reply

Server time is: 2024-11-23 12:08:53
Your offset time is: 2024-11-23 12:08:53