Live data from Hacker News

Php-parser written in golang v0.3 is released

github.com

21–28 of 28 posts

Re: Php-parser written in golang v0.3 is released

#21
post #3

There's a [dead] comment that asks "Why?"... Obviously not every project needs a "why?", and this is a technically cool endeavour that stands on its own.. A few ideas I can think of for "Why?": * Static analysis of a codebase looking for bad practices or errors * Feeding the structured output into code-gen for another language, to start a porting project * //STEP MISSING//, Profit? Anything else?

PHP is often used because it's mature, reasonable secure these days, and has world-class encryption libraries. Lots of companies develop web applications in it....

But if you're developing a web application that you host and also want to offer a private version of for enterprise use, this is somewhat appealing because it's the first step of being able to package the PHP app within a Go binary that runs on a lot of platforms and not have to release your source code.

Sure you could write it in Go from the start, but if you already have a bunch written or want to use less expensive developers, this might work out one day.

Re: Php-parser written in golang v0.3 is released

#22

Write PHP code and package as Go-binaries?? The potential!

Even if this included an interpreter, that wouldn't allow you to package anything besides the PHP runtime (e.g. the "php" executable etc) as a Go binary.

You wouldn't be able to distribute PHP programs as go binaries; it would still be an interpreted language, so you'd still have to make sure your programs, and their dependencies, were correctly deployed to wherever you had installed the interpreter.

Re: Php-parser written in golang v0.3 is released

#23

Write PHP code and package as Go-binaries?? The potential!

Even if this included an interpreter, that wouldn't allow you to package anything besides the PHP runtime (e.g. the "php" executable etc) as a Go binary. You wouldn't be able to distribute PHP programs as go binaries; it would still be an interpreted language, so you'd still have to make sure your programs, and their dependencies, were correctly deployed to wherever you had installed the interpreter.

With a properly parsed AST, you could probably convert to Go's AST and compile down to the final Go binary, similarly to how you can write a new front-end for LLVM.

Re: Php-parser written in golang v0.3 is released

#24

Earlier quoted context omitted.

Even if this included an interpreter, that wouldn't allow you to package anything besides the PHP runtime (e.g. the "php" executable etc) as a Go binary. You wouldn't be able to distribute PHP programs as go binaries; it would still be an interpreted language, so you'd still have to make sure your programs, and their dependencies, were correctly deployed to wherever you had installed the interpreter.

With a properly parsed AST, you could probably convert to Go's AST and compile down to the final Go binary, similarly to how you can write a new front-end for LLVM.

Theoretically, you almost could (with quite a bit of difficulty), but then there's the problem of "eval".

You can "solve" that by embedding an interpreter (or a copy of your compiler) into your runtime, but most interpreted platforms in that situation consider the interpreter "good enough" and work on making optimizations (e.g. JIT compilation to native code) on it rather than making a static compiler.

Re: Php-parser written in golang v0.3 is released

#25

Why?

Probably for the same reason I have a tendency to make earley parsers for random languages in python and C++ every now and again, something to do that's semi-productive.

If I ever get around to playing with golang you can bet there's gonna be yet another earley parser implementation for whatever grammar I'm currently looking at.

Re: Php-parser written in golang v0.3 is released

#27

Earlier quoted context omitted.

With a properly parsed AST, you could probably convert to Go's AST and compile down to the final Go binary, similarly to how you can write a new front-end for LLVM.

Theoretically, you almost could (with quite a bit of difficulty), but then there's the problem of "eval". You can "solve" that by embedding an interpreter (or a copy of your compiler) into your runtime, but most interpreted platforms in that situation consider the interpreter "good enough" and work on making optimizations (e.g. JIT compilation to native code) on it rather than making a static compiler.

I mean, eval is a thing, and I'm sure people use it, but I don't recall using it much while a PHP developer. It's just more likely to footgun than anything else. I think you can credibly release a tool that will compile PHP into a standalone executable, as long as it doesn't call eval.

Re: Php-parser written in golang v0.3 is released

#28
post #3

There's a [dead] comment that asks "Why?"... Obviously not every project needs a "why?", and this is a technically cool endeavour that stands on its own.. A few ideas I can think of for "Why?": * Static analysis of a codebase looking for bad practices or errors * Feeding the structured output into code-gen for another language, to start a porting project * //STEP MISSING//, Profit? Anything else?

I guess my question isn't so much "Why would anybody build this?" but "Why would you upvote this to the front-page?" Seems like part of a larger "I built X in Y" HN pattern.

I have noticed that "I built X " typically gets way more upvotes than "I built X"...
Post reply on HN