• Lucid Dreaming - Dream Views




    Results 1 to 12 of 12
    1. #1
      What's up <span class='glow_006400'>[SomeGuy]</span>'s Avatar
      Join Date
      Nov 2007
      LD Count
      About 1
      Gender
      Location
      Tmux on Debian
      Posts
      2,862
      Likes
      130
      DJ Entries
      4

      Javascript Stuck-tion, grr.

      Well, once again, I'm back here asking my cyber-homies for some help.
      Basically, I'm pretty much making a "word replacer". I'm writing a new browser script, and I'm creating a JS compiler. What the compiler will do is scan through a textarea and replace my script with JS. SO, after the user types in his program and clicks Compile (a button), it will document.write the program in JS. Kinda confusing?
      Here:
      Code:
      Step 1: I type in my program in a text area:
        EX:
        <$ a = 8
        <$ b = 4
        [?echo<< a + b;
        It makes 2 variables, and writes the sum of them.
      
      Step 2: I click compile
        JS scans through my textarea and replaces <$ with "var" and [?echo<<    with "document.write(".
      
      Step 3: It writes to the screen the program compiled into JS.
      Get it?

      Hey guys, I'm back. Feels good man
      ---------------------------------------------------
      WTF|Jesus lul
      spam removed

    2. #2
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      You'd have to make a grammar first, java has one, I don't remember what it's called. You have to make sure that your grammar is LL(1) though. Java also has a tree builder, that one I know, it's called JTB. You can use that to make your concrete parse tree.

    3. #3
      What's up <span class='glow_006400'>[SomeGuy]</span>'s Avatar
      Join Date
      Nov 2007
      LD Count
      About 1
      Gender
      Location
      Tmux on Debian
      Posts
      2,862
      Likes
      130
      DJ Entries
      4
      I'm not using java though...

      Javascript.

      Hey guys, I'm back. Feels good man
      ---------------------------------------------------
      WTF|Jesus lul
      spam removed

    4. #4
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      I thought you were trying to convert to Javascript You could do that with java. As far as I know there is no grammars for javascript.

    5. #5
      Member Identity X's Avatar
      Join Date
      Mar 2004
      Gender
      Posts
      1,529
      Likes
      7
      http://www.tizag.com/javascriptT/jav...ng-replace.php

      I used that magic thing called Google.

      Anyway, this program sounds a little useless, and by that I mean totally useless. Why not write in JavaScript in the first place? And what twisted excuse for syntax is [?echo <<? Besides, a series of replace statements != a compiler.

      ninja9578: I used JavaCC and JJTree last time I wrote a compiler in Java, never heard of JTB though.

      Quote Originally Posted by ninja9578 View Post
      I thought you were trying to convert to Javascript You could do that with java. As far as I know there is no grammars for javascript.
      Why would JavaScript/ECMAScript/JScript etc. (they are all slightly different things) not have grammars? That would be unfair on the browser writer, would it not? Almost every major language since Algol has had an (E)BNF grammar, with a few notable exceptions such as, I think, pre-ANSI C. As such the Java grammar which name you cannot recall is likely called the "Grammar of the Java Programming Language". They don't give these things fancy names, you know.

      AFAIK he's writing it in JavaScript and the output will be in JavaScript. For what it is (a long series of replace statements), JS is a reasonable choice, a good one even given it's mature regex support, given that it is a Web application.
      Last edited by Identity X; 08-26-2008 at 07:20 PM.

    6. #6
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      JavaCC! Thanks, I couldn't remember the name of it. This is JTB

    7. #7
      Member Identity X's Avatar
      Join Date
      Mar 2004
      Gender
      Posts
      1,529
      Likes
      7
      Quote Originally Posted by ninja9578 View Post
      JavaCC! Thanks, I couldn't remember the name of it. This is JTB
      Ah. JavaCC is in no way a grammar. It's a compiler compiler. Hence 'CC'.

    8. #8
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      don't use document.write()

      it's horrible
      and won't work properly (if at all) on XML or XHTML pages
      (page structure needs to be full & valid prior to any processing)

      use the DOM instead

    9. #9
      What's up <span class='glow_006400'>[SomeGuy]</span>'s Avatar
      Join Date
      Nov 2007
      LD Count
      About 1
      Gender
      Location
      Tmux on Debian
      Posts
      2,862
      Likes
      130
      DJ Entries
      4
      Well, As for the syntax, it's an example. I'm changing it and playing with it. I'm also using document.write() so it clears the page with the compiled output as JS.

      As for the name compiler, well it is sorta. C Compilers translate C into Binary. This translates stuff into JS. Also, when it is complete, it will be a bit much easier than JS. For non programmers.AND Thanks for the link IX, but that only replaces a 1 word. I need to know how to make it replace not just "<$", but "<< function" as well.
      replace() only does one word.

      Hey guys, I'm back. Feels good man
      ---------------------------------------------------
      WTF|Jesus lul
      spam removed

    10. #10
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by Identity X View Post
      Ah. JavaCC is in no way a grammar. It's a compiler compiler. Hence 'CC'.
      I was using the term incorrectly. The grammar is what goes into the CC.

      Someguy, are you having a one to one relation between symbols in your language thing and JS? If so then all you need is a translator, if not you need a grammar.

      In your example, GCC is not a translator, it's a compiler.
      Code:
      c = a + b;
      compiles to
      Code:
      mov eax, [a]
      add eax, [b]
      mov [c], eax
      Assemblers are translators (basically,) but if you have any difference in syntax from one language to another, then your program has to understand the grammar of both languages.

    11. #11
      What's up <span class='glow_006400'>[SomeGuy]</span>'s Avatar
      Join Date
      Nov 2007
      LD Count
      About 1
      Gender
      Location
      Tmux on Debian
      Posts
      2,862
      Likes
      130
      DJ Entries
      4
      Oh, no. There isnt any syntax difference. I just need aword replacer so i can change "$" into "var" as well as "<<function" into "function"

      Hey guys, I'm back. Feels good man
      ---------------------------------------------------
      WTF|Jesus lul
      spam removed

    12. #12
      Member Identity X's Avatar
      Join Date
      Mar 2004
      Gender
      Posts
      1,529
      Likes
      7
      Quote Originally Posted by xXSomeGuyXx View Post
      Thanks for the link IX, but that only replaces a 1 word. I need to know how to make it replace not just "<$", but "<< function" as well.
      replace() only does one word.
      Ever heard of that little used programming construct known as a loop?

      Specifically a for loop through an array of string x-replacement y pairs (stored as, for example, two equally sized arrays of strings.)

      Before you ask, I'm not writing the program for you
      Last edited by Identity X; 08-27-2008 at 01:02 PM.

    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
    •