Created
May 18, 2020 16:07
-
-
Save VedantParanjape/3f4d80ca681830b9a8de9be4fd5472ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
#include <stdio.h> | |
#include <iostream> | |
using namespace std; | |
int linenumbers = 0; | |
extern int yylex(); | |
%} | |
%option noyywrap | |
%x comment | |
%% | |
[ \t] ; | |
[@][0-9]+ { printf("found a constant: %s\n", yytext); return 1; } | |
^[@][a-zA-Z]+.* { printf("found a variable: %s\n", yytext); return 1; } | |
^[.*]{1,3}[=]* { printf("found jump statement")} | |
\n { linenumbers++; return 1; } | |
. ; | |
"/*" { BEGIN(comment); } | |
<comment>"*/" { BEGIN(INITIAL); } | |
<comment>\n { linenumbers++; } | |
<comment>. ; | |
%% | |
int main(int, char**) { | |
// Open a file handle to a particular file: | |
FILE *myfile = fopen("../examples/add/Add.asm", "r"); | |
// Make sure it is valid: | |
if (!myfile) { | |
cout << "I can't open a.snazzle.file!" << endl; | |
return -1; | |
} | |
// Set Flex to read from it instead of defaulting to STDIN: | |
yyin = myfile; | |
// Parse through the input: | |
while(yylex()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment