Some new types, and lexer changes

This commit is contained in:
Dale Weiler 2012-04-09 07:45:20 -04:00
parent fe6e142f85
commit c436c3a6c6
4 changed files with 31 additions and 14 deletions

BIN
gmqcc

Binary file not shown.

33
gmqcc.h
View file

@ -20,8 +20,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
#ifndef DPQCC_HDR #ifndef GMQCC_HDR
#define DPQCC_HDR #define GMQCC_HDR
#include <stdio.h> #include <stdio.h>
/* The types supported by the language */ /* The types supported by the language */
@ -155,23 +155,30 @@ struct lex_file {
#define TOKEN_CONTINUE 5 #define TOKEN_CONTINUE 5
#define TOKEN_RETURN 6 #define TOKEN_RETURN 6
#define TOKEN_GOTO 7 #define TOKEN_GOTO 7
#define TOKEN_FOR 8 #define TOKEN_FOR 8 // extension
#define TOKEN_INT 9 // extension
#define TOKEN_BOOL 10 // extension
#define TOKEN_VOID 11
#define TOKEN_STRING 12
#define TOKEN_FLOAT 13
#define TOKEN_VECTOR 14
#define TOKEN_ENTITY 15
/* /*
* Lexer state constants, these are numbers for where exactly in * Lexer state constants, these are numbers for where exactly in
* the lexing the lexer is at. Or where it decided to stop if a lexer * the lexing the lexer is at. Or where it decided to stop if a lexer
* error occurs. * error occurs.
*/ */
#define LEX_COMMENT 128 /* higher than ascii */ #define LEX_COMMENT 128 /* higher than ascii */
#define LEX_CHRLIT 129 #define LEX_CHRLIT 129
#define LEX_STRLIT 130 #define LEX_STRLIT 130
#define LEX_IDENT 131 #define LEX_IDENT 131
#define LEX_DO 132 #define LEX_DO 132
#define LEX_ELSE 133 #define LEX_ELSE 133
#define LEX_IF 134 #define LEX_IF 134
#define LEX_WHILE 135 #define LEX_WHILE 135
#define LEX_INCLUDE 136 #define LEX_INCLUDE 136
#define LEX_DEFINE 137 #define LEX_DEFINE 137
int lex_token(struct lex_file *); int lex_token(struct lex_file *);
void lex_reset(struct lex_file *); void lex_reset(struct lex_file *);

11
lex.c
View file

@ -30,7 +30,16 @@
static const char *const lex_keywords[] = { static const char *const lex_keywords[] = {
"do", "else", "if", "while", "do", "else", "if", "while",
"break", "continue", "return", "goto", "break", "continue", "return", "goto",
"for" "for",
/* types */
"int",
"bool",
"void",
"string",
"float",
"vector",
"entity"
}; };
struct lex_file *lex_open(const char *name) { struct lex_file *lex_open(const char *name) {

View file

@ -22,6 +22,7 @@
*/ */
#include <limits.h> #include <limits.h>
#include "gmqcc.h" #include "gmqcc.h"
int parse(struct lex_file *file) { int parse(struct lex_file *file) {
int token = 0; int token = 0;
while ((token = lex_token(file)) != ERROR_LEX && file->length >= 0) { while ((token = lex_token(file)) != ERROR_LEX && file->length >= 0) {