12 Replies - 6463 Views - Last Post: 17 September 2011 - 05:25 AM

#1 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Project Mizu: Concept programming languages with a .NET compiler

Posted 17 August 2011 - 05:51 PM

Okay, so this isn't the first time I made a topic about a programming language. That was the past (and mostly) childish attempts. A couple of weeks ago, I decided to get serious about my projects. Building a compiler has been on my todo list for a very long time so I decided to buckle down and build one.

Since this is my first real compiler, I wanted to start off with a simple language. So, I created a simple esoteric programming language (its not turing complete though) that was inspired by Fortran and BrainF*ck.

Lets take the following VB:
Public Class App
    Public Shared Sub Main()
        Dim x As Integer = 5
        Dim y As Integer() = {1,2,3,4,...} '1 through 10
        For Each num As Integer in y
            Dim result As Integer = 2+(x*num)
            Console.Writeline(result.ToString())
        Next
    End Sub
End Class



If I wanted to write that in Mizu, it would go something like this:

x`5|y`[1..11]|?z:2+(x*y)|.z



Yes, I know this language is not practical, but the point is... I made a compiler. The compiler even emits debugging information so you can debug your exe via VS:

Attached Image

Now, how I generate IL and the executable is simple. I use the System.Reflection.Emit namespace.

I used a tool called TinyPG to generate my scanner/parser combo.

I used the tool called Peverify (included with VS) to verify my IL.

Let me know what you think or if you have any questions. You can find the source code here. Oh and I plan on making this into a tutorial. More information is on the README.

This post has been edited by Amrykid: 05 September 2011 - 01:01 PM


Is This A Good Question/Topic? 3
  • +

Replies To: Project Mizu: Concept programming languages with a .NET compiler

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9572
  • View blog
  • Posts: 36,244
  • Joined: 12-June 08

Re: Project Mizu: Concept programming languages with a .NET compiler

Posted 17 August 2011 - 05:57 PM

Super sweet! So... like I have this mortgage calculator assignment I need to write in Mizu - can you gimme the codez? It's not working and junk.

;)

Good job!
Was This Post Helpful? 1
  • +
  • -

#3 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Project Mizu: Concept programming languages with a .NET compiler

Posted 17 August 2011 - 06:12 PM

Heh, It doesn't work that way. I did not write a way to access input from stdin... although... thats a good idea.
Was This Post Helpful? 0
  • +
  • -

#4 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Project Mizu: Concept programming languages with a .NET compiler

Posted 18 August 2011 - 03:17 PM

In today's commit, I added support for multi-line code and reading from stdin (Console.ReadLine).


c`^|a`5
b`[1..99]
?res:2+(2+3)+(b*a)
.res
.c


Was This Post Helpful? 0
  • +
  • -

#5 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Project Mizu: Concept programming languages with a .NET compiler

Posted 20 August 2011 - 11:31 AM

In case anyone wanted to try out Mizu, here is a zip containing the binaries.

Zip -> https://github.com/d...u_1.0.218.0.zip

Source -> https://github.com/A...ball/v1.0.218.0

I would like to state that this syntax is only a concept for Mizu. Mizu2 (short for Mizu Concept 2) will have a more OO-styled syntax.
Was This Post Helpful? 0
  • +
  • -

#6 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Project Mizu: Concept programming languages with a .NET compiler

Posted 23 August 2011 - 07:43 AM

Mizu is on its way to becoming usable. I have finished a script that performs the Pythagorean theorem.

a`^~
b`^~
?a2=a*a
?b2=b*b
?c=a2+b2
%(c)
.c



a`^
means declare a variable named 'a' and get its value from Console.ReadLine. The optional ~ after it merely prints the variable name using Console.Write.

Quote

a = *data from Console.ReadLine is entered here*


EDIT:
Forgot to mention, I have implemented a few more things.

  • Format strings can be passed to the print statement:
    .$"I have {0} cans of soda and {1} cups." a 3
    

  • You can use Square Root via the % symbol.
    var`81|%(var)|.var
    

This post has been edited by Amrykid: 23 August 2011 - 08:41 AM

Was This Post Helpful? 0
  • +
  • -

#7 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Project Mizu: Concept programming languages with a .NET compiler

Posted 23 August 2011 - 12:38 PM

An updated build. 1.0.257.0 is available for download:

Download -> https://github.com/d...u_1.0.257.0.zip

It includes example scripts this time.
Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Project Mizu: Concept programming languages with a .NET compiler

Posted 23 August 2011 - 01:32 PM

It be useful if provide/maintained a language specification.
Have a look at the C#/VB.net that are available in vs2010.

A basic getting started guide. How to compile scripts? Is there an IDE? etc

Classic Example

Hello World!
99 Bottles of Beer


Also have a look at installing the CleanProject tool.

This post has been edited by AdamSpeight2008: 23 August 2011 - 02:10 PM

Was This Post Helpful? 1
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Project Mizu: Concept programming languages with a .NET compiler

Posted 23 August 2011 - 03:10 PM

Look at adding in a way defining Functions and a basic conditional to Mizu.

I raised point about a guide, because from examples it
is hard to tell which variables are in scope. In C# the brace help to determine this.
{ }


or the indenting of Python

Anyhow, well done.

This post has been edited by AdamSpeight2008: 23 August 2011 - 03:15 PM

Was This Post Helpful? 1
  • +
  • -

#10 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Project Mizu: Concept programming languages with a .NET compiler

Posted 23 August 2011 - 03:25 PM

View PostAdamSpeight2008, on 23 August 2011 - 05:10 PM, said:

Look at adding in a way defining Functions and a basic conditional to Mizu.

I raised point about a guide, because from examples it
is hard to tell which variables are in scope. In C# the brace help to determine this.
{ }


or the indenting of Python

Anyhow, well done.

How you determine what's in scope is by reading it... top to bottom.

Consider this code example:
/* Declare a variable named a. */
a`5
/* Declare a variable named b. a is in scope because b is being declared under it */
?b=a+5



Simply put, scope is always top to bottom.

Conditional statements is something I looking at right now but it won't be full if statements. At the very least, it would be "conditional printing".

Lastly, I just finished typing the language specification right here.

--

Hello World is as simple as:
."Hello World".


--

Back to my "conditional printing" idea. In the 99 Bottles of Beer program, it would go something like this:
/* Currently loops can only go up (+1) but I will add the functionality to go down (-1) tomorrow. */

bottles`[100..0]
!bottles==1`["No bottles of beer on the wall"|$"{0} bottles of beer on the wall." bottles]



I have not implemented this yet but I am considering it.

This post has been edited by Amrykid: 23 August 2011 - 03:33 PM

Was This Post Helpful? 0
  • +
  • -

#11 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Project Mizu: Concept programming languages with a .NET compiler

Posted 27 August 2011 - 07:07 AM

As of today's build 360, I have added if statements named 'if blocks' and floats support. Other things were added too but I cannot remember from the top of my head.

Anyway, to showcase the if blocks, check out this 99 bottles of beer script.
bottles`[99..-1]
[bottles!=0:{
?lessbot=bottles-1
.$"{0} bottles of beer on the wall. {0} bottles of beer! Take one down, pass it around. {1} of beer on the wall!" bottles lessbot.
},{
."0 bottles of beer on the wall!".
}]



On my todo list:
  • Remove reference to Mizu.Lib.Evaluator. (This is experimental but you can use it via the /noeval switch. Let me know if your script outputs the wrong answer).
  • Switch blocks (Switch statements. I have the parser ready for this. Now I just needed to implement it in IL).


EDIT:
  • Build 360 Zip (Binaries) is here.
  • Build 360 Zip (Source) is here.


Lastly, you can find somemore of my test scripts here.

This post has been edited by Amrykid: 27 August 2011 - 07:13 AM

Was This Post Helpful? 0
  • +
  • -

#12 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Project Mizu: Concept programming languages with a .NET compiler

Posted 05 September 2011 - 12:28 PM

Mizu (Concept 1) is now finished (feature-wise). I will release a build later this week. Now, I have started working on Mizu2 (Mizu Concept 2) which can be found here.

The syntax is a bit of a mix between VB, Python and Javascript:
var x = 5
System.Console.WriteLine()
System.Console.WriteLine("X")
System.Console.ReadLine()
var obj as new System.Object()
if x = 5:
	var y = 9
	var ystr = y.ToString()
	System.Console.WriteLine(ystr)



In contrast to Mizu, I'm writing the compiler for Mizu2 in VB.NET. (Mizu 3, if any, will be in C# and so on). Mizu2 can use .NET interfaces and the above example is an example of that.
Was This Post Helpful? 0
  • +
  • -

#13 Amrykid  Icon User is offline

  • 4+1=Moo
  • member icon

Reputation: 148
  • View blog
  • Posts: 1,589
  • Joined: 16-December 08

Re: Project Mizu: Concept programming languages with a .NET compiler

Posted 17 September 2011 - 05:25 AM

Its been 3 weeks (or so) and I have quite a bit of updates:

I can gotten Mizu2 near completion. The following code segments compile (100% or near 100%):

98%: (Still need to fix enums for Controls.Dock, etc).
uses System
uses System.Windows.Forms
var window as new Form()
var tb as new TextBox()
var controls = window.Controls()
controls.Add(tb)
tb.Dock = 5
handle tb.TextChanged(sender,e) {
MessageBox.Show("Text Changed")
}
window.ShowDialog()


100%: (No generics support so use ArrayList).
uses System
uses System.Collections
var list as new ArrayList()
list.Add("First string")
list.Add("Second string")
for(var item in list)
{
Console.WriteLine(item.ToString())
}
Console.ReadLine()
var x = 0
Console.WriteLine(x.ToString())
Console.ReadLine()



I'm am almost finished with this project... to create a compiler with concept programming languages.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1