From ac58dc8822b154a2ce51cc1b1317bc5e57ebf655 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 11 Dec 2011 23:00:45 -0700 Subject: I think I've narrowed down how commands will work It's kinda' cool for the most part, there will have to be some ways of referencing them later. Basically, there are global commands and situation commands. With any luck, it'll just work. --- demo.stage | 36 +++++++++++++++++++++++++++++++++--- src/parser.l | 3 ++- src/parser.y | 10 ++++++++++ 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 @@ game { title = "Demo game"; + + command: "take" item + { + if item in situation.items then + { + player.inventory += item; + situation.items -= item; + display('''You pickup the ''' + item + + ''' and put it in your pocket.'''); + } + else + { + display('''You don't see anything like that here.'''); + } + } + + command: "use" item + { + if not item in player.inventory then + { + display('''You don't have anything like that in your pocket.'''); + } + else + { + } + } +} + +situation <
> +{ + player.inventory = []; } function hello() @@ -10,9 +41,8 @@ function hello() situation <> { -// set situation end; -// push situation somethingElse; - + display('''You are here, there is a wrench sitting on the table.'''); + global.command("use", } situation <> 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 @@ %x dqstr tdqstr tsqstr %% -[-{}<>=+/*,();] { return yytext[0]; } +[-{}<>=+/*,();:] { return yytext[0]; } game { return tokGame; } function { return tokFunction; } @@ -25,6 +25,7 @@ then { return tokThen; } else { return tokElse; } command { return tokCommand; } goto { return tokGoto; } +not { return tokNot; } true { yylval.bValue = true; return tokBool; } false { 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 ); } %token tokIf %token tokThen %token tokElse +%token tokNot %token tokCommand %token tokSituationName %token tokIdent @@ -54,6 +55,7 @@ gameExprList: ; cmpltGameExpr: gameExpr ';' + | commandDecl ; gameExpr: tokIdent '=' expr @@ -103,6 +105,14 @@ listValues: expr dictValues: expr ':' expr | dictValues ',' expr ':' expr ; + +commandDecl: tokCommand ':' tokString commandParamList '{' '}' + ; + +commandParamList: + | commandParamList tokString + | commandParamList tokIdent + ; %% int main() -- cgit v1.2.3