Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

First pass at redesign of parser

Sign in to follow this  


OK this is what I came up with at work:

My basic plan is to have one class that parses through the input buffer and puts each word into a vector. It then finds the token for each word.

There is another class which holds the noun and verb and uses them to call an action.

All the verbs are instances of general verb classes inherited from the base class verb. The base class verb contains the virtual function activate. This function is overridden in each verb type class to perform the specific actions of the verb typ (like attack, add to inventory etc.).

All the pointers to the verb instances through the base class are contained in a vector. The verb token number can be used to access them through their index. The noun token is passed to the activate function so the object can be manipulated by the verb function.

Buffer-contains the input
whitespace-contains the whitespace characters
word[]-vector of words parsed from buffer
token[]-vector of tokens taken from the words
Parse[Buffer,#]-returns a word
GetToken[word[]]-returns a token for the word

inTokens[]-vector of the tokens parsed from input

getVerb: iterate through inTokens to get the verb
getNoun: iterates through inTokens to get the noun
action: takes the tokens as input and calls the verb class function activate using the verb token as the index to th array of pointers to verbs

There will also be a base class Verb and verb type classes inherited from it.

There will also be a dictionary that can be used to find the tokens and a Noun base class with different nouns.

Well I am just beginning on all this and may be going about it all wrong so I would aprecciate any comments.
I know my plan may not be very clear but I will be working on it more in the next few days.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!