HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How do you make a preprocessor?

12-18-2009, 07:44 AM#1
thelifelessone
Other than the obvious fact you need to program it, how do you make it?
What tools do you use? How do you parse something (like vJASS, for example), into something else (like JASS)?

I'm making a map, and because of the way I'm planning it, I think I may need to make my own preprocessor so I can have the exact features I need.

It doesn't really need to be fast. It just needs to work well. I don't plan on making it a public resource.


Thanks for any help.
12-18-2009, 12:02 PM#2
Seshiro
If you already have some coding expirience in an Highlevel Programming Language, I'd advise you to use Regexes(Patterns) and RegexGroups, it's such an easy way .. If you have knowledge of C# I could give you the Sourcecode of my not yet finished but working Simple Perprocessor O've made.

Else you could use something that's called a Lexer with taht I really don't have any exprience :D

Greez
12-18-2009, 08:03 PM#3
thelifelessone
I know a bit of C#.
12-18-2009, 08:29 PM#4
Seshiro
So, heres the project ... It is not really commented or something kinda, because I didn't think it's necessary.
But I guess, that it's self explanatory!

You can contact me via PM to excahnge ICQ or MSN contacts when you need help.

Greez

BTW, It's made with VSStudio 2010 BETA, so you have to use it to :D Or you open all files in an textEditor :DD
Attached Files
File type: 7zDefines++.7z (147.3 KB)
12-18-2009, 08:51 PM#5
thelifelessone
Thanks! +rep.

> Or you open all files in an textEditor :DD
I've got Visual Studio 08. I can get the beta if I need it (and if possible).
12-19-2009, 08:29 AM#6
Vestras
A parser just gets the information from code, and it is a parser you would probably rather use. For this, most people use GOLD Parser Builder. That's what Vex used :)
12-19-2009, 12:25 PM#7
thelifelessone
Yeah, but I'm too lazy to learn how to use it.
12-19-2009, 12:45 PM#8
Seshiro
So, just for explanation what , my parser does, it checks for things inside < > Brackets and parses them, like cjass, BUT here you can use modular regexgroups, so you can do extended things like this:
Code:
syntax{
 <::> = { uses }
 <0x(?$number$[a-zA-Z0-9]+)> = { Found Hex: Ox$number$ }
	<(?$name$[a-zA-Z]+) is a humpa lumpa> = { call BJDebugMsg("$name$ is a Humpa Lumpa") }
}

library XY :: XZ

0x100

Seshiro is a humpa lumpa
Vestras is a humpa lumpa

Guess what Happens :D
02-25-2010, 08:23 PM#9
Mooglefrooglian
If you have to ask, I dont think you should be making one, but whatever. If you want to go the full vJass route, you need to:

Remove all comments.
Parse the entire map and replace any defines (if you have that feature).
Read every line, remove whitespace, and check for certain keywords as being first, such as "library".
Find out what the line is doing and check for mistakes. The method I would use is: check if the line starts with any special keywords, such as "library". If it contains none, figure out if it is setting a variable, or calling a function, or whathaveyou. I would just check the line for an "=" sign, if its there, say its setting a variable, if it isnt, assume your calling a function I guess.

If you have a keyword that makes a function block and you find that keyword, check and find the end of the block and then parse everything inside of it as above.

Make a list of variables inside the function, with their types, then make a list of all the functions that can be called. If your line is calling a function, find out its arguments, and check the variables given to it against your list of variables. If the variable referenced doesnt exist, check if it is a string (see if it has two quotes), etc.

Really though, why would you want a preprocessor just for some features your map "needs" is beyond me. And if you couldnt think of the stuff above, you may just want to ask someone else to do it.

Highly recommend learning how Grimoire works by browsing the wehack.lua file inside your JNGP folder. Its fairly obvious how to set things up, and being able to put your preprocessor into WE is always a nice feeling.

I'm going to try making something like vJass for sc2 just because it seems so interesting.