Advertisement

Can HTML be used?

Started by January 08, 2005 10:15 PM
5 comments, last by mattnewport 20 years, 1 month ago
hey all, kinda new here, just wondering if HTML could be used fairly easily as a scripting language for C++. On the same note, how about xml-based things. thanks!
HTML is a markup language
Hyper text markup language = html
A markup language cannot compute

XML maybe, but you'd have to embed another scripting lang into it. (XML - Extended markup language)

You should look into python, or lisp.
From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Advertisement
Quote:
Original post by Nice Coder
HTML is a markup language
Hyper text markup language = html
A markup language cannot compute


I just have a little quip with this statement. I do agree that HTML cannot do what's needed, but not for the reason provided. XML is a "markup" language as well, and in the sense that you seem to be speaking, it can compute (i.e. XSLT). However, the language itself does not perform the computing -- an interpreter does. As would be necessary for this particular use, a scripting language interpreter with XML interpreting capabilities. So really, I'm just trying to say that the work "markup" has nothing to do with any of this. :)
Well, firstly, HTML is entirely about document layout. So no, I can't see any way whatsoever that it can practically apply to scripting.

So, let's say XML instead. In theory... yes. You could do this:
<if condition="score=10"><then><dosomething/></then><else><dosomethingelse/></else></if>


But then you could make up your own representation instead:
1 102124246-232364547-3-1


So really, why bother?

When it comes down to it, you'd not really be using XML as a language, more as a vocabulary. The functionality of a programming language is not inherent to it. If you were counting XSLT or some variation as XML for the purposes of argument, then I expect you might find things are possible, but it's incredibly verbose and not at all convenient for the task. And I don't even know how it would handle anything since all the XSLT stuff I am aware of just takes in text and outputs text - that's not much good when you need objects modified.
Quote:
Original post by Kylotan
When it comes down to it, you'd not really be using XML as a language, more as a vocabulary. The functionality of a programming language is not inherent to it. If you were counting XSLT or some variation as XML for the purposes of argument, then I expect you might find things are possible, but it's incredibly verbose and not at all convenient for the task. And I don't even know how it would handle anything since all the XSLT stuff I am aware of just takes in text and outputs text - that's not much good when you need objects modified.


Agreed -- there are plusses and minuses. The intention of XML is more for the representation of data to enable communications across various mediums that could not previously communicate without the introduction of customized interfaces. XSLT is used as a way to format XML data in a certain way. You can use XML really in the way mentioned by Kylotan, and since there are already existing interpreters for the XML file format, it might make your life easier rather than defining your own scripting language format. It is possible, it's just a matter of figuring out whether its syntax will enable what you're looking to accomplish.
Parsers aren't that difficult to write. However, if you are working on a project that accepts data from 100 different sources then it is delightful to have a single syntax for the file format. Hence XML.

When designing a language you want to program in, implementing a parser isn't really any trouble since it will generally have only one syntax*. The real trouble is designing an unmbiguous syntax you feel comfortable typing and comfortable reading. If it's context free so as to allow even easier parsing and therefore very easy tool development -well, that's just icing on the cake.

* I believe Paul Graham intends to have two syntaxes (syntacies?) for Arc. One for hacking in and one for writing tools in. This was in fact the original intention of John McCarthy with Lisp -M-Expressions and S-Expressions, but S-Expressions proved to be adequate for many people to program with. With this strategy in mind, it might be a nice idea to have two syntaxes for the OP's language. One that compiles to an intermediate language (in XML) and then that gets compiled to another language.

This is exactly the case with WYSIWYG editors for HTML.
Advertisement
XML syntax is absolutely horrible for writing code (see Ant/NAnt build files for example) and parsing isn't really the difficult bit of creating a scripting language anyway - flex and bison solve the parsing problem rather better than a generic XML parser for a simple scripting language.

Better yet, use one of the many good existing scripting languages rather than creating your own - Python, Lua, Ruby, Lisp... there's plenty of choices out there.

Game Programming Blog: www.mattnewport.com/blog

This topic is closed to new replies.

Advertisement