Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lessons/002_upn_calculator/calc_002 doesn't produce a useful example program #10

Closed
skvadrik opened this issue Oct 7, 2013 · 3 comments

Comments

@skvadrik
Copy link
Owner

commented Oct 7, 2013

The problem is the fill() routine; if there are less than 3 characters to fill, it just fails, and doesn't try to do anything with the data.

For example:
$ ./a.out "1"
OOD

$ ./a.out "12"
OOD

$ ./a.out "123"
Num
EOF

$ ./a.out "1+1"
Num
+
OOD

$ ./a.out "1+12"
Num
+
OOD

$ ./a.out "1+123"
Num
+
Num
EOF

Original comment by: marjaholtta

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Oct 10, 2013

I don't fully understand the YYFILL stuff (just reading through the lessons), but this seems to produce a more useful example prog:

--- a/re2c/lessons/001_upn_calculator/calc_002.re
+++ b/re2c/lessons/001_upn_calculator/calc_002.re
@@ -33,13 +33,14 @@ int scan(char *s)
char *p = s;
char *l = s;
char *q = 0;

  •   int cont = 1;
    

#define YYCTYPE char
#define YYCURSOR p
#define YYLIMIT l
#define YYMARKER q
-#define YYFILL(n) { if (!fill(p, n, &l)) break; }
+#define YYFILL(n) { if (!fill(p, n, &l)) cont=0; }

- for(;;)

  •   while(cont)
      {
    

/*!re2c
re2c:indent:top = 2;
@@ -52,7 +53,7 @@ int scan(char *s)
[^] { printf("ERR\n"); return 1; }
*/
}

  •   printf("OOD\n"); return 2;
    
  •   printf("EOF\n"); return 0;
    

}

$ ./a.out "1"
Num
EOF

$ ./a.out "12"
Num
EOF

$ ./a.out "1+1"
Num
+
Num
EOF

$ ./a.out "1+12"
Num
+
Num
EOF

Original comment by: marjaholtta

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Oct 10, 2013

More investigation: If we look at the graph for calc_002 (generated by re2c -D calc_002.re), that automaton accepts "0" and "1" and "11" but it doesn't accept "01" -- it only accepts octal numbers which are 3 digits long or longer! So there is another problem there: based on the grammar, "01" should be accepted, but based on the graph, it's not. What's up with that?

Original comment by: marjaholtta

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Mar 19, 2019

That example is deprecated now, new examples are here: http://re2c.org/examples/examples.html

@skvadrik skvadrik closed this Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.