Commit 6a05c158 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Added COMMA to grammar rule.

parent 4303e97c
...@@ -9,8 +9,10 @@ ...@@ -9,8 +9,10 @@
#define TYPE_CMD 3 #define TYPE_CMD 3
// Argument types // Argument types
#define ARG_REG 0 #define ARG_INT 0
#define ARG_OFFSET 1 #define ARG_REG 1
#define ARG_LABEL 2
#define ARG_OFFSET 3
typedef struct line { typedef struct line {
int type; int type;
...@@ -40,21 +42,19 @@ line *first_line, *last_line; ...@@ -40,21 +42,19 @@ line *first_line, *last_line;
%token <sval> COMMENT DIRECTIVE WORD LABEL OFFSET CMD %token <sval> COMMENT DIRECTIVE WORD LABEL OFFSET CMD
%start symbol %start symbol
%type <sval> reg3 %type <sval> command
%% %%
reg3: "add" | "sub"
command: command:
reg3 WORD WORD WORD { "add" WORD COMMA WORD COMMA WORD {
char *argv[] = (char **)malloc(3 * sizeof(char *)); char **argv = (char **)malloc(3 * sizeof(char *));
char *argt[] = (int *)malloc(3 * sizeof(int)); int *argt = (int *)malloc(3 * sizeof(int));
argv[0] = $2; argv[0] = $2;
argv[1] = $3; argv[1] = $4;
argv[2] = $4; argv[2] = $6;
argt[2] = argt[1] = argt[0] = ARG_REG; argt[2] = argt[1] = argt[0] = ARG_REG;
add_line(TYPE_CMD, (char *)$1, 3, argv, argt); add_line(TYPE_CMD, "add", 3, argv, argt);
} }
; ;
...@@ -107,6 +107,7 @@ void yyerror(char *s) ...@@ -107,6 +107,7 @@ void yyerror(char *s)
void add_line(int type, const char *name, int argc, char **argv, int *argt) { void add_line(int type, const char *name, int argc, char **argv, int *argt) {
line *l = (line*)malloc(sizeof(line)); line *l = (line*)malloc(sizeof(line));
printf("\nName: %s\n\n", name);
l->argc = argc; l->argc = argc;
l->argv = argv; l->argv = argv;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment