The Load/Unload Grammar
The motion grammar describes the Load/Unload scenario from Dantam1. The point of this very simple grammar was not to show how motion grammars work, but rather the expressiveness of a CFG (compared to a regular grammar), but it is very simple, so it serves as a starting point.
The grammar comprises three parts.
MotionGrammar contains generic nonterminals present in every motion
LoadUnload has the actual nonterminals of the grammar, and
World describes the context within which the
grammar is parsed.
Execution (Parsing) and Implementation Details
Currently, the parser reads a sequence of
Full tokens and loads a
Container with up to ten
There are no attributes used so far, but at each point where a semantic action takes place, the AST is printed to a file
src/gen/resources/diagrams/parsing, demonstrating the "available" part of the AST, which could be used by
attributes. This trace is shown here.
- Tokens can have semantic actions. This might be a difference to the original motion grammar concept, but could easily be simulated by adding another nonterminal enclosing each token.
Loadtoken currently can always be parsed. This is problematic, since it requires a fixed order in the parser rule for
T. A workaround would be to introduce a new token
NotFullbefore the load token.
- The parser
Worldparser.javauses three kinds of parse methods:
parsedistinguishes an abstract rule (for
T, but since it is the entrypoint, it has this generic name). This only works like this if the abstract rule does not have any elements, which can be achieved by a simple transformation, but maybe breaks the attribute part of the grammar. This method needs a lookahead, which is done by a peek method. The peek method actually parses the next token and keeps it in a cache, which is read by the token parse method later.
parseT2do not need lookahead.
- There are no thoughts on parsing lists and optional children yet.
Dantam, N., Stilman, M., 2013. The Motion Grammar: Analysis of a Linguistic Method for Robot Control. IEEE Trans. Robot. 29, 704–718. https://doi.org/10.1109/TRO.2013.2239553 ↩