building parser for a project
Budget: $30 – $250 USD
I already have a project which generates tokens and then those tokens are passed to the parser which processes the tokens. I can send the code if you feel you are capable to work on the project. PLEASE READ THE PROJECT DESCRIPTION BELOW
Here is what needs to be changed and added:
In my parser, we don’t have a mechanism to process statements yet. We will look for expressions inside of our functions so that indent and dedent will work (they won’t be output on empty lines, remember).
The model of recursive descent should suggest some methods, here:
function() processes a function. It expects a define token. Then an identifier (the name). Then a left paren. Then a list of 0 or more variable declarations. Then a right paren. Then an endOfLine. Then constants and variables. Then an indent. Then statements. Then a dedent. It returns a FunctionNode or null.
parameterDeclarations() process the parameters and returns a collection of VariableNode. Remember that a parameter may or may not be var. Remember that there may not be any parameters.
You can process constants and variables in one function or two (your decision). function() should call this function / these functions until there are no more. There is no strict ordering – you can have variable lines and constants lines intermixed.
Constant parsing needs the logic we used in factor for determining negative and integer or float (based on number). It also needs to account for char, string and boolean (by looking for the relevant tokens – true, false, characterLiteral, stringLiteral). Making helper functions will be beneficial here.
function() should expect indent, then call expression() until it returns null and print the resultant expressions (just to make sure that the parsing is still correct) then expect dedent. Since the expressions are just temporary, we won’t store them in our FunctionNode().
parse() should call function() in its loop. Every FunctionNode returned should go into the ProgramNode (there will be only one of these). null should end the parse() loop. parse() should return the ProgramNode.
and at the end, In main, where parse() is called, you should get the ProgramNode and print every FunctionNode (which will print the parameters, variables, and constants). This should give you a full view of the parse tree so far. The expressions were previously printed and will be out of order
Here is what needs to be changed and added:
In my parser, we don’t have a mechanism to process statements yet. We will look for expressions inside of our functions so that indent and dedent will work (they won’t be output on empty lines, remember).
The model of recursive descent should suggest some methods, here:
function() processes a function. It expects a define token. Then an identifier (the name). Then a left paren. Then a list of 0 or more variable declarations. Then a right paren. Then an endOfLine. Then constants and variables. Then an indent. Then statements. Then a dedent. It returns a FunctionNode or null.
parameterDeclarations() process the parameters and returns a collection of VariableNode. Remember that a parameter may or may not be var. Remember that there may not be any parameters.
You can process constants and variables in one function or two (your decision). function() should call this function / these functions until there are no more. There is no strict ordering – you can have variable lines and constants lines intermixed.
Constant parsing needs the logic we used in factor for determining negative and integer or float (based on number). It also needs to account for char, string and boolean (by looking for the relevant tokens – true, false, characterLiteral, stringLiteral). Making helper functions will be beneficial here.
function() should expect indent, then call expression() until it returns null and print the resultant expressions (just to make sure that the parsing is still correct) then expect dedent. Since the expressions are just temporary, we won’t store them in our FunctionNode().
parse() should call function() in its loop. Every FunctionNode returned should go into the ProgramNode (there will be only one of these). null should end the parse() loop. parse() should return the ProgramNode.
and at the end, In main, where parse() is called, you should get the ProgramNode and print every FunctionNode (which will print the parameters, variables, and constants). This should give you a full view of the parse tree so far. The expressions were previously printed and will be out of order