Script parser - which files?


(Flippy) #1

Hey,

Can anyone tell me which files of the SDK (2.60) take part in the parsing of the script file before loading a map?

I need them for ETScript, want to include this functionality…

Till now I have found some bits in g_script.c and mainly in g_script_actions.c but I don’t think that’s ALL there is, or is it?


(SCDS_reyalP) #2

Look for the COM_Parse* calls in those files.


(Flippy) #3

I see…

Where can I find the code for these COM_Parse calls?

I’m sorry, I have absolutely NO experience in C…
I had a feeling the actuall parsing was done in the COM_Parse sections… but couldn’t find them.


(Ragnar_40k) #4

In MS Visual Studio you can search all project file with STRG+SHIFT+F (most editors have such features). When you enter “COM_Parse” as search phrase it will list all occurences in a window. You only need to double click a find to open the according source file at the correct position. In the source file you can right click a function name etc. (to open the context menu) and choose “Go To Declaration” or “Go To Definition”.

I just checked it with MS Visual Studio Beta 2 (its currently freely available: http://msdn2.microsoft.com/en-us/evalcenter/bb655864.aspx ). Just double click the wolf.sln-project file and VS will open up. Click through the dialogs to convert the project file to the new version. You can even build the game (don’t forget to set $(WOLFDIR)).

But imho (when you have absolutely no C experience) you should go another way: Use something like yacc+lex to mimic script parsing and execution. This way its much easier to support different versions (e.g. ETPro vs. ETMain) or to apply changes/updates. Yacc- resp. lex-like tools should be available for most programming languages.


(Flippy) #5

I have VS2005 so that’s no problem.
What’s “STRG” though, lol?
I will try some things out…

I will see what yacc and lex is… are they plugins or something?

Thanks for the help.


(Shaderman) #6

CTRL


(Ragnar_40k) #7

Oops, STRG (Steuerung) is German for the English CTRL (Control).

Lex creates a scanner and Yacc is a compiler-compiler.

So lex creates the program source for a scanner, which parses a file into tokens. It takes only a (relativly) simple syntax file based on regular expressions. And yacc creates the source for a compiler (syntax usually given in BNF), so you can create a program which runs scripts.


Yacc and lex work for C, but there are similar tools available for nearly all programming languages.


(SCDS_reyalP) #8

Look in q_shared.c

I typically use grep to find things like this.

If you have no experience in C, the parsing code will probably take you quite a bit of work to fully understand.

The Q3 parsing stuff doesn’t come from lex and yacc
edit: I realize Ragnar_40k wasn’t suggesting that it was, but you should be aware that et script syntax might have quirks specific to the way it was implemented.


(Ragnar_40k) #9

Afaics WET just looks at the script code character by character and accepts a string or rewinds to an earlier position and tries again (resp. returns an error). Lex has the lookahead-operator, which does basically the same thing, so you can mimic this 1:1 if needed. But I guess lexical analysis isn’t the problem.

A problem might be to implement script execution correctly (including bugs). But here you can start with an approach which works correctly in 99.9% of the cases and add handling for special quirks later on if needed (which should be relativly easy when you use yacc or something similar).