Creating a scripting language that will be used to create web pages

I am creating a scripting language that will be used to create web pages, but I don’t know where to start.

I have a file that looks like this:


mylanguagename(main) { OnLoad(protected) { Display(img, text, link); } Canvas(public) { Image img: "Images\my_image.png"; img.Name: "img"; img.Border: "None"; img.BackgroundColor: "Transparent"; img.Position: 10, 10; Text text: "This is a multiline str#ning. The #n creates a new line."; text.Name: text; text.Position: 10, 25; Link link: "Click here to enlarge img."; link.Name: "link"; link.Position: 10, 60; link.Event: link.Clicked; } link.Clicked(sender, link, protected) { Image img: from Canvas.FindElement(img); img.Size: 300, 300; } } 

... and I should be able to make this text higher than the goal for the Windows Scripting Host. I know that this can be done, because before there were many Documents on the network, but I can not find them now.

Can someone help or start me in the right direction?

thanks

+6
c # scripting-language wsh
source share
10 answers

You are creating a language specific to a domain that does not exist. You want to translate into another language. You will need the right scanner and parser. You were probably told to look at antlr. yacc / bison, or gold. What went wrong with that?

And like FYI, this is a fun exercise to create new languages, but before you do something like this, you can ask a good solid “why? What is my new language doing so that I cannot get any other (sensible) way?”

+5
source share

What you need to understand in parsing and creating a language is that writing a compiler / interpreter is mainly related to a set of data transformations performed with the input text.

As a rule, from the input text, you first translate it into a series of tokens, each marker represents a concept in your language or a literal value.

From the token stream, you usually create an intermediate structure, usually some kind of tree structure that describes the written code.

This tree structure can then be verified or modified for various reasons, including optimization.

Once this is done, you usually write the tree in some other form — assembly instructions or even a program in another language — in fact, the earliest versions of C ++ wrote direct C code, which was then compiled by the regular C compiler, who didn't know about C ++ at all. Therefore, skipping the assembly assembly step may seem like a hoax, it has a long and proud tradition :)

I deliberately did not enter into any proposals for specific libraries, since understanding the general process is probably much more important than choosing a specific parser technology, for example. Whether you use lex / yacc or ANTLR, or something else is not very important in the long run. They all (mainly) work, and all of them have been successfully used in various projects.

Even doing your own analysis manually is not a bad idea, as it will help you learn the patterns of how the parsing is done, and so using a parser generator will tend to make more sense than being a black voodoo box.

+3
source share

Languages ​​like C # are not easy to parse - of course, there are left-recursive rules. Therefore, you should use a parser generator that can handle them properly. ANTLR is well suited.

If PEG works best, try the following: http://www.meta-alternative.net/mbase.html

+2
source share

So, do you want to translate C # programs to JavaScript? Script # can do this for you.

+1
source share

Instead of writing your own language and then running a translator to convert it to Javascript, why not extend Javascript to do what you want?

Take a look at jQuery - it extends Javascript in many powerful ways with very natural and smooth syntax. This is almost as good as your own language. Take a look at the many extensions people created for it, especially jQuery UI.

+1
source share

Assuming you are truly committed to this, here is the way. This is usually what you should do: source -> SCANNER -> tokens -> PARSER syntax tree ->

1) Create a scanner / parser to analyze your language. You need to write a grammar to generate a parser that can scan / parse your syntax, tokenize / validate them.

I think the easiest way to go with Irony is to make creating a parser quick and easy. Here is a good starting point

http://www.codeproject.com/KB/recipes/Irony.aspx

2) Building a syntax tree. In this case, I suggest you create a simple XML view instead of the actual syntax tree so that you can later view the XML representation of your DOM to spit out VB / Java Script. If your requirements are complex (for example, you want to compile them), you can create a tree of DLR expressions or use the DOM code - but here I think that this is a translator, not a compiler.

But wait, if this is not for educational purposes, consider presenting your “script” as xml from the very beginning, so that you can avoid the scanner / parser between them before spitting out some VB / Java script / Html from this.

+1
source share

You obviously need a technique for translating languages: parsing, tree building, pattern matching, tree building in the target language, target printing in the target language. You can try to do all of this with YACC (or equivalents), but you will find that parsing is only a small part of the complete translator. This means that a lot more work and not just parsing, and it takes time and effort.

Our DMS Software Reengineering Toolkit is a commercial solution for building complete translators at relatively modest costs.

If you want to do it yourself, from the very beginning, this is an exercise. Just be prepared for the efforts that are truly needed.

One final note: creating a complete language is difficult if you want to get a good result.

0
source share

I don't want to be rude ... but why are you doing this?

Creating a parser for an ordinary language is not a trivial task. Just don't do it.

Why don't you just use html, javascript and css (and jquery, as someone suggested above)

If you don’t know where to start, you probably don’t have that kind of experience and you probably don’t have a good reason why to do this.

I want to save you pain. Forget it. This is probably a BAD IDEA!

M.

0
source share
  • Check out Building language processors for small languages . This is a very good introduction, I believe. Actually, I just consulted my copy 2 days ago when I was having problems with my template parser.

  • Use XML, if at all possible. You do not want to bother with the lexer and parser manually if you want this thing to be in production. I have made this mistake several times. You end up supporting code that you really shouldn't be. It seems that your language is mostly a template language. XML will work fine there. Just like ASPX files are XML. Blocks on the server side can be written in Javascript, modified if necessary. If this is a training exercise, do it all manually, by all means.

I think writing your own language is a great exercise. So, take the college level compiler writing class. Good luck.

0
source share

Personally, I believe that every self-imposed challenge is good. I agree with other opinions that if what you want is a real solution to the problem of real life, it's probably best to stick to proven solutions. However, if, as you said yourself, you have an academic interest in solving this problem, then I urge you to continue. If so, I can provide a couple of tips to help you find the track.

Disassembly is actually not an easy task, so we take at least a semester. However, this can be found out. I would recommend starting with Terrence Parr's book on language implementation patterns . There are many great books on compilation and parsing, probably the Dragon Book was the most beloved and hated.

It's pretty hard stuff, but if you really do it and you have the time, you should definitely take a look. It will be Robisson Crusoe, "I will do everything on my own." I recently wrote an LR parser generator, and it took me no more than a long weekend, but this after reading a lot and a full course of two semesters on compilers.

If you don’t have time or just don’t want to learn how to make a parser “like men”, you can always try a commercial or academic parser generator. ANTLR is excellent, but you should learn its metalanguage. Personally, I think Irony is a great tool, especially because it stays inside C # and you can take a look at the source code and find out for yourself. Since we are here, and I am not trying to advertise at all, I have placed a tiny tool in CodePlex that can be useful for this task. Take a look for yourself, open source and free.

As a final tip, don't be afraid if someone tells you that this is not possible. Analysis is a complex theoretical problem, but it’s nothing that is impossible to learn, and it’s really a great tool for your portfolio. I think that he speaks very well about the developer, that he can manually write a recursive parser, even if he does not need it. If you want to pursue this goal to the end, take a college-level compiler course, you will thank me in a year.

0
source share

All Articles