Commit c14e76cf authored by Jayke Meijer's avatar Jayke Meijer

worked on Lex and Yacc.

parent 1573e930
...@@ -3,7 +3,7 @@ LEX=lex ...@@ -3,7 +3,7 @@ LEX=lex
YACC=yacc YACC=yacc
CFLAGS=-ll CFLAGS=-ll
parser: lex yacc parser: yacc lex
$(CC) -c lex.yy.c y.tab.c $(CC) -c lex.yy.c y.tab.c
$(CC) -o $@ lex.yy.o y.tab.o $(CFLAGS) $(CC) -o $@ lex.yy.o y.tab.o $(CFLAGS)
......
...@@ -2,15 +2,17 @@ ...@@ -2,15 +2,17 @@
#include <stdio.h> #include <stdio.h>
#include "y.tab.h" #include "y.tab.h"
%} %}
arg \$[a-zA-Z0-9\.]+
%% %%
[a-z0-9$._]+: { yylval.sval = yytext; return LABEL; } /* Label */ #[^\n]* { yylval.sval = yytext; return COMMENT; } /* Comment */
\$[a-z0-9._] { yylval.sval = yytext; return ARG; } /* Arg of instr */ [a-zA-Z0-9$\.]+: { yylval.sval = yytext; return LABEL; } /* Label */
^[a-z.]+ { yylval.sval = yytext; return INSTR; } /* Instruction */ {arg} { yylval.sval = yytext; return ARG; } /* Arg of instr */
[0-9]+(\({arg}\))? { yylval.sval = yytext; return ARG; } /* Arg of instr */
\.[^\n]* { yylval.sval = yytext; return DIRECTIVE; } /* Assembly */ \.[^\n]* { yylval.sval = yytext; return DIRECTIVE; } /* Assembly */
[a-z\.]+ { yylval.sval = yytext; return INSTR; } /* Instruction */
[,] { return COMMA; } /* Comma */ [,] { return COMMA; } /* Comma */
#[^\n]* { yylval.sval = yytext; return COMMENT; } /* Comment */
[\n] { return NL; } /* New line */ [\n] { return NL; } /* New line */
[\s\t]+ { ; } /* Ignore whitespace */ [ \t]+ { ; } /* Ignore whitespace */
...@@ -17,8 +17,10 @@ void yyerror(char*); ...@@ -17,8 +17,10 @@ void yyerror(char*);
%token <sval> COMMENT %token <sval> COMMENT
%% %%
symb: symb:
LABEL {printf("Found a label: %s\n", $1);} symb symb
| LABEL {printf("Found a label: %s\n", $1);}
| ARG {printf("Found an argument: %s\n", $1);} | ARG {printf("Found an argument: %s\n", $1);}
| INSTR {printf("Found an instruction: %s\n", $1);} | INSTR {printf("Found an instruction: %s\n", $1);}
| DIRECTIVE {printf("Found a directive: %s\n", $1);} | DIRECTIVE {printf("Found a directive: %s\n", $1);}
......
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