summaryrefslogtreecommitdiff
path: root/src/parser.y
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-12-11 21:57:44 -0700
committerMike Buland <eichlan@xagasoft.com>2011-12-11 21:57:44 -0700
commit7c90fe68b557d32b65955ffd18e2e79585a7282b (patch)
tree1713fa7b087c83cd68669a46389bd3b35ae8b840 /src/parser.y
parent78118e3b515ea5268205b4f56d914900a9535c88 (diff)
downloadstage-7c90fe68b557d32b65955ffd18e2e79585a7282b.tar.gz
stage-7c90fe68b557d32b65955ffd18e2e79585a7282b.tar.bz2
stage-7c90fe68b557d32b65955ffd18e2e79585a7282b.tar.xz
stage-7c90fe68b557d32b65955ffd18e2e79585a7282b.zip
Getting closer.
Real turing-complete code is coming soon
Diffstat (limited to 'src/parser.y')
-rw-r--r--src/parser.y56
1 files changed, 44 insertions, 12 deletions
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 @@
1%{ 1%{
2#include <stdint.h> 2#include <stdint.h>
3#include <stdio.h> 3#include <stdio.h>
4#include <bu/string.h>
4 5
5int yylex(); 6int yylex();
6void yyerror( const char *error ) { printf("%s\n", error ); } 7void yyerror( const char *error ) { printf("%s\n", error ); }
@@ -9,7 +10,8 @@ void yyerror( const char *error ) { printf("%s\n", error ); }
9%union { 10%union {
10 int64_t iValue; 11 int64_t iValue;
11 double dValue; 12 double dValue;
12 char *sValue; 13 Bu::String *sValue;
14 bool bValue;
13} 15}
14 16
15%token tokGame 17%token tokGame
@@ -23,15 +25,17 @@ void yyerror( const char *error ) { printf("%s\n", error ); }
23%token tokThen 25%token tokThen
24%token tokElse 26%token tokElse
25%token tokCommand 27%token tokCommand
26%token tokSituationName 28%token <sValue> tokSituationName
27%token tokIdent 29%token <sValue> tokIdent
28%token tokGoto 30%token tokGoto
29%token tokString 31%token <sValue> tokString
30%token tokInt 32%token <iValue> tokInt
31%token tokFloat 33%token <dValue> tokFloat
32%token tokBool 34%token <bValue> tokBool
33%token tokNull 35%token tokNull
34 36
37%destructor { delete $$; printf("string deleted.\n"); } tokString tokSituationName
38
35%token eos 0 "end of stream" 39%token eos 0 "end of stream"
36 40
37%left '(' ')' '[' ']' 41%left '(' ')' '[' ']'
@@ -39,12 +43,28 @@ void yyerror( const char *error ) { printf("%s\n", error ); }
39%left '-' '+' 43%left '-' '+'
40 44
41%% 45%%
42input: 46input: gameDecl bodyDecl
43 | input situation
44 | input function
45 ; 47 ;
46 48
47situation: tokSituation tokSituationName '{' cmpltExprList '}' 49gameDecl: tokGame '{' gameExprList '}'
50 ;
51
52gameExprList:
53 | gameExprList cmpltGameExpr
54 ;
55
56cmpltGameExpr: gameExpr ';'
57 ;
58
59gameExpr: tokIdent '=' expr
60 ;
61
62bodyDecl:
63 | bodyDecl situation
64 | bodyDecl function
65 ;
66
67situation: tokSituation tokSituationName { printf("Read situtaion: %s\n", (*$2).getStr() ); } '{' cmpltExprList '}'
48 ; 68 ;
49 69
50function: tokFunction tokIdent '(' ')' '{' '}' 70function: tokFunction tokIdent '(' ')' '{' '}'
@@ -55,6 +75,7 @@ cmpltExprList:
55 ; 75 ;
56 76
57cmpltExpr: expr ';' 77cmpltExpr: expr ';'
78 | tokGoto '(' expr ')' ';'
58 ; 79 ;
59 80
60expr: tokInt 81expr: tokInt
@@ -69,8 +90,19 @@ expr: tokInt
69 | expr '*' expr 90 | expr '*' expr
70 | '(' expr ')' 91 | '(' expr ')'
71 | expr '[' expr ']' 92 | expr '[' expr ']'
72 | tokGoto '(' expr ')' 93 | '[' ']'
94 | '[' listValues ']'
95 | '{' '}'
96 | '{' dictValues '}'
73 ; 97 ;
98
99listValues: expr
100 | listValues ',' expr
101 ;
102
103dictValues: expr ':' expr
104 | dictValues ',' expr ':' expr
105 ;
74%% 106%%
75 107
76int main() 108int main()