diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | default.bld | 24 | ||||
-rw-r--r-- | demo.stage | 24 | ||||
-rw-r--r-- | src/parser.l | 43 | ||||
-rw-r--r-- | src/parser.y | 81 | ||||
-rw-r--r-- | stage.txt | 29 |
6 files changed, 204 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..275e405 --- /dev/null +++ b/.gitignore | |||
@@ -0,0 +1,3 @@ | |||
1 | stage | ||
2 | .build_cache | ||
3 | .*.swp | ||
diff --git a/default.bld b/default.bld new file mode 100644 index 0000000..296453f --- /dev/null +++ b/default.bld | |||
@@ -0,0 +1,24 @@ | |||
1 | |||
2 | CC="g++"; | ||
3 | target "stage" | ||
4 | { | ||
5 | rule "exe"; | ||
6 | input files("src/*.y", "src/*.l", "src/*.cpp"); | ||
7 | |||
8 | FLEXFLAGS="-osrc/parser.yy.c"; | ||
9 | BISONFLAGS="-d"; | ||
10 | } | ||
11 | |||
12 | /* | ||
13 | rule "bison" | ||
14 | { | ||
15 | input "*.y"; | ||
16 | output [INPUT.regex("\\.y$", ".tab.c"), INPUT.regex("\\.y$", ".tab.h")]; | ||
17 | profile "build" | ||
18 | { | ||
19 | DIR=INPUT.dirName(); | ||
20 | FILE=INPUT.fileName(); | ||
21 | execute("cd ${DIR}; bison -d ${FILE}"); | ||
22 | } | ||
23 | } | ||
24 | */ | ||
diff --git a/demo.stage b/demo.stage new file mode 100644 index 0000000..b1ff4e8 --- /dev/null +++ b/demo.stage | |||
@@ -0,0 +1,24 @@ | |||
1 | //game | ||
2 | //{ | ||
3 | /* | ||
4 | title = "Demo game"; | ||
5 | |||
6 | goto <<start>>; | ||
7 | */ | ||
8 | //} | ||
9 | |||
10 | function hello() | ||
11 | { | ||
12 | } | ||
13 | |||
14 | situation <<start>> | ||
15 | { | ||
16 | // set situation end; | ||
17 | // push situation somethingElse; | ||
18 | |||
19 | } | ||
20 | |||
21 | situation <<end>> | ||
22 | { | ||
23 | goto( <<start>> ); | ||
24 | } | ||
diff --git a/src/parser.l b/src/parser.l new file mode 100644 index 0000000..d5ff735 --- /dev/null +++ b/src/parser.l | |||
@@ -0,0 +1,43 @@ | |||
1 | %{ | ||
2 | #include <stdint.h> | ||
3 | #include "parser.tab.h" | ||
4 | %} | ||
5 | |||
6 | %option noyywrap | ||
7 | |||
8 | %x sitname | ||
9 | %x comment | ||
10 | %x tdqstr tsqstr | ||
11 | %% | ||
12 | |||
13 | [-{}<>=+/*,();] { return yytext[0]; } | ||
14 | |||
15 | game { return tokGame; } | ||
16 | function { return tokFunction; } | ||
17 | situation { return tokSituation; } | ||
18 | while { return tokWhile; } | ||
19 | for { return tokFor; } | ||
20 | each { return tokEach; } | ||
21 | in { return tokIn; } | ||
22 | if { return tokIf; } | ||
23 | then { return tokThen; } | ||
24 | else { return tokElse; } | ||
25 | command { return tokCommand; } | ||
26 | goto { return tokGoto; } | ||
27 | |||
28 | "<<" { BEGIN( sitname ); } | ||
29 | <sitname>[- a-zA-Z0-9]+ { printf("situation: %s\n", yytext ); return tokSituationName; } | ||
30 | <sitname>">>" { BEGIN( INITIAL ); } | ||
31 | <sitname>. REJECT; | ||
32 | |||
33 | "//"[^\n]* {} | ||
34 | |||
35 | "/\*" { BEGIN( comment ); } | ||
36 | <comment>"\*/" { BEGIN( INITIAL ); } | ||
37 | <comment>. {} | ||
38 | |||
39 | [a-zA-Z_][a-zA-Z0-9_]* { return tokIdent; } | ||
40 | |||
41 | [ \t\n\r]+ {} | ||
42 | |||
43 | %% | ||
diff --git a/src/parser.y b/src/parser.y new file mode 100644 index 0000000..b3da848 --- /dev/null +++ b/src/parser.y | |||
@@ -0,0 +1,81 @@ | |||
1 | %{ | ||
2 | #include <stdint.h> | ||
3 | #include <stdio.h> | ||
4 | |||
5 | int yylex(); | ||
6 | void yyerror( const char *error ) { printf("%s\n", error ); } | ||
7 | %} | ||
8 | |||
9 | %union { | ||
10 | int64_t iValue; | ||
11 | double dValue; | ||
12 | char *sValue; | ||
13 | } | ||
14 | |||
15 | %token tokGame | ||
16 | %token tokFunction | ||
17 | %token tokSituation | ||
18 | %token tokWhile | ||
19 | %token tokFor | ||
20 | %token tokEach | ||
21 | %token tokIn | ||
22 | %token tokIf | ||
23 | %token tokThen | ||
24 | %token tokElse | ||
25 | %token tokCommand | ||
26 | %token tokSituationName | ||
27 | %token tokIdent | ||
28 | %token tokGoto | ||
29 | %token tokString | ||
30 | %token tokInt | ||
31 | %token tokFloat | ||
32 | %token tokBool | ||
33 | %token tokNull | ||
34 | |||
35 | %token eos 0 "end of stream" | ||
36 | |||
37 | %left '(' ')' '[' ']' | ||
38 | %left '*' '/' | ||
39 | %left '-' '+' | ||
40 | |||
41 | %% | ||
42 | input: | ||
43 | | input situation | ||
44 | | input function | ||
45 | ; | ||
46 | |||
47 | situation: tokSituation tokSituationName '{' cmpltExprList '}' | ||
48 | ; | ||
49 | |||
50 | function: tokFunction tokIdent '(' ')' '{' '}' | ||
51 | ; | ||
52 | |||
53 | cmpltExprList: | ||
54 | | cmpltExprList cmpltExpr | ||
55 | ; | ||
56 | |||
57 | cmpltExpr: expr ';' | ||
58 | ; | ||
59 | |||
60 | expr: tokInt | ||
61 | | tokFloat | ||
62 | | tokString | ||
63 | | tokBool | ||
64 | | tokNull | ||
65 | | tokSituationName | ||
66 | | expr '+' expr | ||
67 | | expr '-' expr | ||
68 | | expr '/' expr | ||
69 | | expr '*' expr | ||
70 | | '(' expr ')' | ||
71 | | expr '[' expr ']' | ||
72 | | tokGoto '(' expr ')' | ||
73 | ; | ||
74 | %% | ||
75 | |||
76 | int main() | ||
77 | { | ||
78 | yyparse(); | ||
79 | return 0; | ||
80 | } | ||
81 | |||
diff --git a/stage.txt b/stage.txt new file mode 100644 index 0000000..751b1f0 --- /dev/null +++ b/stage.txt | |||
@@ -0,0 +1,29 @@ | |||
1 | Simple, Textual, Adventure Game Environemnt | ||
2 | =========================================== | ||
3 | |||
4 | This is a program that loads games from files that use the Stage language to | ||
5 | describe a complete adventure game. There are lots and lots of possibilities. | ||
6 | |||
7 | This documentation is primarily aimed at game developers initially. | ||
8 | |||
9 | Structure | ||
10 | ========= | ||
11 | |||
12 | A game is divided into several pieces. At any point during the play of a game | ||
13 | a player will be "in" a situation. Each situation provides context for the | ||
14 | player. They can be thought of like rooms in a MUD game or locations in an old | ||
15 | text adventure title, but are more flexible, as they allow different possible | ||
16 | transitions between them as well as different contexts for commands. | ||
17 | |||
18 | Each situation is effectively a block of code that is run when the situation is | ||
19 | made active. I.e. that code runs when the player enters a room, say. Every | ||
20 | time a situation starts it contains an empty context, but may have access to | ||
21 | global parameters. | ||
22 | |||
23 | Variables may be set and used, and there are some special variables that you | ||
24 | have access to that control the way the system works and interactions with the | ||
25 | player. | ||
26 | |||
27 | New functions can be defined that can be used from any code. | ||
28 | |||
29 | |||