This project has moved and is read-only. For the latest updates, please go here.

equivalent of ParserState.ExpectedTerminals when the parse was successful? (aka, OptionalTerminals)

Aug 1, 2012 at 4:11 PM

For my intellisense-like operation I'm using ParserState.ExpectedTerminals to determine the possible options. However, in the situation where my grammar parses correctly but there are still remaining optional (.Q) terminals, is there any way to determine the left-over optional terminals?

Aug 1, 2012 at 6:47 PM

don't quite understand the question, particularly '...still remaining optional terminals.' Remaining - where? what terminals? Pls show an example

Aug 2, 2012 at 3:23 PM

To explain the question a little more, suppose this grammar:

velocity := NumberLiteral
unit := ToTerm("mph") | ToTerm("m/s")
row := velocity + unit.Q()
row |= Empty
program := row* 

As the unit is not required, a row with a number and no unit will parse correctly. However, I want to query for the list of possible units. 

Aug 6, 2012 at 4:26 AM

define unit as optional from the beginning (instead of doing unit.Q()):

unit.Rule = ToTerm("mph") | "m/s" | Empty;

Then unit will always be present in parsed row, just sometimes it would have no child tokens. But you can retrieve the terminal itself and find out possible values from its Rule.


Aug 14, 2012 at 10:42 PM

You say "retrieve the terminal itself". Given a ParseTree object, how do I know which terminal I finished at? Is it Root.ChildNodes.Last().Last().Last().... ?

Aug 14, 2012 at 11:23 PM

what do you mean by 'finished at'?

ParseTree.Root is the top-level ParseTreeNode, the root. Something like "Program" non-terminal, whatever you set to Grammar.Root.

Any parseTreeNode has a property Term that identifies Terminal or non-terminal (grammar element) from the Grammar.

You can traverse the tree and find all "unit" elements (just check the node.Term).

Aug 14, 2012 at 11:39 PM

By "finished at" I mean the very last token in my parsed result. This corresponds to the very last text in the input.

Aug 16, 2012 at 5:45 AM

if the last is last-by-position, then you can just use the search function used by Locate button in Grammar Explorer - locates nodes by position