Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411469 Posts in 69368 Topics- by 58422 Members - Latest Member: daffodil_dev

April 23, 2024, 03:18:42 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Recursive Descent Parser
Pages: [1]
Print
Author Topic: Recursive Descent Parser  (Read 671 times)
DrDerekDoctors
THE ARSEHAMMER
Level 8
******



View Profile WWW
« on: February 17, 2017, 09:46:08 AM »

Has anyone here written one in C++? I need to make one for my game to basically just evaluate nested logical expressions. i.e. stuff along the lines of:

((a == 2) && (b > 2)) || c == 1

And turn that into a nice tree data structure (so that it can be evaluated repeatedly without re-parsing).

But I'm struggling to find a good source document to learn how to make one. It should be suitable for thicky-thickersons like myself.

Anyone?
Logged

Me, David Williamson and Mark Foster do an Indie Games podcast. Give it a listen. And then I'll send you an apology.
http://pigignorant.com/
qMopey
Level 6
*


View Profile WWW
« Reply #1 on: February 17, 2017, 10:07:14 AM »

Ya I've done exactly that in C. Let me dig it up... Here it is: http://www.randygaul.net/2015/06/15/parsing-c-style-expressions/
Cheers  Waaagh! Toast Right
Logged
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #2 on: February 17, 2017, 11:05:51 AM »

Is this for users to use, or to aid in your own development of the game? If the latter, use a scripting language, like Lua, instead. You'll get all the benefits, plus more, and it's easier than writing your own parser.

There's also lots of generators that will create a parser given the grammar definition. But they often a hassle in their own right.
Logged
oahda
Level 10
*****



View Profile
« Reply #3 on: February 17, 2017, 12:32:25 PM »

I might recommend going with Boris's suggestion if it makes sense for what you're doing. Otherwise, here's a great set of tutorial that I found recently and posted in the happy programmer room: https://ruslanspivak.com/lsbasi-part1/ c:
Logged

DrDerekDoctors
THE ARSEHAMMER
Level 8
******



View Profile WWW
« Reply #4 on: February 17, 2017, 02:11:22 PM »

Cheers all! I've thought about LUA in the past, maybe I'll look into it again, though, as it would obviously give more flexibility.
Logged

Me, David Williamson and Mark Foster do an Indie Games podcast. Give it a listen. And then I'll send you an apology.
http://pigignorant.com/
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic