Ok, I see now.

So

a0: a4 a1 a5 '\n' ;
a1: a2 a3 | a3 a2 ;
a2: a4 a4 | a5 a5 ;
a3: a4 a5 | a5 a4 ;
a4: 'a' ;
a5: 'b' ;

is a *restatement* of

0: 4 1 5
1: 2 3 | 3 2
2: 4 4 | 5 5
3: 4 5 | 5 4
4: "a"
5: "b"

And, not a recipe for interpreting that part of the file.

So, hmm... I see. Rather than constructing the rules from the file,
you are translating it manually. So, my corresponding J implementation
should perhaps have been something like

example=:0 :0
0: 4 1 5
1: 2 3 | 3 2
2: 4 4 | 5 5
3: 4 5 | 5 4
4: "a"
5: "b"

ababbb
bababa
abbbab
aaabbb
aaaabbb
)

rule0=:limit (rule4 and rule1 and rule5)
rule1=:limit (rule2 and rule3) or (rule3 and rule2)
rule2=:limit (rule4 and rule4) or (rule5 and rule5)
rule3=:limit (rule4 and rule5) or (rule5 and rule4)
rule4=: <@'a'
rule5=: <@'b'

limit=:~.@/:~@]
and=:[: , ,each/
or=:,

matches=:{{
  t=. <;._2 y
  t ([ -. -.) rule0 ''
}}

And, that simplifies the handling of part 2, also. You could use the
output of make to get the code for most of the rule definitions. And
then manually define

rule8=:{{
  r=. rule42 t=.''
  while. -.r-:t do.
    t=.r
    r=. limit r or (rul42'') and r
  end.
}}

rule11=:{{
  r=. limit (rule42 and rule31) ''
  while. -.r-:t do.
    r=. limit r or (rule42'') and r and rule31 ''
  end.
}}

[Instead of updating 'make' to potentially build all rules along the
lines of rule11.]

(And of course, you would also need to update the definition of
'limit' so that productions which were too long would be eliminated.)

But, also, this approach would limit you to handling rather short
strings (depending on the complexity of the rules). If there's too
many possibilities, a slightly different approach would need to be
used. On the other hand (since this approach would actually need to
consume sample messages), that might even simplify the mechanism for
the recursive rules.

FYI,

-- 
Raul

On Thu, Dec 31, 2020 at 9:04 PM David Lambert <[email protected]> wrote:
>
> As I recall, yacc's default token is the ASCII value of a character.  The
> lexer in this case needn't be more complicated, therefore, than getchar.
> The rule in question means "An `a' is expected here."  Were there a `b' in
> the input, and none of the other paths through the rules matched, the
> program reports syntax error.  A little shell scripting to count the syntax
> errors, a bit of subtraction, is the tally of matching strings.
>
> I hope that some part of this answer is satisfactory.  May 2021 be better,
> much, than 2020.
>
> |Raul Miller rauldmiller at gmail.com
> |Thu Dec 31 15:16:52 UTC 2020
> |
> |what is the significance of this line:
> |
> |a4: 'a' ;
> |
> |?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to