Skip to content

New Parser #42

Open
Open

Description

@Toyz

The new Parser has a flaw in it's design as turtle graphics support float values and we cannot actually handle those currently...

Also the new way to add commands can be clunky at times and yield some issues with newer people wanting to contribute as there's no comments to what things are

Activity

  1. EyLuismi commented on Nov 10, 2018

    @EyLuismi
    Contributor

    Also the new way to add commands can be clunky at times and yield some issues with newer people wanting to contribute as there's no comments to what things are

    Yeah, I was thinking the same, what are your thoughts? First, I think maybe moving the commands definitions to another file would be a good Idea, and then in the readme I would explain with examples how you could add a new command arg type, or a command itself.

    Also, of course, more description in the code never hurts. I can prepare a PR about this.

  2. EyLuismi commented on Nov 12, 2018

    @EyLuismi
    Contributor

    @Toyz In order to close this Issue, do you think that we would need to insert in the readme or myabe in some contribution guide, how to insert a new command? I mean, descriptions do help, but I think we could make a straightforward tutorial.

    Also now there is something about validators and expressions I want to dig in :P

  3. Toyz commented on Nov 14, 2018

    @Toyz
    ContributorAuthor

    We probably show insert into the contributions file regrading it

  4. rhdunn commented on Nov 15, 2018

    @rhdunn

    I was thinking of using something like the original part 1 implementation. My rationale for this is that logo is a relatively simple language that requires tokens to be space separated.

    Lexer

    1. Split on spaces
    2. If the text is a number parse it to a number object -- this can support float values
    3. Anything else (including "[" and "]") is a string object, and is thus a keyword

    There is nothing more complex in terms of tokens in logo.

    Parser

    1. Parse the tokens into a command array.
    2. Parse "[" ... "]" into a command array -- so the repeat command will take a command array as an argument.
    3. Each command is an object with a name and arguments (number tokens or a command array ("[" ... "]")), so parsing a command stops at a command name token.
    4. Return the top-level command array as a repeat 1 [ commands ] command.

    Interpreter

    1. A commands object where the keys are the command name, and the value is a function taking the argument array.
    2. An interpret helper function for looking up the command and calling it with the given arguments for each command in a command array.

    Thus, repeat could be implemented like:

    "repeat": function (arguments) {
        let n = arguments[0];
        while (n > 0) {
            interpret(arguments[1]);
            --n;
        }
    },
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions