Giter VIP home page Giter VIP logo

migraine's People

Contributors

marcofiset avatar

Stargazers

 avatar

Watchers

 avatar  avatar

migraine's Issues

Functions - Phase 1

At first :

  • Functions will not support arguments,
  • Return keyword will not be supported, the last expression will be the result of the function.

Add and implement the following grammar rules :

  • FunctionDefinition = "fun", Identifier, "(", ")", Block
  • Block = "{", ExpressionList, "}"
  • FunctionCall = Identifier, "(", ")"
  • IdentifierList = Identifier, { ",", Identifier }
  • ArgumentList = Expression, { ",", Expression }

Refactor parser tests

Or skip them altogether and test the whole thing (Lexing + Parsing) once it is completed.

Make the input source and output destination a parameter

For the moment, input and output for the brainfuck interpreter uses the Console and there is no way to change that. Make it so input source and output destination are dynamic. Use an interface, something along those lines :

public interface IInputOutputProvider
{
    string GetInput();
    void WriteToOutput(string value);
}

Change TokenStream.Consume to return a Boolean instead of throwing an exception

This pattern is used everywhere in the parser :

//Test for the token
if (CurrentToken.Type == TokenType.Number)
{
    Double termValue = Convert.ToDouble(CurrentToken.Value);
    tokenStream.Consume(); //Consume it
}

It could be simplified as :

//Consume the token if it meets the criteria and return true. False if wrong token.
if (tokenStream.Consume(TokenType.Number))
{
    //Use the ConsumedToken function to get back the token we just consumed,
    //because CurrentToken will no longer hold the value we want.
    Double termValue = Convert.ToDouble(ConsumedToken.Value);
}

This will require to implement a ConsumedToken function on TokenStream which will hold the last consumed token.

If we want an exception to be thrown, use the to-be-implemented Expect method instead.

Make it possible to pre-supply input to the interpreter

The check-box and textbox are available to pre-supply input, but they are not supported yet.

In MainViewPresenter, do not delegate to the view to get input. On program execution, the presenter should ask the view for any pre-supplied inputs and store them in a queue. If no more input in the pre-supply list, then you should ask the view to get input.

Support for variables

What is a programming language without variables?

Here are the steps required to implement variables :

  • Create an IdentifierNode class which will hold the name of the variable
  • Add a Terminator TokenType which will separate different expressions
  • Add = to the list of operators
  • Add ParseExpressions method which will parse multiple ExpressionNode each separated by a Terminator token.
  • Add ParseIdentifier and ParseAssignment methods

Use a real grammar for the expression evaluator

Currently, I use the shunting yard algorithm for evaluating expression. This is not a very extensible solution if I want to build a complete programming language. I must now define a grammar and write a recursive descent parser for it so I can add functionnality easily in the grammar and parser. This will be the first step before proceeding to implement the language.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.