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
1b032096
Commit
1b032096
authored
Nov 16, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated token formats and added tokes REF, INT instead of ARG.
parent
c14e76cf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
25 deletions
+27
-25
src/lex.l
src/lex.l
+15
-12
src/lex_out.y
src/lex_out.y
+12
-13
No files found.
src/lex.l
View file @
1b032096
...
@@ -2,17 +2,20 @@
...
@@ -2,17 +2,20 @@
#include <stdio.h>
#include <stdio.h>
#include "y.tab.h"
#include "y.tab.h"
%}
%}
arg \$[a-zA-Z0-9\.]+
reg \$[a-zA-Z0-9]+
word [a-zA-Z0-9_\.]+
int [1-9][0-9]*
%%
%%
#[^\n]* { yylval.sval = yytext; return COMMENT; } /* Comment */
[\n] { return NL; } /* Newline */
[a-zA-Z0-9$\.]+: { yylval.sval = yytext; return LABEL; } /* Label */
#.* { yylval.sval = yytext; return COMMENT; } /* Comment */
{arg} { yylval.sval = yytext; return ARG; } /* Arg of instr */
\..* { yylval.sval = yytext; return DIRECTIVE; } /* Assembly directive */
[0-9]+(\({arg}\))? { yylval.sval = yytext; return ARG; } /* Arg of instr */
{reg} { yylval.sval = yytext; return REG; } /* Registry address */
\.[^\n]* { yylval.sval = yytext; return DIRECTIVE; } /* Assembly */
{word}: { yylval.sval = yytext; return LABEL; } /* Label */
[a-z\.]+ { yylval.sval = yytext; return INSTR; } /* Instruction */
{int} { yylval.ival = atoi(yytext); return INT; } /* Integer */
[,] { return COMMA; } /* Comma */
[0-9]+(\({reg}\))? { yylval.sval = yytext; return OFFSET; } /* Registry offset */
[\n] { return NL; } /* New line */
[a-z\.]+ { yylval.sval = yytext; return INSTR; } /* Instruction */
{word} { yylval.sval = yytext; return REF; } /* Label reference */
[ \t]+ { ; } /* Ignore whitespace */
[,] { return COMMA; } /* Comma */
[ \t]+ ; /* Ignore whitespace */
src/lex_out.y
View file @
1b032096
...
@@ -4,28 +4,27 @@
...
@@ -4,28 +4,27 @@
void yyerror(char*);
void yyerror(char*);
%}
%}
%token COMMA NL
%union {
%union {
int ival;
char *sval;
char *sval;
}
}
%token <sval> LABEL
%token NL COMMA
%token <sval> ARG
%token <ival> INT
%token <sval> INSTR
%token <sval> COMMENT DIRECTIVE REG LABEL OFFSET INSTR REF
%token <sval> DIRECTIVE
%token <sval> COMMENT
%%
%%
symb:
symb:
symb symb
symb symb
| COMMENT {printf("Found a comment: %s\n", $1);}
| DIRECTIVE {printf("Found a directive: %s\n", $1);}
| REG {printf("Found a registry address: %s\n", $1);}
| LABEL {printf("Found a label: %s\n", $1);}
| LABEL {printf("Found a label: %s\n", $1);}
| ARG {printf("Found an argument: %s\n", $1);}
| REF {printf("Found a label reference: %s\n", $1);}
| INT {printf("Found an integer: %d\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);}
| COMMA {printf("Found a comma\n");}
| COMMA {printf("Found a comma\n");}
| COMMENT {printf("Found a comment: %s\n", $1);}
| NL {printf("Found a newline\n");}
| NL {printf("Found a newline\n");}
;
;
%%
%%
...
@@ -41,7 +40,7 @@ main(int argc, const char* argv[])
...
@@ -41,7 +40,7 @@ main(int argc, const char* argv[])
printf("No file specified");
printf("No file specified");
exit(-1);
exit(-1);
}
}
// open a file handle to a particular file:
// open a file handle to a particular file:
FILE *myfile = fopen(argv[1], "r");
FILE *myfile = fopen(argv[1], "r");
// make sure it is valid:
// make sure it is valid:
...
@@ -51,7 +50,7 @@ main(int argc, const char* argv[])
...
@@ -51,7 +50,7 @@ main(int argc, const char* argv[])
}
}
// set lex to read from it instead of defaulting to STDIN:
// set lex to read from it instead of defaulting to STDIN:
yyin = myfile;
yyin = myfile;
// parse through the input until there is no more:
// parse through the input until there is no more:
do {
do {
yyparse();
yyparse();
...
@@ -62,4 +61,4 @@ void yyerror(char *s)
...
@@ -62,4 +61,4 @@ void yyerror(char *s)
{
{
printf("Found error: %s\n", s);
printf("Found error: %s\n", s);
exit(-1);
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