Menu

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

0.15
open
nobody
None
5
2015-06-04
2013-10-07
No

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

Discussion

  • Marja Hölttä

    Marja Hölttä - 2013-10-10

    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

     

    Last edit: Marja Hölttä 2013-10-10
  • Marja Hölttä

    Marja Hölttä - 2013-10-10

    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?

     

Log in to post a comment.