Blockman========Hi, what are you doing?General=======I'm getting my troops in order.Move Blockman 5 NFork Move General 4 EEndWait Blockman
Code: (Markdown) [Select]Blockman========Hi, what are you doing?General=======I'm getting my troops in order.Move Blockman 5 NFork Move General 4 EEndWait Blockman
@Radnen - you're getting more into scenario or cutscene parsing territory. In your example, you're better off doing some line-by-line routine or flat out JS.
Could I see your Arq script? Perhaps I'll incorporate it into my cutscene manager, if you will. I wonder if it's adaptable or if you've designed it around your own static functions (if so, that's okay).
Blockman: "Hi, what are you doing?"General: "I'm getting my troops in order."move('Blockman, "5N");fork move('General, "4E");endsync;
Compiler? You'd likely want an interpreter, that would be much easier.
And I'm surprised you mention you haven't taken a "formal" compilers class when I have (just now finished) and your code would look no different than what we would do in class if not better, far better (even if it looks a bit like chicken scratch). You have the concept of it down, from lexical analysis to "code generation" (technically it's JS here and not say, IA32). I doubt a formal class could teach you much more. Besides that you shouldn't make a token for comments, they'd be stripped during lexical analysis.
Tell me, if you never took such a class, how did you learn how to build a recursive descent parser? Learn about "token"s? That Lexical analysis came before parsing, etc. It's really quite remarkable. Or you wrote it but still not certain as to how or why?
Anyways, if I was going to make my own language I would make a "byte-code" (well, they wouldn't be bytes) interpreter utilizing a stack rather than a full-blown compiler.
RadLexer.register(/^[0-9]+$/, NUM);RadLexer.register(/^print$/, PRINT); // quick way of grabbing 'print', not ideal though.RadLexer.register(/^#[^\n\r]*$/, COMMENT); // my comments start with a single #RadLexer.register(/^+$/, '+');RadLexer.register(/^-$/, '-');RadLexer.register(/^*$/, '*');RadLexer.register(/^\/$/, '/');RadLexer.register(/^;$/, ';');RadLexer.register(/^[\s]+$/, WHITESPACE);RadLexer.register(/^[^ \n\r]+$/, ERROR); // all other characters not caught by previous regex steps are errors
Probably, if the number of scripts grows, a download manager for system scripts in the editor would make sense...