-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Dayof/dev
Initial parser version
- Loading branch information
Showing
25 changed files
with
2,814 additions
and
407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
cppython | ||
cppython | ||
*.tab.* | ||
*.yy.* |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FILES = parser.c lexer.c ast.c sym_tab.c main.c | ||
CFLAGS = -g -Wall -pedantic -x c | ||
CC = gcc | ||
|
||
cppython: $(FILES) ast.h sym_tab.h | ||
$(CC) $(CFLAGS) $(FILES) -o cppython -lfl | ||
|
||
lexer.c: cppython.lex | ||
flex cppython.lex | ||
|
||
parser.c: cppython.y | ||
bison -d -v cppython.y | ||
|
||
clean: | ||
rm -f *.o *~ lexer.c lexer.h parser.c parser.h parser.output cppython |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "ast.h" | ||
|
||
ast_node* create_bin_expr(char *operator, ast_node* left, ast_node* right) { | ||
printf("\nCreating binary expression node: %d %s %d\n", | ||
left->op.integer_expr, operator, right->op.integer_expr); | ||
ast_node* expr = (ast_node*) malloc(sizeof(ast_node)); | ||
expr->op.binary_expr.operator = operator; | ||
expr->op.binary_expr.left = left; | ||
expr->op.binary_expr.right = right; | ||
return expr; | ||
} | ||
|
||
ast_node* create_int_expr(int value) { | ||
printf("\n\nCreating integer expression node: %d\n", value); | ||
ast_node* expr = (ast_node*) malloc(sizeof(ast_node)); | ||
expr->op.integer_expr = value; | ||
return expr; | ||
} | ||
|
||
void create_ast(ast_node* expression) { | ||
ast* ast_obj = (ast*) malloc(sizeof(ast)); | ||
ast_obj->head = expression; | ||
ast_obj->next = NULL; | ||
printf("\nAST created.\n"); | ||
} | ||
|
||
ast_node* show(ast_node* expression) { | ||
printf("\nAssign expression.\n"); | ||
return expression; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef __AST_H__ | ||
#define __AST_H__ | ||
|
||
int line, column; | ||
|
||
typedef struct exp { | ||
union { | ||
int integer_expr; | ||
char *string_expr; | ||
char *variable_expr; | ||
struct { | ||
char *operator; | ||
struct exp* left; | ||
struct exp* right; | ||
} binary_expr; | ||
} op; | ||
} ast_node; | ||
|
||
typedef struct expr_list { | ||
ast_node* head; | ||
struct expr_list* next; | ||
} ast; | ||
|
||
void create_ast(ast_node* expression); | ||
ast_node* show(ast_node* expression); | ||
ast_node* create_int_expr(int value); | ||
ast_node* create_bin_expr(char *operator, ast_node* left, ast_node* right); | ||
|
||
void handle_token(int token); | ||
|
||
#endif // __AST_H__ |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.