Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 48

Thread: Php Transpiler (per to x)

  1. #11
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by keyboard1333 View Post
    *this is my entry in a competition for "understatement of the year." isn't a vote of confidence
    That particular line wasn't my "vote of confidence," nor a vote of "no confidence" - just asserting that it's a very difficult undertaking, almost certainly many times more difficult than you might imagine. Not because of any shortcomings in your imagination, but because you're trying to convince yourself that you can do it. I'm not saying you can't, but that fact does distort your judgement at least a little bit.

    Personally, I'd love to see this. It'd be quite interesting, and I'd enjoy helping out where I could. Daniel's right, though; you'd need to do a lot of tedious, complex theoretical work before you started writing any code.

    Can you distill your code examples into a basic syntax? e.g.,
    PHP Code:
    $message $logged_in'you are logged in''please log in'
    translates to
    Code:
    {handle}{assignment_operator}{condition}?{value if condition is true}:{value if condition is false};
    and that's not even a particularly complete representation.
    Last edited by traq; 10-20-2012 at 04:47 AM.

  2. #12
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    I know how hard this is (trust me... the whole phrase "biting off more than you can chew" was based on me [but that's a story for another time]).
    The language that I'm converting to is actually incredibly simple.
    There is no math, functions or things like that.
    There is simply "If these values are true - Do this" (and some minor stuff with declaring constants).
    I don't think it's as hard as you're envisioning, but maybe not as simple as I'd imagined...
    There are some simple search and replace things (if line starts with // replace // with ; - things like that) but there are also a few tricky things...
    Also, it's a very limited language (it does one particular thing and that thing only... no extensions or anything like that).

    Basically, it will just be very advanced search and replace script... Not entirely, but mainly....

  3. #13
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Also, it's a very limited language (it does one particular thing and that thing only... no extensions or anything like that).
    This is very very helpful for what you're trying to do.

    There are some simple search and replace things (if line starts with // replace // with ; - things like that) but there are also a few tricky things...
    But even your simple example isn't actually that simple. Comments work like that, unless they're inside strings. And what does it mean to be inside a string? You'll start to run into scope issues, and simple search and replace will fail, and regex may fail as well or get very complex.

    One important question is whether you rely on well-written code, or any kind of valid syntax.

    Basically, it will just be very advanced search and replace script... Not entirely, but mainly....
    It's the subset of harder things that will give you trouble. The rest is irrelevant and easy.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #14
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Actually, one sucky thing I just though of...
    Since this outputs files, I don't particually want them to have to read those files.
    And since the engine that runs them only runs files with particular extensions, it would just output an error referencing the outputed script...
    E.g. If the user makes a mistake, it would make a mistake in the output.
    Therefor, I also have to debug the input....

  5. #15
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Yes, that's entirely true, as well as the possibility of oddly formatted (but potentially valid) syntax.
    You need to fully parse the code, including checking for errors, then figure out how to translate it.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #16
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    yes, as daniel mentioned, you will have to format the code yourself to specific standards, as, for example, the user might input all the code on only one line.
    so this is what appears to be what the script needs to do.

    1) user input
    2) format user input
    3) check for errors
    4) translate
    5) check syntax of output
    6) re-format it
    7) output it
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  7. #17
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    4) translate
    5) check syntax of output
    6) re-format it
    These could be one step if it's written well (eg, logically correct for the entire formal system of the language)

    2) format user input
    This could also be eliminated if you write a good enough parser, eg, a complete compiler. However, perhaps something like HTML Tidy would be more helpful to get you started. I'm not sure on that one.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #18
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    .per tidy maybe? One thought I had, was to actually strip some of the whitespace, making it quick to parse. However, that won't work, if per's don't have anything to end a line with (ie, semi-colon), then it just won't parse at all. I'm not familiar with the language, so we'll have to wait for a reply from keyboard.
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  9. #19
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    I'm fairly sure you could just put all the code on one line (each bit of code is wrapped in () ) just like javascript....
    I'll go try it to find out....
    Might take me a while

  10. #20
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    One thought I had, was to actually strip some of the whitespace, making it quick to parse. However, that won't work, if per's don't have anything to end a line with (ie, semi-colon), then it just won't parse at all. I'm not familiar with the language, so we'll have to wait for a reply from keyboard.
    That's not just an option; it's logically necessary. However, again there's a detail: this must be done only in the right context-- outside of strings, and potentially outside of comments as well. And maybe I'm not thinking of something else. The extra whitespace will be eventually stripped, but not as the first step.

    By the way, the idea of tidying up the code should be explained a bit-- it's to make it machine readable, not human readable. So it won't look nice and pretty with the tabs we like; it'll be simple for a machine to understand. In fact, compressing all of it to a single line might be the best way to go in terms of writing a parser-- line breaks are completely irrelevant in most situations in most languages (except, of course, strings, and then there's the issue of whether it has the same 'flexibility' (in my mind bug) of Javascript where a linebreak can be effectively the same as a semicolon).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •