Git Product home page Git Product logo

vork's Introduction

Vork

Vork will eventually be a fully fledged V implementation.

Right now it is just a parser, once I get a full parser then I will start working on code gen.

Example

for now all that it does is read in a file and try to parse it. Right now there is no error recovery on a syntax error, but there is a nice printout so you can hopefully understand what went wrong.

The parse output will be printed and is formated in a lisp like way

fn fib(n int) int {
        if n <= 1 {
                return n
        }
        return fib(n - 1) + fib(n - 2)
}

fn main() {
        i := 0
        for i = 0; i < 10; ++i {
                println(fib(i))
        }
}
(func fib ((n int)) int
  (block
    (if (<= n 1)
      (block
        (return n)))
    (return (+ (call fib ((- n 1))) (call fib ((- n 2)))))))
(func main () 
  (block
    (var (i) 0)
    (for (= i 0) (< i 10) (prefix ++ i)
      (block
        (call println ((call fib (i))))))))

Formal grammar

The lark file has an old formal grammar I defined which I am going to keep as a reference, maybe after finishing the hand written parser I will go back and rewrite the formal grammar to be updated.

hopefully by the done I am finished with the parser the (official) formal grammar will be out already ๐Ÿคท

Implemented

  • All binary and unary expressions
    • post fix operators are not added to the ast yet
    • Function calls can not take mut modifier to expression for now
  • Almost full type parsing support
    • missing function types
  • Functions, methods and interop functions
    • missing generics
    • missing multiple return value
    • missing auto wrapping of optional values
  • Module and Imports
  • Structs with their access modifiers
    • missing the base type
    • missing generics
  • asserts
  • if\if else\else
  • Most of the for loops
    • in c like for loops can not declare a variable at the start...
    • missing for with only condition (for true)
  • Constants
  • Variable declarations
  • Enums declarations
  • Integer, Float and arrays literals
  • or statement
  • Super basic type checking
    • missing mut checks
    • missing unsafe checks
    • missing access checks (pub)
    • missing implicit enum

Missing

  • string and map
  • interfaces
  • match
  • go statement
  • attributes
  • compile time if

Problems

Right now the parser ignores new lines completely, that is because from what I could see the official V compiler also does that, but in an inconsistent way... sometimes it ignores it and sometimes not...

for the most part it is not actually a problem, but specifically for the * operator it makes a problem, because it is used both for deref and for multipication

a := 123
b := &a
*b = 456

will not give the correct output!

the simplest way to get around it for now is to simply seround it with a block

a := 123
b := &a
{*b = 456}

but the real solution is to wait for a formal grammar and see how newlines should actually be handled.

note that this problem happens on any operator which may be used in both unary and binary way, including - and alike...

vork's People

Contributors

chaoscat avatar itay2805 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vork's Issues

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.