Hacker News new | ask | show | jobs
Ask HN: Why build compilers in Rust instead of C?
1 points by calebwin 2701 days ago
2 comments

I find that Rust's syntax/ecosystem is much more modern and pleasant to use. Some examples are: pattern matching, immutable variable, better build and dependency system, and many more.

There are some concepts like lifetime that you have to learn. But you can always use unsafe pointer and look at Rust as a modern version of C.

I looked at the Rust site and their published grammar. It is VERY incomplete, missing entire productions.

I cannot determine if the syntax of Rust is "better" than that of C.

At least the ISO "C" std. organization publishes a complete syntax of their language.

Perhaps someone knows where there is a complete grammar for the Rust language?

I cannot find one.

I might misunderstand the question here.

Could you elaborate more why the complete grammar of Rust is important for writing a compiler (for any programming langugage) in Rust?

I thought the question was about whether to write a compiler in Rust or C. But it seems you meant writing a parser that parsed the Rust language itself. Or there's something I misunderstand here.

I found a LALR grammar for Rust on GitHub, compatible with Bison.

But it does not closely track the published Rust Grammar nor syntax rules in the Rust Reference. (See Rust-lang DOT org site.)

Although perhaps a Rust grammar could be extracted from the syntax rules in the Reference doc, it may be incomplete. For example, how do "as-yet-undocumented features" affect the current syntax rules in the Rust Reference?

So for now, it looks like C is easier to parse than Rust.