From 7c90fe68b557d32b65955ffd18e2e79585a7282b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 11 Dec 2011 21:57:44 -0700 Subject: Getting closer. Real turing-complete code is coming soon --- src/parser.y | 56 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 12 deletions(-) (limited to 'src/parser.y') diff --git a/src/parser.y b/src/parser.y index b3da848..9fb2be9 100644 --- a/src/parser.y +++ b/src/parser.y @@ -1,6 +1,7 @@ %{ #include #include +#include int yylex(); void yyerror( const char *error ) { printf("%s\n", error ); } @@ -9,7 +10,8 @@ void yyerror( const char *error ) { printf("%s\n", error ); } %union { int64_t iValue; double dValue; - char *sValue; + Bu::String *sValue; + bool bValue; } %token tokGame @@ -23,15 +25,17 @@ void yyerror( const char *error ) { printf("%s\n", error ); } %token tokThen %token tokElse %token tokCommand -%token tokSituationName -%token tokIdent +%token tokSituationName +%token tokIdent %token tokGoto -%token tokString -%token tokInt -%token tokFloat -%token tokBool +%token tokString +%token tokInt +%token tokFloat +%token tokBool %token tokNull +%destructor { delete $$; printf("string deleted.\n"); } tokString tokSituationName + %token eos 0 "end of stream" %left '(' ')' '[' ']' @@ -39,12 +43,28 @@ void yyerror( const char *error ) { printf("%s\n", error ); } %left '-' '+' %% -input: - | input situation - | input function +input: gameDecl bodyDecl ; -situation: tokSituation tokSituationName '{' cmpltExprList '}' +gameDecl: tokGame '{' gameExprList '}' + ; + +gameExprList: + | gameExprList cmpltGameExpr + ; + +cmpltGameExpr: gameExpr ';' + ; + +gameExpr: tokIdent '=' expr + ; + +bodyDecl: + | bodyDecl situation + | bodyDecl function + ; + +situation: tokSituation tokSituationName { printf("Read situtaion: %s\n", (*$2).getStr() ); } '{' cmpltExprList '}' ; function: tokFunction tokIdent '(' ')' '{' '}' @@ -55,6 +75,7 @@ cmpltExprList: ; cmpltExpr: expr ';' + | tokGoto '(' expr ')' ';' ; expr: tokInt @@ -69,8 +90,19 @@ expr: tokInt | expr '*' expr | '(' expr ')' | expr '[' expr ']' - | tokGoto '(' expr ')' + | '[' ']' + | '[' listValues ']' + | '{' '}' + | '{' dictValues '}' ; + +listValues: expr + | listValues ',' expr + ; + +dictValues: expr ':' expr + | dictValues ',' expr ':' expr + ; %% int main() -- cgit v1.2.3