summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--demo.stage36
-rw-r--r--src/parser.l3
-rw-r--r--src/parser.y10
3 files changed, 45 insertions, 4 deletions
diff --git a/demo.stage b/demo.stage
index 3d10efe..78e705c 100644
--- a/demo.stage
+++ b/demo.stage
@@ -2,6 +2,37 @@
2game 2game
3{ 3{
4 title = "Demo game"; 4 title = "Demo game";
5
6 command: "take" item
7 {
8 if item in situation.items then
9 {
10 player.inventory += item;
11 situation.items -= item;
12 display('''You pickup the ''' + item +
13 ''' and put it in your pocket.''');
14 }
15 else
16 {
17 display('''You don't see anything like that here.''');
18 }
19 }
20
21 command: "use" item
22 {
23 if not item in player.inventory then
24 {
25 display('''You don't have anything like that in your pocket.''');
26 }
27 else
28 {
29 }
30 }
31}
32
33situation <<main>>
34{
35 player.inventory = [];
5} 36}
6 37
7function hello() 38function hello()
@@ -10,9 +41,8 @@ function hello()
10 41
11situation <<start>> 42situation <<start>>
12{ 43{
13// set situation end; 44 display('''You are here, there is a wrench sitting on the table.''');
14// push situation somethingElse; 45 global.command("use",
15
16} 46}
17 47
18situation <<end>> 48situation <<end>>
diff --git a/src/parser.l b/src/parser.l
index dff6507..59a0358 100644
--- a/src/parser.l
+++ b/src/parser.l
@@ -11,7 +11,7 @@
11%x dqstr tdqstr tsqstr 11%x dqstr tdqstr tsqstr
12%% 12%%
13 13
14[-{}<>=+/*,();] { return yytext[0]; } 14[-{}<>=+/*,();:] { return yytext[0]; }
15 15
16game { return tokGame; } 16game { return tokGame; }
17function { return tokFunction; } 17function { return tokFunction; }
@@ -25,6 +25,7 @@ then { return tokThen; }
25else { return tokElse; } 25else { return tokElse; }
26command { return tokCommand; } 26command { return tokCommand; }
27goto { return tokGoto; } 27goto { return tokGoto; }
28not { return tokNot; }
28 29
29true { yylval.bValue = true; return tokBool; } 30true { yylval.bValue = true; return tokBool; }
30false { yylval.bValue = false; return tokBool; } 31false { yylval.bValue = false; return tokBool; }
diff --git a/src/parser.y b/src/parser.y
index 9fb2be9..7242df0 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -24,6 +24,7 @@ void yyerror( const char *error ) { printf("%s\n", error ); }
24%token tokIf 24%token tokIf
25%token tokThen 25%token tokThen
26%token tokElse 26%token tokElse
27%token tokNot
27%token tokCommand 28%token tokCommand
28%token <sValue> tokSituationName 29%token <sValue> tokSituationName
29%token <sValue> tokIdent 30%token <sValue> tokIdent
@@ -54,6 +55,7 @@ gameExprList:
54 ; 55 ;
55 56
56cmpltGameExpr: gameExpr ';' 57cmpltGameExpr: gameExpr ';'
58 | commandDecl
57 ; 59 ;
58 60
59gameExpr: tokIdent '=' expr 61gameExpr: tokIdent '=' expr
@@ -103,6 +105,14 @@ listValues: expr
103dictValues: expr ':' expr 105dictValues: expr ':' expr
104 | dictValues ',' expr ':' expr 106 | dictValues ',' expr ':' expr
105 ; 107 ;
108
109commandDecl: tokCommand ':' tokString commandParamList '{' '}'
110 ;
111
112commandParamList:
113 | commandParamList tokString
114 | commandParamList tokIdent
115 ;
106%% 116%%
107 117
108int main() 118int main()