making another "simple language" using C++

This is a discussion on making another "simple language" using C++ within the C++ Programming forums, part of the General Programming Boards category; Let's say that i wanted to create a simple web programming language using C++, that has the extension of *.web ...

  1. #1
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186

    making another "simple language" using C++

    Let's say that i wanted to create a simple web programming language using C++, that has the extension of *.web

    and I open Note Pad (let's suppose the language i created somehow can work on note pad like html), and write this command (which was a built-in type in my language) to out put a text:

    Code:
    text("Hellow world")!

    what does it take to do this ??? does it have to be pure C++ ?? is it gonna be pain in the butt ?
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    the answer is...................... it depends.

    if all you want is a few simple commands e.g.
    text(somestring)
    add(number1, number2)

    that's relatively easy to do with simple text parsing. if you want to get more complicated, you want something more flexible.

    a couple of options are (ranging from easy and fast but rigid to more complex, slower but more flexible)
    simple string parsing (i.e. if (cmd == "text") std::cout << arg; )
    boost.spirit - allows you to define a language grammar within your c++ code
    embed an interpretted language like python or lua

    if you give some more detail as to what you'd like to achieve, I could probably point you in a more specific direction
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    what does it take to do this ???
    As a programming exercise, you can probably do this, and you can keep it as simple as you want.

    does it have to be pure C++ ??
    No. Typically, you would write an interpreter. You can write that in "pure C++", or with whatever additional libraries you want to use. Then, you would compile that into an EXE (or other executable file).

    When someone writes (and runs) a program in your special-language, they don't care what language you used to write the interpreter. They just need to run your interpreter-program before they run their application-program.

    If you wanted to create a compiled language, you could do that with C++ too. (As you probably know, a compiler creates a stand-alone executable. The end-user wouldn't need your program to run the EXE file.) But to do it "correctly", you would need to know quite a bit of Assembly language.

    is it gonna be pain in the butt ?
    Probably. Again, if this is just an exercise you can make it as simple as you want. Is this going to be a browser plug-in? If so, it's going to take quite a bit of study if you don't know how to make plug-in (I don't).

    ---------------------------
    If this is going to be a real-world program (as opposed to an exercise), I see some problems. You would need users to download and run your interpreter/plug-in. Most of us are paranoid about that kind of thing, and we don't like "clogging-up" our computer with extra junk.

    And in order for it to be useful, it can't be too simple. In that case, it's probably not a one-man project.

    ----------------------------
    There are some applications where a simple scripting language is useful. Let's say you make a microprocessor-controlled temperature chamber...

    You might want to give the user a way to program it without using Assembly, C/C++, or whatever you used to make the thing work. And, you might not want the user hacking-into your firmware, etc.

    You might want to create a few programming commands to give the user a way to program temperature changes, run temperature cycling loops, maybe include some "if-statements" in case something unexpected happens, etc.

    A simple language like that can be learned in a day or so by a technically competent person who is not a programmer.

    However, your part wouldn't be quite that simple.... The idea is to make things simple for the programmer, not to make things simple for the language-creator compiler/interpreter-writer. You would need to know C/C++ and/or Assembly. You would have to understand the nitty-gritty details of how the temperature-controller hardware & firmware work together. You would have to make sure your interpreter handles syntax errors by the end user, and maybe put-in some other error protection to keep the user from writing a program that's invalid, "stupid", or maybe even dangerous.
    Last edited by DougDbug; 05-25-2007 at 06:20 PM.

  4. #4
    "Why use dynamic memory?"
    Join Date
    Aug 2006
    Posts
    186
    thank all for replies. I asked this because I was planning to make a simple web designing language, like HTML, but at the same time, it offers more functionality than HTML. My design was like this for printing a text or displaying image:
    Code:
    text(string text, font, size, color, background, link)!
    image(location, border, width, height, link)!
    
    //It will be like this 
    text("Hellow world", Tuhama, 12, red, yellow, http://www.google.com)!
    image(images/car.jpg, 2, 200, 200, http://www.yahoo.com)!
    and i also planned to provide the user functionality make loops and stuff.

    and of course all the parameters are set to default in case the user doesn't use any thing. That was just fooling around and dreaming. I dont know if I will ever make effort to do that
    "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg."-Bjarne Stroustrup
    Nearing the end of finishing my 2D card game! I have to work on its 'manifesto' though <_<

  5. #5
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    To be honest I think this design offers much less functionality, and nobody will want to use it.
    For example, with HTML you can see the order in which things will appear, while reading the code. With this, you cannot.
    >>and i also planned to provide the user functionality make loops and stuff.
    We've got PHP for that. You will have to come up with something really original if you want your brainchild to be preferred over existing technologies.
    Don't call me stupid.

  6. #6
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    Like pronecracker said, it would have to be really good to be able to be better than the existing technologies.

    HTML is a "mark-up language". It is very useful for what it was designed to do, and is even more powerful when combined with a CSS style sheet to help it out. For everything else, there is a multitude of scripting languages to do the job: JavaScript on the client side, and PHP and Python on the server side.

    But let's say we completely ignore all that for now:

    If you really want to create your own language, it takes a lot more than knowing how to code a program in C++. Do you know what a grammar is? Do you know anything about context-free grammars or regular grammars? Do you know anything about LL(k) parsing...or more specifically...LL(1) parsing? Do you know what a Finite State Machine is?

    If you don't know those topics, I suggest reading up and studying them, because they are pretty important for defining a language. You define a language completely separate of coding any C++. You define a language on paper. Then you code a parser and a lexical analyzer in C++. After a parser is written, you can worry about doing an interpreter.

    Some other good topics to read up on that might help you out, although they are not 100% vital: regular and context-free languages and turing machines, and graph theory
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making sprites
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 02-20-2010, 07:00 AM
  2. Making great graphics
    By MadCow257 in forum Game Programming
    Replies: 1
    Last Post: 02-20-2006, 11:59 PM
  3. Making control...
    By Finchie_88 in forum C++ Programming
    Replies: 2
    Last Post: 09-07-2004, 02:42 PM
  4. Replies: 2
    Last Post: 01-13-2003, 01:28 PM
  5. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 08:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21