mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 14:21:36 +00:00
Some parsing
This commit is contained in:
parent
1deeb8c9cf
commit
e6a270a7e0
5 changed files with 100 additions and 8 deletions
2
cpp.c
2
cpp.c
|
@ -6,5 +6,5 @@
|
|||
* which is what we parse for the preprocessor here.
|
||||
*/
|
||||
int cpp(struct lex_file *file) {
|
||||
/* TODO ... */
|
||||
/* no return */
|
||||
}
|
||||
|
|
BIN
gmqcc
BIN
gmqcc
Binary file not shown.
1
lex.c
1
lex.c
|
@ -349,6 +349,7 @@ int lex_debug(struct lex_file *file) {
|
|||
while ((token = lex_token(file)) != ERROR_LEX && file->length >= 0)
|
||||
if (token == LEX_IDENT)
|
||||
printf("%s ", file->lastok);
|
||||
fputc('\n', stdout);
|
||||
lex_reset(file);
|
||||
return 1;
|
||||
}
|
||||
|
|
11
main.c
11
main.c
|
@ -61,12 +61,11 @@ int main(int argc, char **argv) {
|
|||
if (!fp) {
|
||||
fclose(fp);
|
||||
return error(ERROR_COMPILER, "Source file: %s not found\n", ifile);
|
||||
} else {
|
||||
struct lex_file *lex = lex_open(fp);
|
||||
lex_debug(lex);
|
||||
parse (lex);
|
||||
lex_close(lex);
|
||||
}
|
||||
|
||||
struct lex_file *lex = lex_open(fp);
|
||||
lex_debug(lex);
|
||||
parse (lex);
|
||||
lex_close(lex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
94
parse.c
94
parse.c
|
@ -23,6 +23,19 @@
|
|||
#include <limits.h>
|
||||
#include "gmqcc.h"
|
||||
|
||||
|
||||
static const char *const parse_punct[] = {
|
||||
"&&", "||", "<=", ">=", "==", "!=", ";", ",", "!", "*",
|
||||
"/" , "(" , "-" , "+" , "=" , "[" , "]", "{", "}", "...",
|
||||
"." , "<" , ">" , "#" , "&" , "|" , "$", "@", ":", NULL
|
||||
/*
|
||||
* $,@,: are extensions:
|
||||
* $ is a shorter `self`, so instead of self.frags, $.frags
|
||||
* @ is a constructor
|
||||
* : is compiler builtin functions
|
||||
*/
|
||||
};
|
||||
|
||||
int parse(struct lex_file *file) {
|
||||
int token = 0;
|
||||
while ((token = lex_token(file)) != ERROR_LEX && \
|
||||
|
@ -42,10 +55,89 @@ int parse(struct lex_file *file) {
|
|||
|
||||
/* TODO: Preprocessor */
|
||||
case '#':
|
||||
token = cpp(file);
|
||||
token = lex_token(file);
|
||||
token = lex_token(file);
|
||||
token = lex_token(file);
|
||||
token = lex_token(file);
|
||||
token = lex_token(file);
|
||||
token = lex_token(file);
|
||||
break;
|
||||
|
||||
/* PUNCTUATION PARSING BEGINS */
|
||||
case '&': /* & */
|
||||
token = lex_token(file);
|
||||
if (token == '&') { /* && */
|
||||
token = lex_token(file);
|
||||
printf("--> LOGICAL AND\n");
|
||||
goto end;
|
||||
}
|
||||
printf("--> BITWISE AND\n");
|
||||
break;
|
||||
case '|': /* | */
|
||||
token = lex_token(file);
|
||||
if (token == '|') { /* || */
|
||||
token = lex_token(file);
|
||||
printf("--> LOGICAL OR\n");
|
||||
goto end;
|
||||
}
|
||||
printf("--> BITWISE OR\n");
|
||||
break;
|
||||
case '!':
|
||||
token = lex_token(file);
|
||||
if (token == '=') { /* != */
|
||||
token = lex_token(file);
|
||||
printf("--> LOGICAL NOT EQUAL\n");
|
||||
goto end;
|
||||
}
|
||||
printf("--> LOGICAL NOT\n");
|
||||
break;
|
||||
case '<': /* < */
|
||||
token = lex_token(file);
|
||||
if (token == '=') { /* <= */
|
||||
token = lex_token(file);
|
||||
printf("--> LESS THAN OR EQUALL\n");
|
||||
goto end;
|
||||
}
|
||||
printf("--> LESS THAN\n");
|
||||
break;
|
||||
case '>': /* > */
|
||||
token = lex_token(file);
|
||||
if (token == '=') { /* >= */
|
||||
token = lex_token(file);
|
||||
printf("--> GREATER THAN OR EQUAL\n");
|
||||
goto end;
|
||||
}
|
||||
printf("--> GREATER THAN\n");
|
||||
break;
|
||||
case '=':
|
||||
token = lex_token(file);
|
||||
if (token == '=') { /* == */
|
||||
token = lex_token(file);
|
||||
printf("--> COMPARISION \n");
|
||||
goto end;
|
||||
}
|
||||
printf("--> ASSIGNMENT\n");
|
||||
break;
|
||||
case ';':
|
||||
token = lex_token(file);
|
||||
printf("--> FINISHED STATMENT\n");
|
||||
break;
|
||||
case '-':
|
||||
token = lex_token(file);
|
||||
printf("--> SUBTRACTION EXPRESSION\n");
|
||||
break;
|
||||
case '+':
|
||||
token = lex_token(file);
|
||||
printf("--> ASSIGNMENT EXPRRESSION\n");
|
||||
break;
|
||||
}
|
||||
end:;
|
||||
}
|
||||
lex_reset(file);
|
||||
|
||||
// "&&", "||", "<=", ">=", "==", "!=", ";", ",", "!", "*",
|
||||
//"/" , "(" , "-" , "+" , "=" , "[" , "]", "{", "}", "...",
|
||||
//"." , "<" , ">" , "#" , "&" , "|" , "$", "@", ":", NULL
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue