Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
peephole
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
peephole
Commits
1573e930
Commit
1573e930
authored
Nov 16, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Yacc with makefile etc.
parent
c49aaf7d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
7 deletions
+90
-7
.gitignore
.gitignore
+4
-0
src/Makefile
src/Makefile
+16
-0
src/lex.l
src/lex.l
+7
-7
src/lex_out.y
src/lex_out.y
+63
-0
No files found.
.gitignore
View file @
1573e930
...
...
@@ -4,3 +4,7 @@
*~
*.o
*.s
lex.yy.c
y.tab.c
y.tab.h
parser
src/Makefile
0 → 100644
View file @
1573e930
CC
=
gcc
LEX
=
lex
YACC
=
yacc
CFLAGS
=
-ll
parser
:
lex yacc
$(CC)
-c
lex.yy.c y.tab.c
$(CC)
-o
$@
lex.yy.o y.tab.o
$(CFLAGS)
lex
:
lex.l
$(LEX)
lex.l
yacc
:
lex_out.y
$(YACC)
-d
lex_out.y
all
:
parser
src/lex.l
View file @
1573e930
...
...
@@ -5,12 +5,12 @@
%%
[a-z0-9$._]+: { yylval = yytext; return LABEL; } /* Label */
\$[a-z0-9._] { yylval = yytext; return ARG; } /* Arg of instr */
^[a-z.]+ { yylval = yytext; return INSTR; } /* Instruction */
\.[^\n]* { yylval = yytext; return DIRECTIVE; } /* Assembly */
\,
{ return COMMA; } /* Comma */
#[^\n]* { yylval = yytext; return COMMENT; } /* Comment */
\n
{ return NL; } /* New line */
[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 DIRECTIVE; } /* Assembly */
[,]
{ return COMMA; } /* Comma */
#[^\n]* { yylval
.sval
= yytext; return COMMENT; } /* Comment */
[\n]
{ return NL; } /* New line */
[\s\t]+ { ; } /* Ignore whitespace */
src/lex_out.y
0 → 100644
View file @
1573e930
%{
#include <stdio.h>
#include <stdlib.h>
void yyerror(char*);
%}
%token COMMA NL
%union {
char *sval;
}
%token <sval> LABEL
%token <sval> ARG
%token <sval> INSTR
%token <sval> DIRECTIVE
%token <sval> COMMENT
%%
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);}
| COMMA {printf("Found a comma\n");}
| COMMENT {printf("Found a comment: %s\n", $1);}
| NL {printf("Found a newline\n");}
;
%%
extern int yylex();
extern int yyparse();
extern FILE *yyin;
main(int argc, const char* argv[])
{
if (argc < 2)
{
printf("No file specified");
exit(-1);
}
// open a file handle to a particular file:
FILE *myfile = fopen(argv[1], "r");
// make sure it is valid:
if (!myfile) {
printf("Cannot open %s\n", argv[1]);
return -1;
}
// set lex to read from it instead of defaulting to STDIN:
yyin = myfile;
// parse through the input until there is no more:
do {
yyparse();
} while (!feof(yyin));
}
void yyerror(char *s)
{
printf("Found error: %s\n", s);
exit(-1);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment