Discussion:
Full Haxe Grammar
danielku15
2010-09-29 13:57:45 UTC
Permalink
Hi Everybody.

I'd like to write a module described here
(http://haxe.1354130.n2.nabble.com/Writing-Targets-using-Haxe-td5583679.html#a5583679).
The only problem is: There is no clean full haxe grammar available.

I'm no Ocaml developer and I don't have the interests to learn this (in my
opinion ugly) language. It would be great if someone could write a full
grammar or enhance this one to be complete and valid:
http://www.semitwist.com/download/haxepred/Haxe_gold_0.2.zip (Made by Nick
Sabalausky). :)

Greetings
Daniel
--
View this message in context: http://haxe.1354130.n2.nabble.com/Full-Haxe-Grammar-tp5584001p5584001.html
Sent from the Haxe mailing list archive at Nabble.com.
--
haXe - an open source web programming language
http://haxe.org
Marc Weber
2010-09-29 14:24:54 UTC
Permalink
Hi Daniel
Post by danielku15
I'd like to write a module described here
(http://haxe.1354130.n2.nabble.com/Writing-Targets-using-Haxe-td5583679.html#a5583679).
So you want to implement targets using the HaXe language?

My two cents: I dislike some aspects of Ocaml as well. But due to
pattern matching and speed its a lot more suited for this task than HaXe
itself.

To summarize: Obviously it gets the job done.

The switch mess of HaXe is no alternative (yet).

Anyway: I may be mistaken. In that case I'd be happy to provide the
interface you're requesting - if you code up the Java backend in turn
*kidding*
Post by danielku15
I'm no Ocaml developer and I don't have the interests to learn this (in my
opinion ugly) language.
Give reasons why. Maybe you're mistaken. In order to read HaXe's source
code you don't need all ocaml features. Learning about match and that
!foo does not mean not foo but read value of an mutable reference is
almost all you need.
Post by danielku15
The only problem is: There is no clean full haxe grammar available.
Why do you need a grammar? HaXes internal system roughly has three
steps:
1) parse file
2) run macros
3) type the ast
4) transform ast into target code
(I"m not sure it is complete)
So which step do you want to code in HaXe?
The code which you needed to target new backends is 4) only.
You don't need a grammar for that.
Post by danielku15
http://www.semitwist.com/download/haxepred/Haxe_gold_0.2.zip (Made by Nick
I thought about how much work it was to rewrite parts of HaXe using a
different language (such as Haskell). The reason is I think that Ocaml
is a nice language, but compared to Haskell more verbose. I'm still very
new to ocaml - so I may be mistaken.

While doing so I thought about how to rewrite the parser. The result of
this effort was: I'd not use happy (a bison like parser generator) - I'd
use parsec - because the code base I had to write would be smaller.
So probably I would not have created a grammar either.

So which parts of adding backends would you like to work on?

By the way: Macros are a nice way to get started looking at ast.
You can pass expressions and trace them with trace.

I patched HaXe to print the ast as well.

Marc Weber
--
haXe - an open source web programming language
http://haxe.org
danielku15
2010-09-29 15:08:03 UTC
Permalink
Hi Marc.
Post by Marc Weber
Anyway: I may be mistaken. In that case I'd be happy to provide the
interface you're requesting - if you code up the Java backend in turn
*kidding*
It was my base idea to ease the development of the Java and C# target. :)
Another (definitly more simple) way would be to create one new Haxe target
which prints the full AST as xml. This would allow everybody to create a
parser in it's own programming-language which converts/compiles the xml ast
to targets like c# and java. The good thing: You can rely on the existing
XML target and extend it. I'll immediatly start writing a xml parser if I
know, someone will provide such a new xml target.
Post by Marc Weber
Post by danielku15
I'm no Ocaml developer and I don't have the interests to learn this (in my
opinion ugly) language.
Give reasons why. Maybe you're mistaken. In order to read HaXe's source
code you don't need all ocaml features. Learning about match and that
!foo does not mean not foo but read value of an mutable reference is
almost all you need.
I'm definitly a fan of C based languages (syntactic) and the Ocaml Syntax is
quite confusing. I don't have the time to learn a new language and setup the
environment required "only" to develop new targets.
Post by Marc Weber
Post by danielku15
The only problem is: There is no clean full haxe grammar available.
Why do you need a grammar? HaXes internal system roughly has three
1) parse file
2) run macros
3) type the ast
4) transform ast into target code
(I"m not sure it is complete)
So which step do you want to code in HaXe?
The code which you needed to target new backends is 4) only.
You don't need a grammar for that.
My idea was to create steps 1-3 as a haxe lib, and the last step 4 would
allow everyone to create new targets :)
Post by Marc Weber
So which parts of adding backends would you like to work on?
I'd like to create new targets. It would be easier to start with a C# target
because a lot of language features like optional method parameters and the
dynamic keyword are available. As a next step I'd also like to create a Java
target.
--
View this message in context: http://haxe.1354130.n2.nabble.com/Full-Haxe-Grammar-tp5584001p5584349.html
Sent from the Haxe mailing list archive at Nabble.com.
--
haXe - an open source web programming language
http://haxe.org
Marc Weber
2010-09-29 15:24:32 UTC
Permalink
Hi Daniel,
Post by danielku15
It was my base idea to ease the development of the Java and C# target. :)
Another (definitly more simple) way would be to create one new Haxe target
which prints the full AST as xml. This would allow everybody to create a
parser in it's own programming-language which converts/compiles the xml ast
to targets like c# and java. The good thing: You can rely on the existing
XML target and extend it. I'll immediatly start writing a xml parser if I
know, someone will provide such a new xml target.
You got it: Its not the work providing an interface to the ast (either
HaXe serialization or xml or JSON or even yaml if you prefer ..)
The hard work is implementing and testing the backend.
Post by danielku15
I'm definitly a fan of C based languages (syntactic) and the Ocaml Syntax is
quite confusing.
So ask your questions about the confusing syntax instead. I"m sure we
can help you understand much faster than it would take you to implement
1-3

