On Wed, Feb 4, 2009 at 7:11 AM, Jack Andrews <[email protected]> wrote:
> when i want to implement a language, i'm used to using parser
> generators like yacc.  on a couple of occasions, i've tried to find
> out how to hand craft a parser.  i just can't find a way to 'get' the
> programming of state machines.  from my limited exposure to the APL
> community, parsers are hand made. and the APL community usually has a
> fair few smart cookies.

It should be possible to make a lex style program to generate
arguments for J's ;: from some abstract notation.

> can you help me get a hang of programming a state machine? any good links?

First off, please note that ;: does not implement a stack.
So ;: by itself would give you something that can be a
work-alike for a lex generated program rather than for
a yacc generated program.

I have not put much thought into doing something yacc-like with ;:
If I did go there, I might use the code I see when I execute
   edit'trace'
as a model.  In other words, each data type and each
distinct token would get a type so I could treat them
uniformly in my data structures, and then I would take
my yacc style gramar and convert each of its alternate
rules to a pattern and then write a little stack based
parser to grind through them.  (Except for a traditional
parser, my queue would represent left to right
parsing rather than right to left.)

That said, the "magic" of yacc is that it can
translate rules with an arbitrary sequence of
symbols to "only care about one lexical object
at a time", but I would try to avoid going there
because kind of scalar thinking tends to be
very inefficient in J.  I suspect (but do not know)
that you can avoid having to do that kind of
crunching in most useful cases of these kinds
of problems.

On the other hand, most languages are not designed
to have simple grammars, so you might need a
fairly large set of rules to represent them.

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to