summaryrefslogtreecommitdiff
path: root/src
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 /src
downloadstage-4d5d24f1da11a1279da0b5ea9351c4372a74bc43.tar.gz
stage-4d5d24f1da11a1279da0b5ea9351c4372a74bc43.tar.bz2
stage-4d5d24f1da11a1279da0b5ea9351c4372a74bc43.tar.xz
stage-4d5d24f1da11a1279da0b5ea9351c4372a74bc43.zip
Basic parser coming together.
Diffstat (limited to 'src')
-rw-r--r--src/parser.l43
-rw-r--r--src/parser.y81
2 files changed, 124 insertions, 0 deletions
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