Coder Social home page Coder Social logo

sernick's People

Contributors

aleksanderkatan avatar bartlomiejbloniarz avatar dembanakh avatar erheron avatar jwajgelt avatar kaliciak avatar krzysztofziobro avatar lukaszselwa avatar oloiwojo avatar ssalabura avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

sernick's Issues

Implement type checking

Implement type checking.
The inputs are the AST of the program, and the result of name resolution.
The result is a mapping Expression (ASTNode) -> Type, defining the type for each expression.

The possible errors are:

  • using a variable of wrong type (check assignments, operators, function calls...)

Add the type checking step to the compiler frontend

[Regex] Implement regex normalization in factory methods

  • Factory methods:
    • static Regex.Atom(char): Regex
    • static Regex.Union(IEnumerable<Regex>): Regex
    • static Regex.Concat(IEnumerable<Regex>): Regex
    • static Regex.Star(Regex): Regex)
  • Normalization
    1. X \cup X == X
    2. X \cup Y == Y \cup X
    3. (X \cup Y) \cup Z == X \cup (Y \cup Z)
    4. \empty \cup X == X
    5. \neg\empty \cup X == \neg\empty
    6. (XY)Z == X(YZ)
    7. \empty * X == X * \empty == \empty
    8. \eps * X == X * \eps == X
    9. X^^ == X^
    10. \eps^ == \empty^ = \eps
    11. \neg(\neg X) == X

Test Sernick syntax

Based on our Language notes in #1 , let's divide test into 8 roughly equal parts:

  1. Test types and naming of types/variables/functions -- @bartlomiejbloniarz
  2. Test functions -- naming, readonly arguments -- @aleksanderkatan
  3. Test functions -- argument types, default value syntax @krzysztofziobro
  4. Test control flow -- if/else -- @jwajgelt
  5. Test Loops -- @ssalabura
  6. Test comments and line separators -- @Kaliciak
  7. Test blocks of code -- grouping by {} and (), introducing new scope only by {} -- @LukaszSelwa
  8. Variable declaration/initialization syntax -- @dembanakh

Each part/suite should contain not less than 5 good and 5 bad examples of code (remember, we use .ser extension)

[Regex] Implement Equals and GetHashCode methods

Implement Equals and GetHashCode methods for every class inheriting from Regex class (AtomRegex, StarRegex, UnionRegex, ConcatRegex).
Methods assume that Regexes are normalized and compare them structurally.

[IInput] Change IInput interface and modify implementation of StringInput

Change IInput Interface and change StringInput implementation,

IInput proposition

public interface IInput
{
    /// <summary>
    ///     Advances input to the next element.
    ///     Upon creation input is positioned on the Start location.
    /// </summary>
    /// <returns>
    ///     false if after execution input's location points to End;
    ///     true otherwise 
    /// </returns>
    bool MoveNext();
    
    void MoveTo(ILocation location);
    ILocation CurrentLocation { get; }
    
    /// <summary>
    ///     Returns the location of the first char in input.
    /// </summary>
    ILocation Start { get; }
    
    /// <summary>
    ///     Returns location after the last character in input.
    /// </summary>
    ILocation End { get; }
}

[Parser] Implement factory method of `Parser`

The method takes a Grammar and prepares all data needed for the constructor call:

  • Converts Grammar into a DfaGrammar
  • Performs an analysis of it (computes Nullable, First and Follow sets)
  • Computes reversed automata of given productions

Construct map of functions' variable access

Provide implementation for visitor VariableAccessVisitor, it should (based on AST) construct VariableAccessMap which can:

  • For a specified function output all it's variable accesses along with mode (Read/Write)
  • Check if a function has exclusive write access to a variable

Integration tests

Write integration tests checking the example sernick programs checking for:

  • parser errors
  • name resolution errors
  • type checking errors
    By passing the programs to the compiler frontend once these parts have been implemented.

[DFA] Implement RegexDfa

Implement and test public methods of RegexDfa class.
RegexDfa should work as described in the first lecture (please see slides "Alternatywna Konstrukcja RE -> DFA")

[Week3] Add base API

  • Add Diagnostics and Diagnostic classes (+Severity enum)
  • Separate frontend and backend stages
  • Add compiler's main function
  • Add ASTNode base class
  • Add Grammar<TSymbol> and Production<TSymbol> classes
  • Add DfaGrammar<TSymbol, TState> class
  • Declare .Nullable(), .First(), and .Follow()

Write the signatures for `ASTVisitor` methods.

