sholloway / agents-playground

MIT License
4 stars 0 forks source link

Simulation Console #51

Open sholloway opened 1 year ago

sholloway commented 1 year ago

I'd like to have an engine console similar to how Quake and the Valve engines provide.

Tasks

Commands

Nice to Haves

Questions

Implementation Thoughts

Naive Approach

Just split the string and use the String module to check for numbers. Then use a match statement and a factory pattern or command pattern to invoke things.

Write a Lexer and Parser

Take a look at Fowler's DSL book.

Options

  1. Leverage ANTLR to generate a lexer and parser. This approach involves creating a grammar and then generating the parser code. The parser be responsible for building up an Abstract Syntax Tree in memory. I would then need to have something take the AST and execute a python function. I might be able to register "hooks" on the parser to run commands automatically in a similar fashion to XSLTs or SAX parsers.

  2. Use the Lark Python module. This is designed to be embedded in an application and use a grammar to parse content. It can generate ASTs.

  3. Lrparsing is a parser generator that uses Python to define grammars.

  4. Ply is a Python module for defining lexers and parsers in Python code. Rather simplistic. This may be a good option for the console.

  5. PlyPlus is a Python module that expands beyond the capabilities of Ply.

  6. Pyleri another parser generator that defines rules using python code. A good choice for doing autocompletions.

  7. Arpeggio module generates simple parse trees but supports the use of a visitor.

  8. Canopy is a parser generator that can target python.

  9. Parsimonious is a python PEG parser that uses a simplified EBNF notation. Designed for speed and low RAM usage.

  10. pyPEG is a framework for parsing and composing text.

  11. TatSu is another python parser generator.

  12. Waxeye is a parser generator based on parsing expression grammars (PEGs). It supports C, Java, Javascript, Python, Ruby and Scheme. Very clean-looking grammars.

Use a Parser Combinator

Parser combinators enable creating a parser by combining different pattern-matching functions that are equivalent to grammar rules. They are considered best suited for simpler parsing needs.

  1. The Parsy module might work if I want to just do this in regex.
  2. Pyparsing is another option. However, it might not have good documentation.
  3. Reparse is another one that is even simpler.

Create a DSL

  1. TextX
sholloway commented 1 year ago

Hand Writing an Interpreter

After some research I'm leaning on creating an interpreter.

Recursive Descent with Prax President Operations seems viable. http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/