Skip to content

Commit

Permalink
settle on simple string matcher for now
Browse files Browse the repository at this point in the history
  • Loading branch information
oboroc committed Jun 4, 2019
1 parent 57620bb commit 735036f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
2 changes: 2 additions & 0 deletions examples/test.txt
Original file line number Diff line number Diff line change
@@ -1,3 1,5 @@
"string in 'double' quotes"

alpha equ 1

123
Expand Down
2 changes: 1 addition & 1 deletion src/crass.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 45,7 @@ int main(int argc, char** argv)
fprintf(stderr, "ERROR: please provide an input file to process\n");
exit(1);
}
scan_str("0abch A 1 0.1 equ \"abc\" ahaha");
// scan_str("0abch A 1 0.1 equ \"abc\" ahaha");
for (int i = 1; i < argc; i )
{
printf("Argument #%d = %s\n", i, argv[i]);
Expand Down
30 changes: 8 additions & 22 deletions src/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 24,7 @@ TODO: use https://westes.github.io/flex/manual/Common-Patterns.html for basic pa
%option outfile="scanner.flex.c" header-file="scanner.flex.h"
%option prefix="crass"

%x incl str
%x incl

%%

Expand All @@ -50,27 50,13 @@ include BEGIN(incl);
yyterminate();
}

/* https://westes.github.io/flex/manual/Start-Conditions.html#Start-Conditions */
\" BEGIN(str);

/*<str>.*\" {
BEGIN(INITIAL);
printf("A simple string: %s\n", yytext);
}/
/*<str> {
\n yyerror("the string misses \" to termiate before newline");
<<EOF>> yyerror("the string misses \" to terminate before EOF");
([^\\\"]|\\.)* {
/* do your work like save in here */
printf("A simple string: %s\n", yytext);
}
\" BEGIN(INITIAL);
}*/




/* super simple string matcher */
/* a much more complex C-style matcher example is here:
https://westes.github.io/flex/manual/Start-Conditions.html#Start-Conditions */
\"[^\"]*\" {
yytext[strlen(yytext) - 1] = 0; /* remove trailing " */
printf("A sting: %s\n", yytext 1); /* skip over starting " */
}

[0-9] {
printf("An integer: %s (%d)\n", yytext, atoi(yytext));
Expand Down

0 comments on commit 735036f

Please sign in to comment.