For each type NodeType implementing ASTNode, add a method public TResult visitNodeType(NodeType node, TParam param), with the default implementation delegating to visitNodeSuperType(node, param), where NodeSuperType is the immediate supertype of NodeType in the ASTNode types' hierarchy.

[Grammar] Add tests for `Nullable`, `First` and `Follow`

Test these three methods separately - i.e. for the test grammar

  1. Compute NULLABLE manually
  2. Test that grammar.Nullable() generates a correct set of symbols (=NULLABLE)
  3. Compute FIRST(A) manually
  4. Test that grammar.First(NULLABLE) generates a correct function of symbols (=FIRST(A))
  5. Compute FOLLOW(A) manually
  6. Test that grammar.Follow(NULLABLE, FIRST) generates a correct function of symbols (=FOLLOW(A))

[Grammar] Create Sernick Grammar

Consult StringToRegex API and create Regular Expressions for categories needed in Sernick.
Decide how we store categories (Enum or classes inhering from abstract category class).

We need categories for:

  • Keywords
  • Variable identificators
  • Type identificators
  • Code blocks brackets
  • Operators

We will probably have to decide on categories priorities (eg, that keywords have bigger priority then identificators)

[Regex] Implement StringToRegex

Consult and implement API of StringToRegex class

  • it should simplify the process of defining more complex regular expressions
  • use Regex static methods to build RegularExpression

[Grammar] Sernick grammar is not SLR

How to reproduce:

  • Run CompilerFrontendTest.cs tests

Issue:

  1. There is a production cycle Expression -> X1 -> X2 -> X3 -> Expression
Shift/reduce conflict between symbol Semicolon(;) and production X3 -> Expression | X3*BinaryOperatorPriority3*Expression

Prepare a hierarchy of `CodeTree` nodes

Prepare a hierarchy of CodeTree nodes such that they represent all low level operations sufficient to represent sernick's functionality (without control flow).

[Frontend] Add `LexicalError` reporting and test pipeline

  1. Add LexicalError : IDiagnosticItem { Start, End: ILocation }
  2. Modify Lexer.Process() so that it reports any error it finds to diagnostics
  3. Test Frontend
    • implement ReadFile method in Utility.FileUtility
    • create a FakeDiagnostics class, which makes checking if some specific error was reported easier
    • create a helper method, which accepts a file name (*.ser), reads its content into IInput, executes a frontend compilation pass, and returns a FakeDiagnostics object
    • using that helper method, test some small sernick programs against our compiler

[Frontend] Implement `Diagnostics` and `main()` function

  1. Implement Diagnostics class
  2. Implement initial frontend compilation pass
    • call Lexer
    • react to any critical (or non-critical) errors reported
  3. Implement compiler's entry point in Main.cs (mind that C# doesn't require explicit main() function)
    • receive file name to be compiled
    • read file contents into IInput
    • call frontend

[Parser] Add tests for `Parser`

Test the implementation of Parser using simple grammars and inputs and compare the resulting ParseTree to what is expected.

Implement name resolution algorithm

For each use of a variable x, we need to know where that variable was defined (either via a new variable binding var x, or a function parameter binding fun f(x){...}).
For each function call f() we need to know where that function was defined.

The result of the name resolution are three mappings:

  • variable use -> variable declaration | function parameter
  • variable assignment -> variable declaration
  • function call -> function declaration

Note: the variable and function names live in the same namespace - new function declarations can shadow variable declarations from previous scopes, and the other way around. It's illegal to declare a function and a variable using the same identifier in a single scope.

Errors to be returned:

  • multiple declarations of same identifier (variable or function name) in one scope
  • use of undeclared identifiers
  • use of a variable name as function or a function name as variable

To be implemented using the ASTVisitor, using the functional algorithm presented at the lecture.

Add the name resolution step to the compiler frontend.

Modify AST so every declaration is inside some funtion (make "main" a function)

Currently in our AST we have some of our variable declarations outside any function, which won't work well with our approach.
So, there is a need to somehow change AST so the whole body of the program will be treated as a function, my proposal:

  • convert to AST
  • wrap the whole resulting Expression into a FuctionDefinition (probably named "" [empty string])
  • make new expression consisting only of main FunctionDefinition, and main FunctionCall

[Lexer] Implement Lexer

Implement Lexer class

  • Do it according to the alternative lexer construction presented on the first lecture (RE -> DFA)
  • Decide how do we deal with conflicts (prioritise categories/return every possible category for token), this will probably require to change Lexer API a bit

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.