start implimenting a parser
This commit is contained in:
@@ -1,17 +1,9 @@
|
||||
#include "lex.yy.h"
|
||||
#include "lexer.h"
|
||||
#include "../string/string.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void lexer(LexerState state) {
|
||||
yyscan_t scanner;
|
||||
|
||||
char *unquoted = unquote(state.content);
|
||||
if (unquoted) {
|
||||
printf("%s\n", unquoted);
|
||||
free(unquoted);
|
||||
}
|
||||
|
||||
yylex_init(&scanner);
|
||||
|
||||
yyset_extra(&state, scanner);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
TokenStruct* init_token() {
|
||||
TokenStruct *tokenStruct = malloc(sizeof(TokenStruct));\
|
||||
TokenStruct *tokenStruct = malloc(sizeof(TokenStruct));
|
||||
if (tokenStruct == NULL) {
|
||||
// handle malloc failure
|
||||
return NULL;
|
||||
|
||||
@@ -2,85 +2,86 @@
|
||||
#define TOKEN_H
|
||||
|
||||
typedef enum {
|
||||
TOKEN_STRING,
|
||||
TOKEN_NUMBER,
|
||||
TOKEN_FRACTION,
|
||||
TOKEN_IDENTIFIER,
|
||||
TOKEN_KEYWORD,
|
||||
TOKEN_NEW_LINE,
|
||||
TOKEN_INDENT,
|
||||
TOKEN_STRING,
|
||||
TOKEN_NUMBER,
|
||||
TOKEN_FRACTION,
|
||||
TOKEN_IDENTIFIER,
|
||||
TOKEN_KEYWORD,
|
||||
TOKEN_NEW_LINE,
|
||||
TOKEN_INDENT,
|
||||
|
||||
// Operators
|
||||
TOKEN_AND, // &&
|
||||
TOKEN_OR, // ||
|
||||
TOKEN_NOT_IN, // not in
|
||||
TOKEN_LE, // <=
|
||||
TOKEN_GE, // >=
|
||||
TOKEN_LT, // <
|
||||
TOKEN_GT, // >
|
||||
TOKEN_NE, // !=
|
||||
TOKEN_EQ, // ==
|
||||
TOKEN_ASSIGN,
|
||||
TOKEN_PLUS, // +
|
||||
TOKEN_MINUS, // -
|
||||
TOKEN_MODULO, // %
|
||||
TOKEN_STAR, // *
|
||||
TOKEN_FLOORDIV, // //
|
||||
TOKEN_SLASH, // /
|
||||
TOKEN_CARET, // ^
|
||||
// Operators
|
||||
TOKEN_AND, // &&
|
||||
TOKEN_OR, // ||
|
||||
TOKEN_NOT_IN, // not in
|
||||
TOKEN_LE, // <=
|
||||
TOKEN_GE, // >=
|
||||
TOKEN_LT, // <
|
||||
TOKEN_GT, // >
|
||||
TOKEN_NE, // !=
|
||||
TOKEN_EQ, // ==
|
||||
TOKEN_ASSIGN,
|
||||
TOKEN_PLUS, // +
|
||||
TOKEN_MINUS, // -
|
||||
TOKEN_MODULO, // %
|
||||
TOKEN_STAR, // *
|
||||
TOKEN_FLOORDIV, // //
|
||||
TOKEN_SLASH, // /
|
||||
TOKEN_CARET, // ^
|
||||
|
||||
// Keywords
|
||||
TOKEN_IF,
|
||||
TOKEN_ELSE,
|
||||
TOKEN_WHILE,
|
||||
TOKEN_FOREVER,
|
||||
TOKEN_FOR,
|
||||
TOKEN_BREAK,
|
||||
TOKEN_CONTINUE,
|
||||
TOKEN_RETURN,
|
||||
TOKEN_LET,
|
||||
TOKEN_IMPORT,
|
||||
TOKEN_FROM,
|
||||
TOKEN_DO,
|
||||
TOKEN_TRUE,
|
||||
TOKEN_FALSE,
|
||||
TOKEN_NULL,
|
||||
TOKEN_DELETE,
|
||||
TOKEN_NOT,
|
||||
TOKEN_IN,
|
||||
TOKEN_TRY,
|
||||
TOKEN_CATCH,
|
||||
// Keywords
|
||||
TOKEN_IF,
|
||||
TOKEN_ELSE,
|
||||
TOKEN_WHILE,
|
||||
TOKEN_FOREVER,
|
||||
TOKEN_FOR,
|
||||
TOKEN_BREAK,
|
||||
TOKEN_CONTINUE,
|
||||
TOKEN_RETURN,
|
||||
TOKEN_LET,
|
||||
TOKEN_IMPORT,
|
||||
TOKEN_FROM,
|
||||
TOKEN_DO,
|
||||
TOKEN_TRUE,
|
||||
TOKEN_FALSE,
|
||||
TOKEN_NULL,
|
||||
TOKEN_DELETE,
|
||||
TOKEN_NOT,
|
||||
TOKEN_IN,
|
||||
TOKEN_TRY,
|
||||
TOKEN_CATCH,
|
||||
|
||||
// parentheses, brackets, and braces
|
||||
TOKEN_LPAREN, // (
|
||||
TOKEN_RPAREN, // )
|
||||
TOKEN_LBRACKET, // [
|
||||
TOKEN_RBRACKET, // ]
|
||||
TOKEN_LBRACE, // {
|
||||
TOKEN_RBRACE, // }
|
||||
// parentheses, brackets, and braces
|
||||
TOKEN_LPAREN, // (
|
||||
TOKEN_RPAREN, // )
|
||||
TOKEN_LBRACKET, // [
|
||||
TOKEN_RBRACKET, // ]
|
||||
TOKEN_LBRACE, // {
|
||||
TOKEN_RBRACE, // }
|
||||
|
||||
TOKEN_DOT,
|
||||
TOKEN_COMMA,
|
||||
TOKEN_COLON,
|
||||
TOKEN_DOT,
|
||||
TOKEN_COMMA,
|
||||
TOKEN_COLON,
|
||||
} TokenType;
|
||||
|
||||
typedef struct {
|
||||
TokenType type;
|
||||
int line;
|
||||
int column;
|
||||
char* value;
|
||||
TokenType type;
|
||||
int line;
|
||||
int column;
|
||||
char *value;
|
||||
} Token;
|
||||
|
||||
typedef struct {
|
||||
int count;
|
||||
int capacity;
|
||||
Token* tokens;
|
||||
int count;
|
||||
int capacity;
|
||||
Token *tokens;
|
||||
} TokenStruct;
|
||||
|
||||
TokenStruct* init_token();
|
||||
TokenStruct *init_token();
|
||||
|
||||
void add_token(TokenStruct* token,TokenType type, const char* value, int line, int column);
|
||||
void add_token(TokenStruct *token, TokenType type, const char *value, int line,
|
||||
int column);
|
||||
|
||||
void free_tokens(TokenStruct* token);
|
||||
void free_tokens(TokenStruct *token);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user