Commit c14e76cf authored by Jayke Meijer's avatar Jayke Meijer

worked on Lex and Yacc.

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