grammar proto1
[henge/webcc.git] / src / parser.y
1 /* Asset Package Compiler */
2 %{
3 #include <stdio.h>
4 #include <string.h>
5 #include <dirent.h>
6 #include "sprite.h"
7 #include "symbol.h"
8 #include <png.h>
9
10
11 extern int lexer_init();
12 extern int lexer();
13 #define yylex lexer
14
15
16 void yyerror();
17 %}
18 %define parse.error verbose
19 %define lr.type ielr
20 %define api.value.type union
21 %token <int> NUM
22 %token <char*> WORD
23 //operators
24 %token PROTOCLASS //+
25 %token SIBS //|
26 %token FNAME //!
27 //nonterminal types
28 %type <int> fd
29 %type <int*> fdlist
30
31 /* %token <str> EXT */
32 /* %token <str> FW */
33 /* %token <str> SPR */
34 /* %token CC */
35 /* /\* Rules *\/ */
36 /* %% */
37 /* SS: SPR '/' MD '.' EXT */
38 /* MD: CC '_' FW */
39 /* | FW */
40 /* | CC */
41
42 /* Rules */
43 %%
44
45 object_defs:
46 %empty
47 | arch_id object_defs
48 ;
49
50 arch_id:
51 archetype
52 | arch_id_ref
53 ;
54
55 arch_id_list:
56 arch_id
57 | arch_id arch_id_list
58 ;
59
60 archetype:
61 PROTOCLASS label arch_id_list SIBS arch_id_list
62 | PROTOCLASS label arch_id_list
63 | label arch_id_ref vdat
64 ;
65
66 label:
67 WORD
68 ;
69
70 arch_id_ref:
71 NUM
72 ;
73
74 vdat:
75 spritesheet
76 ;
77
78 spritesheet:
79 fdlist
80 ;
81
82 fdlist:
83 fd
84 | fd fdlist
85 ;
86
87 fd:
88 FNAME WORD
89 | NUM;
90 %%
91
92 int
93 main(int argc, char** argv)
94 { /* Parse cmd line arguments */
95 lexer_init();
96 yyparse(); /* runs handle_fname for each filename */
97 return 0;
98 }
99
100 void
101 yyerror (char const *s)
102 { fprintf(stderr, "%s\n", s);
103 }