+++ /dev/null
-/* Asset Package Compiler */
-%{
- #include <stdio.h>
- #include <string.h>
- #include <dirent.h>
- #include "sprite.h"
- #include "symbol.h"
- #include <png.h>
-
-
- extern void yyerror();
- extern int linit();
- extern int yylex();
-
-
- int handle_fname(char *);
- int eval_png_file(char*);
- int read_png_file(char*);
-
-%}
-%define parse.error verbose
-%union{
- char* str;
- }
-
-/* %token <str> EXT */
-/* %token <str> FW */
-/* %token <str> SPR */
-/* %token CC */
-
-/* /\* Rules *\/ */
-/* %% */
-/* SS: SPR '/' MD '.' EXT */
-/* MD: CC '_' FW */
-/* | FW */
-/* | CC */
-
-
-%token <str> FDAT
-
-/* Rules */
-%%
-FLIST : FLIST FNAME {printf("reducing to flist\n");} /* Now output to asspack.o */ | FNAME
-FNAME : FDAT {printf("handle_fname(%s)\n", $1);handle_fname(yylval.str);printf("handled fname\n");}
-
-%%
-int
-main(int argc, char** argv)
-{
- /* Parse cmd line arguments */
-
- linit();
- yyparse(); /* runs handle_fname for each filename */
-
-
- return 0;
-}
-void
-yyerror (char const *s)
-{
- fprintf(stderr, "%s\n", s);
-}
-
-
-
-/* Analyze file_name for information on sprite sheet,
- store sprite sheet and label into sprite then
- push sprite onto sprites[]*/
-int
-handle_fname(char* file_name)
-{
- /* Parse the file_name for data */
-
-
- /* Get the specs of the PNG file */
- if(eval_png_file(file_name))
- {
- printf("Failed in eval_png_file\n");
- return 1;
- }
-
- /* Insert sprite sheet from PNG into sprite_sheets */
- push_sprite();
-
-
-
-
- /* Store dir/filename in label as well as any other data that fits */
-}
-int eval_png_file(char* file_name)
-{
- /* Evaluate file_name for metadata */
-
- /* Extracts header info from png_file */
- read_png_file(file_name);
-
- /* Create the symbol and put it in symbol_table[]*/
-
- return 0;
-}
-
-
-
-/* variables for libPNG */
-int png_width,png_height;
-png_byte bit_depth;
-png_byte color_type;
-png_structp png_ptr;
-png_infop info_ptr;
-
-int
-read_png_file( char* file_name)
-{
- /* Setup PNG file */
- char header[8];
- int is_png = 0;
- char* dir = "pngfiles";
-
- /* TODO: Change this fopen to a real var! */
- FILE *fp = fopen("pngfiles/env_street_road03_0.png","rb");
-
- if(!fp)
- { printf("Could not read file %s in handle_fname()", file_name);
- return 1;
- }
-
- fread(header, 1, 8, fp);
-
- is_png = !png_sig_cmp(header, 0, 8);
- if(!is_png)
- return 1;
-
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
-
- if (!png_ptr)
- { printf("Failed to allocate png_ptr\n");
- return 1;
- }
- info_ptr = png_create_info_struct(png_ptr);
-
- if (!info_ptr)
- { printf("Failed to create info_ptr\n");
- png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL);
- return 1;
- }
-
- png_infop end_info = png_create_info_struct(png_ptr);
- if (!end_info)
- { printf("Failed to create end_info \n");
- png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL);
- return 1;
- }
-
- if(setjmp(png_jmpbuf(png_ptr)))
- { printf("Failed in init_io\n");
- png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL);
- fclose(fp);
- return 1;
- }
- png_init_io(png_ptr, fp);
- png_set_sig_bytes(png_ptr, 8);
-
- png_read_info(png_ptr, info_ptr);
-
- png_width = png_get_image_width(png_ptr, info_ptr);
- png_height = png_get_image_height(png_ptr, info_ptr);
- color_type = png_get_color_type(png_ptr, info_ptr);
- bit_depth = png_get_bit_depth(png_ptr, info_ptr);
-
- png_read_update_info(png_ptr, info_ptr);
-
- printf("successfully read png file %s\n", file_name);
-
- return 0;
-
-}
+++ /dev/null
-/* Asset Package Compiler */
-%{
- #include <stdio.h>
- #include <string.h>
- #include <dirent.h>
- #include "sprite.h"
- #include "symbol.h"
- #include <png.h>
-
-
- extern void yyerror();
- extern int rinit();
- extern int yylex();
- #define DIR_SIZE 128/* size when all files have been concatenated together */
-
- char dir_files[DIR_SIZE];
- FILE* yyin;
-
- int populate_yyin(FILE*);
- int handle_vdat(char *);
- int eval_png_file(char*);
- int read_png_file(char*);
-
-%}
-%define parse.error verbose
-%union{
- char* str;
- }
-
-/* %token <str> EXT */
-/* %token <str> FW */
-/* %token <str> SPR */
-/* %token CC */
-
-/* /\* Rules *\/ */
-/* %% */
-/* SS: SPR '/' MD '.' EXT */
-/* MD: CC '_' FW */
-/* | FW */
-/* | CC */
-
-
-%token <str> VDAT
-%token ODAT
-%token ADAT
-
-/* Rules */
-%%
-FLIST : FNAME /* Now output to VDAT.o */
-FNAME : VDAT {printf("handle_vdat(%s)\n", $1);handle_vdat(yylval.str);printf("handled vdat\n");}
- | ADAT
- | ODAT
-
-%%
-int
-main(int argc, char** argv)
-{
- /* Take arguments */
-
- /* Concatenate all files into buf, they are null-terminated
- by default */
- FILE *fp;
-
- fp = fopen("all_files", "w+");
-
- if(!populate_yyin(fp))
- printf("error processing the directory");
-
- yyin = fp;
- rinit();
- yyparse(); /* runs handle_vdat after token is scanned */
-
-
-
- return 0;
-}
-void
-yyerror (char const *s)
-{
- fprintf(stderr, "%s\n", s);
-}
-
-/* TODO: READ INTO SINGLE BUFFER, NOT A FILE */
-int
-populate_yyin(FILE* fp)
-{
- int files_pos = 0;
- int file_len = 0;
- struct dirent* ep;
-
- DIR* dp = opendir("pngfiles");
- /* Concatenate all file names, seperated by '\0'
- into files[] */
- if(dp != NULL)
- {
- while(ep = readdir(dp))
- { file_len = strlen(ep->d_name);
- fwrite(ep->d_name, 1, file_len, fp);
- printf("writing %s to file\n", ep->d_name);
- }
- fseek(fp, SEEK_SET, 0);
- return 0;
- }
- else
- {return 1;
- }
- closedir(dp);
-}
-
-
-
-
-/* Analyze file_name for information on sprite sheet,
- store sprite sheet and label into sprite then
- push sprite onto sprites[]*/
-int
-handle_vdat(char* file_name)
-{
- /* Parse the file_name for data */
-
-
- /* Get the specs of the PNG file */
- if(!eval_png_file(file_name))
- {
- printf("Failed in read_png_file\n");
- return 1;
- }
-
- /* Insert sprite sheet from PNG into sprite_sheets */
- push_sprite();
-
-
-
-
- /* Store dir/filename in label as well as any other data that fits */
-}
-int eval_png_file(char* file_name)
-{
- /* Evaluate file_name for metadata */
-
- /* Extracts header info from png_file */
- read_png_file(file_name);
-
-
- /* Create the symbol and put it in symbol_table[]*/
-
- return 0;
-}
-
-
-
-/* variables for libPNG */
-int png_width,png_height;
-png_byte bit_depth;
-png_byte color_type;
-png_structp png_ptr;
-png_infop info_ptr;
-
-int
-read_png_file( char* file_name)
-{
- /* Setup PNG file */
- char header[8];
- int is_png = 0;
- char* dir = "pngfiles";
-
- /* TODO: Change this fopen to a real var! */
- FILE *fp = fopen("pngfiles/env_street_road03_0.png","rb");
-
- if(!fp)
- { printf("Could not read file %s in handle_vdat()", file_name);
- return 1;
- }
-
- fread(header, 1, 8, fp);
-
- is_png = !png_sig_cmp(header, 0, 8);
- if(!is_png)
- return 1;
-
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
-
- if (!png_ptr)
- { printf("Failed to allocate png_ptr\n");
- return 1;
- }
- info_ptr = png_create_info_struct(png_ptr);
-
- if (!info_ptr)
- { printf("Failed to create info_ptr\n");
- png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL);
- return 1;
- }
-
- png_infop end_info = png_create_info_struct(png_ptr);
- if (!end_info)
- { printf("Failed to create end_info \n");
- png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL);
- return 1;
- }
-
- if(setjmp(png_jmpbuf(png_ptr)))
- { printf("Failed in init_io\n");
- png_destroy_read_struct(&png_ptr,(png_infopp)NULL, (png_infopp)NULL);
- fclose(fp);
- return 1;
- }
- png_init_io(png_ptr, fp);
- png_set_sig_bytes(png_ptr, 8);
-
- png_read_info(png_ptr, info_ptr);
-
- png_width = png_get_image_width(png_ptr, info_ptr);
- png_height = png_get_image_height(png_ptr, info_ptr);
- color_type = png_get_color_type(png_ptr, info_ptr);
- bit_depth = png_get_bit_depth(png_ptr, info_ptr);
-
- png_read_update_info(png_ptr, info_ptr);
-
-
- return 0;
-
-}
+++ /dev/null
-#include <stdio.h>
-#include <string.h>
-#include <dirent.h>
-#include <errno.h>
-#include <unistd.h>
-#include "fileparser.tab.h"
-
-int linit(void);
-int tok_dir(DIR*, char *);
-
-#define MAX_TOK_LEN 256
-#define MAX_DIR_DEP 8
-#define MAX_PATH_LEN 64
-static DIR* dp_stack[MAX_DIR_DEP];
-static DIR** dsp;
-static char path[MAX_PATH_LEN];
-
-/* Setup stack and first directory to read from */
-int
-linit()
-{
- DIR *dp;
- char cwd[MAX_TOK_LEN];
-
- dsp = dp_stack;
-
- getcwd(cwd, MAX_TOK_LEN);
-
- printf("|------cwd is %s------|\n", cwd);
- if(!(dp = opendir(cwd)))
- printf("opendir(cwd) failed in linit()\n");
-
- *dsp = dp;
- /* Dont use ADD_PATH because it concats a "/", which is already
- present with cwd */
- strcat(path, cwd);
- printf("dp_stack is %x, dsp is %x size is %d\n",*dp_stack, *dsp, sizeof dp);
-
- return 0;
-}
-
-int
-yylex()
-{
- int tok_t = 0;
- char buf[MAX_TOK_LEN];
- char* file_name;
-
- /* Each call to tok_dir will return a file_name to be
- tokenized. tok_dir calls readdir(), which saves the
- position in the directory after returning a file_name
- for the next call. */
- printf("|------in yylex(), calling tok_dir------|\n");
- if((tok_t = tok_dir(*dsp, buf)) == -1)
- printf("tok_dir returned -1, something is broken\n");
- yylval.str = strdup(buf);
-
- printf("|------in yylex(), returning tok_t = %d | err = %s------|\n", tok_t, strerror(errno));
-
- return tok_t;
-}
-
-#define DSP_PUSH(_val) *++dsp = (_val)
-
-int
-tok_dir(DIR* dp, char buf[])
-{
- struct dirent* de; /* directory entry */
- static DIR *tmp_dp;
- char *tmp_path;
- int path_len;
-
-
-tok_start:
- if((*dsp == NULL) || (de = readdir(*dsp)) == NULL)
- {
- if(errno)
- { printf("Error:%s in tok_dir\n", strerror(errno));
- return errno;
- }
- if( (dsp - dp_stack) >= 0)
- {
- printf("Current directory is null, pop one off ");
-#define DSP_POP() *dsp--
-
- dp = DSP_POP();
-
- /* Remove directory that was popped from path */
-#define SUB_PATH() tmp_path = strrchr(path, '/'); \
- path_len = strlen(tmp_path); \
- memset(tmp_path, 0, path_len)
-
- SUB_PATH();
-
- goto tok_start;
- }
- return 0; /* Done */
- }
-
- else if(de->d_type == DT_REG)
- { printf("|------dir_ent is a file, "\
- "setting yylval to %s------|\n", de->d_name);
- memmove(buf, de->d_name, MAX_TOK_LEN);
- return FDAT;
- }
- else if (de->d_type == DT_DIR )
- { if ((dsp - dp_stack) >= MAX_DIR_DEP) /* We've opened to many directories */
- {
- printf("Too many directories!\n");
- return 1;
- }
- if(strcmp(de->d_name,".") == 0 || strcmp(de->d_name,"..") == 0)
- {
- printf("directory is %s \n", de->d_name);
- goto tok_start;
- }
-
- printf("|------ dir_ent is directory %s, "\
- "cwd = %s, path = %s ------|\n", de->d_name, get_current_dir_name(), path);
-
-
- /* Add directory name to path */
-#define ADD_PATH(_name) strcat(path, "/"); \
- strcat(path, _name)
-
- ADD_PATH(de->d_name);
-
- tmp_dp = opendir(path);
- if(tmp_dp == 0)
- { printf("opening the directory failed,"\
- "errno = %s\n", strerror(errno));
- return -1;
- }
-
- DSP_PUSH(tmp_dp);
-
- goto tok_start;
-
- }
- else
- {
- printf("A file that is not a diretory or a regular file is unable to be tokenized: %s\n", de->d_name);
- return -1;
- }
-
-
-
-}
+++ /dev/null
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <dirent.h>
-#include "fileparser.tab.h"
-extern FILE* yyin;
-
-int rinit(void);
-
-#define MAX_TOK_LEN 32
-static char buf[MAX_TOK_LEN];
-static char *p, *pe; /* scanner points to p, pe points to end of buf */
-
-%%{
- machine scanner;
-
- main := |*
-
- 'env_street_road03_0.png' => {ret=VDAT;memmove(rbuf, ts, (te-ts)); yylval.str=strdup(rbuf); printf("Lexer matched with %s\n",yylval.str);fbreak; };
- '.' => {printf("matched with .\n");fbreak;};
- '..' => {printf("matched with ..\n");fbreak;};
-
- *|;
-
-}%%
-
-%%write data;
-
-int
-rinit()
-{ p = buf;
- pe = p + fread(buf, 1, MAX_TOK_LEN, yyin);
- printf("buf in rinit is %s\n", buf);
- return 0;
-}
-
-int
-yylex()
-{ int ret;
- static char *eof;
- char rbuf[MAX_TOK_LEN];
- int cs, act;
- char *ts, *te;
-
- /*init cs, ts, te, act */
- %%write init;
- ret = 0;
-
- %%write exec ;
- if (te == 0)
- {
- if(eof == pe ){
- return 0;
- }
- printf("This is a lexical error, tokens can not be larger than max token length\n buf is = %s | ts = %s | te = %s\n", buf,ts,te);
- return 0;
- }
-
-
- /* We matched a token, remove it from buf and set
- buf to have rest of unmatched buf (buf - matchedtoken).*/
- if (!feof(yyin))
- { int r = pe-te; /* remainder length */
- memmove(buf, te, r); /* also the max more buf can hold */
- p = buf;
- pe = p + r + fread(buf+r,1,MAX_TOK_LEN -r,yyin);
- }
- if((p+1) == pe && feof(yyin))
- eof = pe;
-
- return ret;
-}
-
-/* 'sprites' => {};
- /0x[xdigit]{8}/ => {};
- '_' => {};
- /[digit]{2}/ => {}; /* CC */
-
+++ /dev/null
-#!/bin/bash
-bison -t -d fileparser.y
-ragel filescanner.rl
-gcc sprite.c fileparser.tab.c filescanner.c -o ragson -lm -lpng
+++ /dev/null
-int
-push_sprite(void)
-{
- return 0;
-}
+++ /dev/null
-#ifndef _SPRITEH_
-#define _SPRITEH_
-
-/* Sprite Sheet Header */
-/* Sprite Sheets can have 1-8 frames for each direction they are facing. */
-struct sprite_sheet
-{
- int num_frames; /* Defaults to 0 */
- int frame_width; /*Found frome file name */
- int sprite_start; /* points to where first frame points */
-};
-
-
-extern struct sprite_sheet sprite_sheets[16]; /* stack of sprites */
-extern struct sprite_sheet* ssp; /* sprite sheets pointer */
-
-
-int push_sprite();
-
-#endif
+++ /dev/null
-/* Header file for Symbols */
-#ifndef _SYMBOLH_
-#define _SYMBOLH_
-#include "sprite.h"
-
-struct symbol
-{
- struct sprite_sheet ss;
- int ss_id;
- char label[255];
-};
-
-struct symbol symbol_table[16];
-#endif
#include "sprite.h"
#include "symbol.h"
#include <png.h>
-
+ #include "ir.h"
extern int lexer_init();
extern int lexer();
%define parse.error verbose
%define lr.type ielr
%define api.value.type union
-%token <int> NUM
%token <char*> WORD
//operators
-%token PROTOCLASS //+
-%token SIBS //|
-%token FNAME //!
- //nonterminal types
-%type <int> fd
-%type <int*> fdlist
-
-/* %token <str> EXT */
-/* %token <str> FW */
-/* %token <str> SPR */
-/* %token CC */
-/* /\* Rules *\/ */
-/* %% */
-/* SS: SPR '/' MD '.' EXT */
-/* MD: CC '_' FW */
-/* | FW */
-/* | CC */
+%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?
+;
-object_defs:
- %empty
-| arch_id object_defs
+class_list:
+class_list class {cbi++;};
+| class
;
-arch_id:
- archetype
-| arch_id_ref
+class_label:
+STR
;
-arch_id_list:
- arch_id
-| arch_id arch_id_list
+class:
+class_label CLOPEN class_closure CLCLOSE {CB[cbi].label = $1;};
;
-archetype:
- PROTOCLASS label arch_id_list SIBS arch_id_list
-| PROTOCLASS label arch_id_list
-| label arch_id_ref vdat
+class_closure:
+subclass_list
+| subclass_list set_list
+| set_list
;
-label:
- WORD
+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);};
;
-arch_id_ref:
- NUM
+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:
- spritesheet
+vdat model {VB[vbi].num_models++;};
+| model
;
-spritesheet:
- fdlist
+model:
+model fdat
+| fdat
;
-fdlist:
- fd
-| fd fdlist
+fdat:
+label SS FNAME {insert_fdat($1, $2, $3);};
;
-fd:
- FNAME WORD
-| NUM;
-%%
+label:
+STR
+;
+ref:
+NUM
+;
+
+FNAME:
+STR
+;
+
+%%
int
-main(int argc, char** argv)
-{ /* Parse cmd line arguments */
+main (argc, argv)
+{
lexer_init();
- yyparse(); /* runs handle_fname for each filename */
+ yyparse();
return 0;
}