Page 1 of 1
My own Macro Language
Posted: Tue Mar 11, 2008 4:45 pm
by Altair
Hello All,
I've been developing in PHP for several years, but in other languages for several more Wink
Anyway... I have been combing the internet for a simple (I MEAN SIMPLE) custom language parser. Let me explain what I'm trying to do.
I'm trying to develop a simplified macro type parse in php... Example of the custom language:
Code: Select all
cvar myVar1 = 'hello world';
cvar myVar2 = 'blah';
if (myVar1 != myVar2)
{ storeToDB(); }
Do any of you have any idea how to do this without developing some uber complex lexer and parser situation? Or perhaps you know where I might find one that I can use in my code set?
Keep in mind that my goal is that this is developed in PHP.
Does that make sense? Let me know if more info is needed.
Re: My own Macro Language
Posted: Tue Mar 11, 2008 5:44 pm
by alex.barylski
If your after a macro language, why not use an existing such as GNU cpp or m4?
Implementing your own, would be a helluva lot of work. If it's required to be done in PHP your in for a ruff ride.
Re: My own Macro Language
Posted: Tue Mar 11, 2008 5:57 pm
by Altair
Hockey wrote:If your after a macro language, why not use an existing such as GNU cpp or m4?
Implementing your own, would be a helluva lot of work. If it's required to be done in PHP your in for a ruff ride.
hmmm... You might be right... This may be a lost cause. Perhaps I should think of an alternative method of getting this same effect.
Thanks for the response

Re: My own Macro Language
Posted: Wed Mar 12, 2008 4:08 am
by Mordred
1. Why do you need this, what is the problem that you're trying to solve?
2. The easiest way to do this, is to make a tool that transforms your language to PHP
Re: My own Macro Language
Posted: Wed Mar 12, 2008 11:45 pm
by Altair
Mordred wrote:1. Why do you need this, what is the problem that you're trying to solve?
My goal with this is to allow my users to "program" components within my site. It was a thought I had to make things a bit more interesting for any developers/technically minded individuals that use my site.
The idea is that the user would be able to do something like:
Code: Select all
cvar comp1 = getComp(132);
cvar comp2 = getComp(145);
cvar combined = null;
if (isCompatible(comp1, comp2))
{ combined = combine(comp1, comp2); }
compile(combined);
That's obviously a very rough example... But that example would basically combine component 1 and component 2 to create a new component with the attributes and abilities of both components.
Mordred wrote:2. The easiest way to do this, is to make a tool that transforms your language to PHP
That's kind of what I'm trying to do, but, as far as I can tell, a tool like that would have to have some kind of grammatical parser which would indicate (for performance needs) that I need a lexer and parser to accomplish that task.
However, as I'm thinking, I suppose it would be possible to generate a list of methods within a standard php class and only allow those methods to be used. But again... I would have to parse the string (which could be huge) to insure that ONLY THOSE methods, functions, constants, etc... were being used which could be a slow and painful process. Though that might not be a terrible thing. It might add to the entertainment of this idea, giving the impression that these components are highly complex
I'm not sure... Maybe I'm thinking about this all wrong.