summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-12-11 10:01:52 -0700
committerMike Buland <eichlan@xagasoft.com>2011-12-11 10:01:52 -0700
commit4d5d24f1da11a1279da0b5ea9351c4372a74bc43 (patch)
tree90e2e93ee24518fc098b0109871f83fbd07ac392
downloadstage-4d5d24f1da11a1279da0b5ea9351c4372a74bc43.tar.gz
stage-4d5d24f1da11a1279da0b5ea9351c4372a74bc43.tar.bz2
stage-4d5d24f1da11a1279da0b5ea9351c4372a74bc43.tar.xz
stage-4d5d24f1da11a1279da0b5ea9351c4372a74bc43.zip
Basic parser coming together.
-rw-r--r--.gitignore3
-rw-r--r--default.bld24
-rw-r--r--demo.stage24
-rw-r--r--src/parser.l43
-rw-r--r--src/parser.y81
-rw-r--r--stage.txt29
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 @@
1stage
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
2CC="g++";
3target "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/*
13rule "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
10function hello()
11{
12}
13
14situation <<start>>
15{
16// set situation end;
17// push situation somethingElse;
18
19}
20
21situation <<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
15game { return tokGame; }
16function { return tokFunction; }
17situation { return tokSituation; }
18while { return tokWhile; }
19for { return tokFor; }
20each { return tokEach; }
21in { return tokIn; }
22if { return tokIf; }
23then { return tokThen; }
24else { return tokElse; }
25command { return tokCommand; }
26goto { 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
5int yylex();
6void 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%%
42input:
43 | input situation
44 | input function
45 ;
46
47situation: tokSituation tokSituationName '{' cmpltExprList '}'
48 ;
49
50function: tokFunction tokIdent '(' ')' '{' '}'
51 ;
52
53cmpltExprList:
54 | cmpltExprList cmpltExpr
55 ;
56
57cmpltExpr: expr ';'
58 ;
59
60expr: 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
76int 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 @@
1Simple, Textual, Adventure Game Environemnt
2===========================================
3
4This is a program that loads games from files that use the Stage language to
5describe a complete adventure game. There are lots and lots of possibilities.
6
7This documentation is primarily aimed at game developers initially.
8
9Structure
10=========
11
12A game is divided into several pieces. At any point during the play of a game
13a player will be "in" a situation. Each situation provides context for the
14player. They can be thought of like rooms in a MUD game or locations in an old
15text adventure title, but are more flexible, as they allow different possible
16transitions between them as well as different contexts for commands.
17
18Each situation is effectively a block of code that is run when the situation is
19made active. I.e. that code runs when the player enters a room, say. Every
20time a situation starts it contains an empty context, but may have access to
21global parameters.
22
23Variables may be set and used, and there are some special variables that you
24have access to that control the way the system works and interactions with the
25player.
26
27New functions can be defined that can be used from any code.
28
29