Page 4 of 5 FirstFirst ... 2345 LastLast
Results 31 to 40 of 48

Thread: Php Transpiler (per to x)

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

    Default

    Oops...
    The only thing is; I can't think of anything that can't be done in that way...
    And the only way to find those things is to try them all out.... correct?

    What do you mean look at it on a more abstract level?

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

    Default

    The only thing is; I can't think of anything that can't be done in that way...
    I don't know the full syntax of these languages. If there really is nothing that can't be done by a simple "flat" search and replace, then go for it. But if there is anything that requires re-ordering of parts of the syntax, you'll get into serious trouble trying to do it that way.

    And the only way to find those things is to try them all out.... correct?
    In some sense. But understanding the theory behind it will help you predict the problems.

    What do you mean look at it on a more abstract level?
    My other life is doing linguistics and I've seen quite a bit on this topic. A friend of mine was trying to write a Swahili-English translator and had some promising results, just using formulas. But the problem is that you will eventually run into problems for certain things that don't exactly fit those patterns. And that's the hard part.
    There are a couple ways to approach this; what I'd do is parse it into some sort of representational language so that you can then easily translate between them. But that maybe isn't necessary.

    I suggest spending a day reading about the topic; here's one place to start:
    http://en.wikipedia.org/wiki/Translator_%28computing%29
    Another is to look into "Machine Translation", which will be about natural languages-- it'll go into certain topics you do not need to worry about, but overall a lot of the ideas will be helpful.
    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

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

    Default

    There are some bits that require complete re-ordering...
    E.g. I can add in functions to my language by using "goals" (if value = something, goal = something. Then if goal = something, do something), but that means writing stuff to the top file and all kinds of stuff...
    I'm fairly sure I can do this just with things like preg_replace, but the code would be so complex it wouldn't be funny....

    Ahh... so your talking about intermittent languages?
    I've actually done a fair bit of research on compilers all ready (and things related to them) but I'll go have a look at what your suggesting...

    My only question is: how would using an intermittent language actually stop the need for search and replace?
    I mean, how is doing that actually any different to the preg_replace and stuff like that?

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

    Default

    Well, having an intermediate language would allow you 2 things:
    1) If you ever want to expand this beyond just X-Y translation you'd be able to do it more easily (adding also, let's say, PHP translation, or JS translation).
    2) The process of writing the new code will be much easier than parsing the old code, no real question about that. And that will mean that you don't need to worry about oddities of the target language while parsing the oddities of the source language. Your intermediate language would need to have all of the functionality of each but be organized in a very clean way such that you know exactly how to translate into another languages-- it wouldn't even need to be a "language" in a strict sense, but more like a set of instructions to your program to write code into a different language.
    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

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

    Default

    Ahh... ok.
    Just found this.... does that look like the kind of thing to do?
    Actually, there's no point in being able to convert to different languages: the language that I'm converting to is the only one that can do what it does.
    Sure you could use a similar syntax, but the actual values and stuff would never be used in a different language...
    Last edited by keyboard; 10-20-2012 at 10:25 PM.

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

    Default

    That looks completely reasonable to me, and it looks similar to what I've seen in NLP, in some fundamental ways, not in the details of course.
    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

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

    Default

    I've got an actual coding question -
    I'm trying to make two arrays - the value in array1[1] should be the data related to array2[1] (and so on).

    I've got this -
    PHP Code:
    <?php
    $handle 
    file_get_contents('Test/1.per');
    echo 
    '<pre>' $handle '</pre><br /><br />';
    $char_type = array(
        
    " " => "SPACE",
        
    "bar" => "foo",
    );
    $export;
    $count1 strlen($handle);
    $count2 count($char_type);
    for(
    $i=0;$i<$count1;$i++) {
        
    $r substr($handle$i1); 
        for(
    $u=0;$u<$count2;$u++) {
            if(
    $r $char_type[$u]) {
                
    $compare[i] = $char_type[$u];
                
    //break;
            
    }
        }
        
    $export[i] = $r;
        echo 
    $r;
        
    //break;
    }
    echo 
    $count2;
    for(
    $z=0;$z<$count1;$z++) {
        echo 
    $export[z] . '<br />';
        echo 
    $compare[z] . '<br /><br />';
    }
    ?> 
    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
    </body>
    </html>
    And the file 1.per -
    Code:
    if(
    	(or
    		game.time > 1;
    		game.time > 100;
    	)
    	count(militia-line) < 10
    ){
    	chat_all("Hello World");
    	break();
    }
    The php code isn't writing the two arrays (but it's writing the contents of the file).
    Any help?
    Also, is there a better way to do this?

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

    Default

    Shouldn't there be $ signs with the arrays and loops?
    Code:
    <?php
    $handle = file_get_contents('Test/1.per');
    echo '<pre>' . $handle . '</pre><br /><br />';
    $char_type = array(
        " " => "SPACE",
        "bar" => "foo",
    );
    $export;
    $count1 = strlen($handle);
    $count2 = count($char_type);
    for($i=0;$i<$count1;$i++) {
        $r = substr($handle, $i, 1); 
        for($u=0;$u<$count2;$u++) {
            if($r = $char_type[$u]) {
                $compare[$i] = $char_type[$u];
                //break;
            }
        }
        $export[$i] = $r;
        echo $r;
        //break;
    }
    echo $count2;
    for($z=0;$z<$count1;$z++) {
        echo $export[$z] . '<br />';
        echo $compare[$z] . '<br /><br />';
    }
    ?> 
    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
    </body>
    </html>
    "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. #39
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    PHP Code:
    <?php
    $handle 
    file_get_contents('Test/1.per');
    echo 
    '<pre>' $handle '</pre><br /><br />';
    $char_type = array(
        
    " " => "SPACE",
        
    "(" => "LEFT BRACKET",
    );
    $export;
    $count1 strlen($handle);
    $count2 count($char_type);
    for(
    $i=0;$i<$count1;$i++) {
        
    $r substr($handle$i1); 
        for(
    $u=0;$u<$count2;$u++) {
            if(
    $r $char_type[$u]) {
                
    $compare[$i] = $char_type[$u];
                
    //break;
            
    }
        }
        
    $export[$i] = $r;
        echo 
    $r;
        
    //break;
    }

    for(
    $z=0;$z<$count1;$z++) {
        echo 
    $export[$z] . '<br />';
        echo 
    $compare[$z] . '<br /><br />';
    }
    ?> 
    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
    </body>
    </html>
    Fixed what you pointed out but it still doesn't work...

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

    Default

    One thing I can see, or can't see rather, is where the variable $compare is created. You actually need a variable before you should write to it. Shouldn't you just create compare and export as empty arrays rather than one empty variable, and one not-a-variable?
    Code:
    <?php
    $handle = file_get_contents('Test/1.per');
    echo '<pre>' . $handle . '</pre><br /><br />';
    $char_type = array(
        " " => "SPACE",
        "(" => "LEFT BRACKET",
    );
    $export = array();
    $compare = array();
    $count1 = strlen($handle);
    $count2 = count($char_type);
    for($i=0;$i<$count1;$i++) {
        $r = substr($handle, $i, 1); 
        for($u=0;$u<$count2;$u++) {
            if($r = $char_type[$u]) {
                $compare[$i] = $char_type[$u];
                //break;
            }
        }
        $export[$i] = $r;
        echo $r;
        //break;
    }
    
    for($z=0;$z<$count1;$z++) {
        echo $export[$z] . '<br />';
        echo $compare[$z] . '<br /><br />';
    }
    ?> 
    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
    </body>
    </html>
    give that a try.
    "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

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
  •