parser wip pt2
[henge/webcc.git] / src / apc / parser.y
diff --git a/src/apc/parser.y b/src/apc/parser.y
new file mode 100644 (file)
index 0000000..c16dc18
--- /dev/null
@@ -0,0 +1,175 @@
+/* Asset Package Compiler */
+%{
+  #include <stdio.h>
+  #include <string.h>
+  #include <dirent.h>
+  #include "sprite.h"
+  #include "symbol.h"
+  #include <png.h>
+  #include "ir.h"
+
+  extern int lexer_init();
+  extern int lexer();
+  #define yylex lexer
+
+
+  void yyerror();
+%}
+%define parse.error verbose
+%define lr.type ielr
+%define api.value.type union
+%token <char*> WORD
+//operators
+%token         CLOPEN   // /
+%token         CLCLOSE  // \
+%token         RLS     //!
+%token         RLE    //#
+%token         RT     //*
+%token         HB
+//nonterminal types
+%type <int> element
+%type <int> vdat
+%type <str> elem_label
+//terminals
+%token <int> NUM
+%token <int> fd
+%token <str> STR
+%token <int> VAR
+%token <int> SS
+//precedence
+%right LOW HIGH
+
+/* Syntax Directed Translation Scheme of the APC grammar */
+
+
+/* Rules */
+%%
+output:
+class_list                   {condense();} //Seperate file?
+;
+
+class_list:
+class_list class             {cbi++;};
+| class
+;
+
+class_label:
+STR
+;
+
+class:
+class_label CLOPEN class_closure CLCLOSE {CB[cbi].label = $1;};
+;
+
+class_closure:
+subclass_list
+| subclass_list set_list
+| set_list
+;
+
+subclass_list:
+subclass_list class           {CB[cbi].subclass_index++;};
+| class
+;
+
+set_list:
+set_list set                  {CB[cbi].set_index++;};
+| set
+;
+
+
+//set needs a label, vdat_id.
+set:
+set_map_data element_list     {insert_set();};
+| element_list
+;
+
+
+//TODO: Figure out what to do with hitbox and root. 
+set_map_data:
+ref_list                      {};
+| ref_list hitbox
+| ref_list hitbox root
+| hitbox root
+| hitbox
+| root
+;
+
+ref_list:
+RLS quads RLE
+;
+
+quads:
+quads quad                    {OB[obi].ref_index++;OB[obi].num_ref++;};
+| quad
+;
+
+quad:
+NUM NUM NUM NUM               {insert_ref($1, $2, $3, $4);};
+;
+
+hitbox:
+HB NUM
+;
+
+root:
+RT NUM NUM NUM
+;
+
+//parent_id is the set_index of the subclass_index.
+element_list:
+element_list element          {CB[cbi].set_stack[stack_index].num_ele++;};
+| element
+;
+
+element:
+set_label elem_label vdat     {insert_ele($2,$3); vbi++;};
+;
+
+set_label:
+  STR
+;
+
+elem_label:
+  STR
+;
+
+vdat:
+vdat model                    {VB[vbi].num_models++;};
+| model
+;
+
+model:
+model fdat
+| fdat
+;
+
+fdat:
+label SS FNAME                {insert_fdat($1, $2, $3);};
+;
+
+label:
+STR
+;
+
+ref:
+NUM
+;
+
+FNAME:
+STR
+;
+
+%%
+int
+main (argc, argv)
+{
+  lexer_init();
+  yyparse();
+  return 0;
+}
+
+void
+yyerror (char const *s)
+{ fprintf(stderr, "%s\n", s);
+}