Page 1 of 1

Own parser

Posted: Wed Jul 08, 2009 11:08 am
by morpheouss
Hello,

Last time i have hit upon a new idea, to create a new programming language and parser for it. I would like its syntax to be similiar to something between C and C++ with some addition and changes (w/o details for now), but designed for webmasters, like PHP. I have hit upon this idea, when PHP begun to go into the wrong direction:
1) Poor OOP
2) Bad namespaces implementation
3) Controversial namespace separator

That's only a few...
Due to that i would like to create my own language and parser for it, that would check code for errors, show potential warnings and 'execute' program showing it results in parallel. I dont want to supercede PHP or any other language. I would just like to create my own small language parser that would like to work in console in both Windows & Unix.

I would like to ask You about opinion and some tips, eg what tools should i use for that. Best i would like to do it in clean OOP C++ without the ussage of utilities like bison. I would also like You to not tell me that there are already many languages that are suitable for software development. Even if my project would come to an end i am sure that i can learn something from it. I hope You will understand me.

Thanks for Your advices, opinions and Your time!

Re: Own parser

Posted: Wed Jul 08, 2009 2:44 pm
by stephenj
The first question I'd ask is what are your grammar requirements. Is your grammar going to be LL(1), LR(1), LALR(1), GLR, etc? You choice of tool will probably vary depending on how you answer this question. You could always write your parse-tree generator by hand, but that is an annoying path. You've mentioned C and C++ as a model, but the two languages have different requirements in this regard. As a side note, I tried writing a parser generator from scratch, but gave up because I lack the time (I'm much further along in a shorter period by using bison). I'll probably revisit the problem years from now when I start thinking about higher level languages (my current one is C-like).

The second question is about the "execution/displaying results in parallel" part? Why not just use a log file (or something similar)?

The third question I have is are you going to be compiling/interpreting your language?

The fourth question is if you've ever tried Ruby or Python? When I went to design my system programming language I went out and studied other languages to see how they did things. Re-inventing the wheel is bad enough, but re-discovering it is worse. And there are some pretty impressive features in these languages.

Beyond that, I don't know what to tell you because I don't know what you want. If you have yet to read a book on the topic, do so. If English isn't your native tongue, then look into books in your first language, otherwise, I suppose I'd recommend Parsing Techniques*. It is the best book I've read on the subject.

*To make the URL work, replace the u in duck with an i. @mods, can that word be taken out of the default censoring? It is an English name after all.

Re: Own parser

Posted: Wed Jul 08, 2009 3:06 pm
by morpheouss
1) LL(1), LR(1), LALR(1), GLR? I think i should read about that ;) Lets say i want to wrie sth like php actually is making it more C-like strict, so if($x AND $y) would not work as there is no AND keyword in C - only &&. I would also add some lacking features and improove OOP. But thats a long-time plan. Actually i would like to focus on imperative paradigm only.
2) as i wrote i wpuld like it to be designed for webmasters in the future, so i want to display erros, warnings, results in web browser, like php does. however actually i want it to work from command line only
3) i'd like it to be interpreted only (no compilation & consolidation)
4) Yes i tried them

I thought about making classes eg

class Variable {
};
that would store single variable and information about it (name, type, value, etc...) and put it into vector (all tokens stored in vectors). Then i could check if variable exist or not and eg show error. But not sure if this is a good idea?

Re: Own parser

Posted: Wed Jul 08, 2009 3:22 pm
by stephenj
I think you should read up on the subject of language design and implementation. Before long you'll be able to answer these questions yourself.

Re: Own parser

Posted: Thu Jul 09, 2009 1:17 pm
by Brendan
Hi,
morpheouss wrote:I would like its syntax to be similiar to something between C and C++ with some addition and changes (w/o details for now), but designed for webmasters, like PHP.
I assume that you are aware that it's possible to use almost any language to create a CGI for a web server? I've implemented forums and a web interface to a database in C before, and it's not really very hard.

When someone downloads the web page, the web server (Apache in my case) sets environment variables for things like the client's IP address, browser type, etc; and starts your executable. "stdin" is used for data being sent to the web page (input boxes, forms, file uploads, etc); and the binary uses "stdout" to send data to the web server (which sends it to the client), so you can do "printf("Hello world!\n");" and when someone sends their browser to "http://foo.com/cgi/bar" they get "Hello world!" back.


Cheers,

Brendan

Re: Own parser

Posted: Sun Jul 12, 2009 7:37 am
by Owen
Of course it's important to be aware that CGIs are ridiculously slow.

It's successor FastCGI is so much better

Re: Own parser

Posted: Tue Aug 11, 2009 4:44 am
by AndrewAPrice
There is also ASP.Net. I haven't used it, but it allows you to write web applications in any .Net language (VB.Net, C#, etc).

Re: Own parser

Posted: Tue Aug 11, 2009 8:57 am
by Narida
I can recommend the following tutorial on compiler development: http://compilers.iecc.com/crenshaw/
There's a part about interpreters in in too.
Theoretically, you don't need any tools, you can write your own lexical and syntactical analyzer relatively easily...it is explained pretty clearly in the tutorial^^.

Re: Own parser

Posted: Wed Aug 12, 2009 11:33 am
by earlz
I am a believer that it is not necessary to define a formal grammar in order to make a decent language, and that creating your own parser isn't impossible...

edit:
I do like that crenshaw link. It's a very good tutorial on creating a compiler or interpreter.

Re: Own parser

Posted: Wed Aug 12, 2009 9:50 pm
by tantrikwizard
earlz wrote:I am a believer that it is not necessary to define a formal grammar in order to make a decent language
I'll second that. Compilers are relatively trivial (depending on the utility of the language and target platform.) But for the most part are pretty straight forward. The real complexity comes from optimal code generation. If you're not too concerned about performance or optimal code generation compilers are relatively simple.