Sign in to follow this  
  • entries
    5
  • comments
    2
  • views
    2506

First pass at redesign of parser

Sign in to follow this  

254 views

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.

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

TakeAction
Data:
verbToken
nounToken
inTokens[]-vector of the tokens parsed from input

Functions:
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  


0 Comments


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