#include <limits.h>
#include "gmqcc.h"
-//typedef int foo;
-
int usage(const char *name) {
printf("Usage: %s -f infile -o outfile\n", name);
return 0;
}
-
int main(int argc, char **argv) {
const char *ofile = NULL;
const char *ifile = NULL;
printf("ifile: %s\n", ifile);
printf("ofile: %s\n", ofile);
+
/* Open file */
FILE *fp = fopen(ifile, "r");
-
- /* run the preprocessor */
if (!fp) {
fclose(fp);
return error(ERROR_COMPILER, "Source file: %s not found\n", ifile);
#define PARSE_TYPE_BAND 35
#define PARSE_TYPE_BOR 36
#define PARSE_TYPE_DONE 37
+#define PARSE_TYPE_IDENT 38
/*
* Adds a parse type to the parse tree, this is where all the hard
case PARSE_TYPE_RETURN: STORE("STATEMENT: RETURN\n");
case PARSE_TYPE_DONE: STORE("STATEMENT: DONE\n");
-
+ case PARSE_TYPE_VOID: STORE("DECLTYPE: VOID\n");
+ case PARSE_TYPE_STRING: STORE("DECLTYPE: STRING\n");
case PARSE_TYPE_ELIP: STORE("DECLTYPE: VALIST\n");
case PARSE_TYPE_ENTITY: STORE("DECLTYPE: ENTITY\n");
case PARSE_TYPE_FLOAT: STORE("DECLTYPE: FLOAT\n");
+ case PARSE_TYPE_VECTOR: STORE("DECLTYPE: VECTOR\n");
case PARSE_TYPE_GT: STORE("TEST: GREATER THAN\n");
case PARSE_TYPE_LT: STORE("TEST: LESS THAN\n");
case PARSE_TYPE_FOR: STORE("LOOP: FOR\n");
case PARSE_TYPE_DO: STORE("LOOP: DO\n");
-
+ case PARSE_TYPE_IDENT: STORE("IDENT: ???\n");
}
tree = tree->next;
}
switch (token) {
case TOKEN_IF:
token = lex_token(file);
- while ((token == ' ' || token == '\n') && file->length >= 0)
- token = lex_token(file);
+ //while ((token == ' ' || token == '\n') && file->length >= 0)
+ // token = lex_token(file);
- if (token != '(')
- error(ERROR_PARSE, "Expected `(` after if\n", "");
+ //if (token != '(')
+ // error(ERROR_PARSE, "Expected `(` after if\n", "");
PARSE_TREE_ADD(PARSE_TYPE_IF);
break;
case TOKEN_ELSE:
token = lex_token(file);
- while ((token == ' ' || token == '\n') && file->length >= 0)
- token = lex_token(file);
+ //while ((token == ' ' || token == '\n') && file->length >= 0)
+ // token = lex_token(file);
PARSE_TREE_ADD(PARSE_TYPE_ELSE);
break;
case TOKEN_FOR:
token = lex_token(file);
- while ((token == ' ' || token == '\n') && file->length >= 0)
- token = lex_token(file);
+ //while ((token == ' ' || token == '\n') && file->length >= 0)
+ // token = lex_token(file);
PARSE_TREE_ADD(PARSE_TYPE_FOR);
break;
-
- case LEX_IDENT:
- token = lex_token(file);
- break;
/*
* This is a quick and easy way to do typedefs at parse time
token = lex_token(file);
break;
+ case '(':
+ token = lex_token(file);
+ PARSE_TREE_ADD(PARSE_TYPE_LPARTH);
+ break;
+ case ')':
+ token = lex_token(file);
+ PARSE_TREE_ADD(PARSE_TYPE_RPARTH);
+ break;
+
case '&': /* & */
token = lex_token(file);
if (token == '&') { /* && */
token = lex_token(file);
PARSE_TREE_ADD(PARSE_TYPE_ADD);
break;
- case '(':
- token = lex_token(file);
- PARSE_TREE_ADD(PARSE_TYPE_LPARTH);
- break;
- case ')':
- token = lex_token(file);
- PARSE_TREE_ADD(PARSE_TYPE_RPARTH);
- break;
case '{':
token = lex_token(file);
PARSE_TREE_ADD(PARSE_TYPE_LBS);
token = lex_token(file);
PARSE_TREE_ADD(PARSE_TYPE_RBS);
break;
+
+ /*
+ * TODO: Fix lexer to spit out ( ) as tokens, it seems the
+ * using '(' or ')' in parser doesn't work properly unless
+ * there are spaces before them to allow the lexer to properly
+ * seperate identifiers. -- otherwise it eats all of it.
+ */
+ case LEX_IDENT:
+ token = lex_token(file);
+ PARSE_TREE_ADD(PARSE_TYPE_IDENT);
+ break;
}
}
parse_debug(parseroot);