By the way: check out: http://lib.haxe.org/p/hscript
That's close to what you want to do. Don't know how big the implemented
subset is..

I don't have the time to learn a new language and setup the
Post by danielku15
environment required "only" to develop new targets.
I can setup the environment for you. You can work by either using VNC or
SSH using Emacs Vim (or any other editor which runs on Linux)
Post by danielku15
My idea was to create steps 1-3 as a haxe lib, and the last step 4 would
allow everyone to create new targets :)
So you want to provide 1-3 (the easy parts) making it easier for others
to work on the hard part (step 4) ? :)
Post by danielku15
I'd like to create new targets. It would be easier to start with a C# target
because a lot of language features like optional method parameters and the
dynamic keyword are available. As a next step I'd also like to create a Java
target.
If you start working on Java I'd announce it - because I heared that
somebody else might be working on it as well.

Marc Weber
--
haXe - an open source web programming language
http://haxe.org
danielku15
2010-09-29 21:32:01 UTC
Permalink
Another reason why I don't want to develop ocaml is because of the coding and
debugging capabilities. If I think of developing in C#/Vs2010 or
Java/Eclipse it's a lot easier to analyze the AST and write acurate targets.
I started to create a stub compiler using the XML target. 320 Lines of code
allow me to write Enums, Interfaces and Class Stubs. Of course my "compiler"
doesn't support all features of haxe as the xml target ignores a lot of AST
elements. I have uploaded my little utility here
www.coderline.net/files/HaxeXmlCompiler.exe . Of course it's only a
quick&dirty/2 hours work program but it shows what would be possible easily.

We are probably a little bit off-topic now but I think my request changed.
:) My wish is to access the full AST without writing ocaml or the need of
recompiling haxe for each test. Of course it would be the best if all
targets are written in ocaml and are compiled into the main module, but for
a start this would fasten the development of C# and Java Targets. If someone
writes a module for translating the AST to C# or Java in C# or Java, it
would be easy to a ocaml developer to translate the code.
--
View this message in context: http://haxe.1354130.n2.nabble.com/Full-Haxe-Grammar-tp5584001p5585443.html
Sent from the Haxe mailing list archive at Nabble.com.
--
haXe - an open source web programming language
http://haxe.org
Marc Weber
2010-09-29 21:57:52 UTC
Permalink
Post by danielku15
Another reason why I don't want to develop ocaml is because of the coding and
debugging capabilities. If I think of developing in C#/Vs2010 or
Java/Eclipse it's a lot easier to analyze the AST and write acurate targets.
I started to create a stub compiler using the XML target. 320 Lines of code
allow me to write Enums, Interfaces and Class Stubs. Of course my "compiler"
doesn't support all features of haxe as the xml target ignores a lot of AST
elements. I have uploaded my little utility here
www.coderline.net/files/HaxeXmlCompiler.exe . Of course it's only a
quick&dirty/2 hours work program but it shows what would be possible easily.
We are probably a little bit off-topic now but I think my request changed.
:) My wish is to access the full AST without writing ocaml or the need of
recompiling haxe for each test. Of course it would be the best if all
targets are written in ocaml and are compiled into the main module, but for
a start this would fasten the development of C# and Java Targets. If someone
writes a module for translating the AST to C# or Java in C# or Java, it
would be easy to a ocaml developer to translate the code.
Never mind. We all want new targets :)

Which language would you use if you started for what reasons?
You can try telling me you'd prefer using Java because you have a
debugger. But I'll tell you that you would dislike having to write many
if foo = then
else if foo then
else if ...

Using Ocaml you'll get errors forgetting a case (using HaXe you'll get
as well) Don't know how to get this using xml ?

YOu're right: The Java case could be interesting because you could
compile to class files on the fly without creating .java files.

Anyway let me tell you that Franco only recompiled the php module and
run the linker. So the dev cyle: recompile HaXe, run HaXe on .hx code to
generate a java file would be reasonable fast.

Of course you can do whatever you want

Marc Weber
--
haXe - an open source web programming language
http://haxe.org
Nicolas Cannasse
2010-09-29 17:10:58 UTC
Permalink
Post by danielku15
Hi Everybody.
I'd like to write a module described here
(http://haxe.1354130.n2.nabble.com/Writing-Targets-using-Haxe-td5583679.html#a5583679).
The only problem is: There is no clean full haxe grammar available.
Grammar is not enough to implement a new haXe target : you need the
fully typed/optimized AST as well as many compiler-internal type
informations to write a proper haXe target. So it cannot be done outside
of the compiler itself.
Post by danielku15
I'm no Ocaml developer and I don't have the interests to learn this (in my
opinion ugly) language.
Judging a language by its syntax is a bit like judging people by their
clothes. You might end up getting the wrong idea...

Nicolas
--
haXe - an open source web programming language
http://haxe.org
Loading...