Gray4 parser generator 
Author Message
 Gray4 parser generator

Hi All,
I am a Forth newbie. Currently I try to learn and use Gray parser
generator written by Martin Anton Ertl,
ftp://server.complang.tuwien.ac.at/pub/forth/gray4.zip. For some
reason I was not able to run it under Win32Forth or Spf4 (note: for
case-sensitive Spf4 I've modified source text into upper case). Then
I've loaded and installed gForth for Win32 from
http://www.*-*-*.com/
I can load Gray.fs into Gforth (in fact I use Gray from gForth
distribution, otherwise I cannot get anything), then I can include
mini.fs. But I am not quite sure what I suppose to get as a result? If
I run word mini:

S" test.mini" mini

I've got nothing...
Did anybody use Gray before? Could you please pinpoint to a sample of
Gray usage? So far Gray description states: "It should not be hard to
generate parsers for most programming languages with Gray", but I am
not quite sure what does it mean. Shall I treat Gray purely as a
"template", trying to learn its techniquie only, or shall I expect a
parser as an exe file, or something else? I know that answers are in
the gray.fs source, but perhaps it will take weeks before I would be
able fully understand what it suppose to do :-)
Regards
  Alex



Fri, 06 Feb 2004 15:07:34 GMT  
 Gray4 parser generator

Quote:
> I am a Forth newbie. Currently I try to learn and use Gray parser
> generator written by Martin Anton Ertl,

There are easier ways to start. But if you insist :-)

Quote:
> ftp://server.complang.tuwien.ac.at/pub/forth/gray4.zip. For some
> reason I was not able to run it under Win32Forth or Spf4 (note: for
> case-sensitive Spf4 I've modified source text into upper case).

There might be a problem with uppercase conversion. Or maybe not
anymore, I only use(d) Gray-3.

Quote:
>                                                                 Then
> I've loaded and installed gForth for Win32 from
> http://www.complang.tuwien.ac.at/forth/gforth
> I can load Gray.fs into Gforth (in fact I use Gray from gForth
> distribution, otherwise I cannot get anything), then I can include
> mini.fs. But I am not quite sure what I suppose to get as a result? If
> I run word mini:
> S" test.mini" mini
> I've got nothing...

Maybe the interface to this word has changed. Below is what I do.

Quote:
> Did anybody use Gray before? Could you please pinpoint to a sample of
> Gray usage? So far Gray description states: "It should not be hard to
> generate parsers for most programming languages with Gray", but I am
> not quite sure what does it mean. Shall I treat Gray purely as a
> "template", trying to learn its techniquie only, or shall I expect a
> parser as an exe file, or something else? I know that answers are in
> the gray.fs source, but perhaps it will take weeks before I would be
> able fully understand what it suppose to do :-)

When you look into test.min, there is a little program in a language
vaguely reminiscent of Pascal. The syntax and semantics for this little
language are completely defined in mini.fs, which is build with Gray.
Many possibilities should now bubbling in your brain. When not, try
some other Forth material and come back later.

-marcel

=================
Try to type this:

  cr .( mini )
  s" mini.fs" included
  s" test.min" included

The file test.min contains this:

-----8<------
mini

PROGRAM test
VAR laufVar, i, j, SUM
BEGIN
Read i;
laufVar := i+1;
j := 0 - 1;
SUM := j;
WHILE laufVar > 0 DO
        j := j + 2;
        IF j#3 THEN SUM := SUM+j END;
        laufVar := laufVar -1
        END;
IF i+1 > 0 THEN j:=j-2 END;
IF i > 0 THEN SUM := 3+SUM END;
Write SUM - (j - 2 * 2 + 11 + 9 - (3*5))
END

0  ( that was for mini ??)
5 test  
6 test
-1 test
-2 test
111 test
------8<------

There should be output, on my system I get:

25 36 -1 -1 12321

You can take it from there. It is fun.

-marcel



Sat, 07 Feb 2004 06:15:39 GMT  
 Gray4 parser generator


Quote:
>Hi All,
>I am a Forth newbie. Currently I try to learn and use Gray parser
>generator written by Martin Anton Ertl,
>ftp://server.complang.tuwien.ac.at/pub/forth/gray4.zip.

That's maybe a little heavy for a newbie.

Quote:
> For some
>reason I was not able to run it under Win32Forth or Spf4

Unless you can at least describe some symptoms, it's hard to tell
what's wrong.

Quote:
> Then
>I've loaded and installed gForth for Win32 from
>http://www.complang.tuwien.ac.at/forth/gforth
>I can load Gray.fs into Gforth (in fact I use Gray from gForth
>distribution, otherwise I cannot get anything)

Define

: 2- 2 - ;

before loading Gray.

Quote:
> then I can include
>mini.fs. But I am not quite sure what I suppose to get as a result?

You get a compiler loaded into the Forth system that you can invoke
with MINI.

Quote:
> If
>I run word mini:

>S" test.mini" mini

>I've got nothing...

You get the program test.mini compiled.  You can invoke it by its name
("test").  It takes one parameter from the stack (because there is one
Read statement executed in the program), and prints one number as
output.  E.g., you can execute

5 test

or

12 test

Take a look at test.fs, and see how the various examples are invoked.

Quote:
>Did anybody use Gray before? Could you please pinpoint to a sample of
>Gray usage?

4 examples are included, 1 of them a complete compiler (mini), and one
a complete interpreter (calc).  You can also look at prims2x.fs in the
Gforth distribution for another application.

Quote:
> Shall I treat Gray purely as a
>"template", trying to learn its techniquie only, or shall I expect a
>parser as an exe file, or something else?

The parser is executable Forth code, and you can invoke it through the
word that you specified to PARSER.

Quote:
> I know that answers are in
>the gray.fs source, but perhaps it will take weeks before I would be
>able fully understand what it suppose to do :-)

Actually the README and gray.doc should be sufficient.  If your OS has
trouble displaying gray.doc, rename it into gray.txt.  To understand
the source, it is probably necessary to understand how to use Gray,
and to know something about LL(1) and recursive descent parsers.

- anton
--
M. Anton Ertl                    Some things have to be seen to be believed

http://www.complang.tuwien.ac.at/anton/home.html



Sat, 07 Feb 2004 16:43:33 GMT  
 Gray4 parser generator

Quote:


> > For some
> >reason I was not able to run it under Win32Forth or Spf4

> Unless you can at least describe some symptoms, it's hard to tell
> what's wrong.

It crashes while executing words RULE and PARSER.
Spf4 is case-sensitive, so I've modified gray.fs into up-case
(Gray4spf.f); also I've modified calc.fs into up-case (Calc4spf.f).
Then I tried to "trace" two last lines of Calc4spf.f

\ -----------------------------------
Firstly I've commented last line (that have PARSER word) and commented
RULE:
 ))  expr \ RULE ( -- n )
I've included Gray4spf.f, reply is Ok. Then I've included Calc4spf.f,
reply is:
 Ok ( 5610388 5605880 )
Then I execute word RULE "manually":
NEW-CONTEXT
 Ok ( 5610388 )
Rule-Body

 Ok ( 5610388 5603157 )
Next word is IF, but it does not make sense for me, because 5603157
apparently is an address. If I execute another fetch it looks more

 Ok ( 5610388 0 )

I guess the error part:
IF .IN ." multiple rules for nonterminal" GRAY-ERROR ENDIF
shall not be executed. Then I type the rest of RULE's words:
DROP Rule-Body ! OLD-CONTEXT
 Ok
System actually crashed when the sentence IF-ENDIF was proceeded, it
something wrong with the word .IN. I'm going to sort it out later. At

without crashing.

\ -----------------------------------
Secondly in the Calc4spf.f I've removed comment from RULE, commented
word PARSER in the last line and conducted "manual" execution of word
PARSER. After a while I realize that system crashes when it executes
word BINARY-SET-TEST? (PARSER -> PROPAGATE -> SUBSET? ->
BINARY-SET-TEST?)
Before BINARY-SET-TEST? data stack is:
Ok ( 5611016 5603141 5603141 57 5592528 )
Executing BINARY-SET-TEST? "manually" I've used a Tmp variable instead
of R-stack. Thus, instead of >R execute:
Tmp !
 Ok ( 5611016 5603141 5603141 57 )
TRUE ROT ROT
 Ok ( 5611016 5603141 4294967295(-1) 5603141 57 )

 Ok ( [6].. 5603141 4294967295(-1) 5603141 57 5592528 )

 Ok ( [8].. 5603141 57 5592528 8 0 )

Then I skip DO and execute:

 Ok ( [9].. 57 5592528 8 4294967093(-203) 8 )


system image:

6DEDE8   7C 00 6F 00  94 25 54 00  A0 25 54 00  D8 14 6F 00
|.o.?%T.%T.+.o.
6DEDF8   A0 25 54 00  08 00 00 00  1C FE 6D 00  A0 25 54 00
%T......|m.%T.
6DEE08   5F 01 00 00  86 02 01 00  28 EE 6D 00  67 01 00 00
_...?...(em.g...
USER DATA: 6F007C HANDLER: 6DEE38 RETURN STACK:
6DEE28 :  54C15C INTERPRET_
6DEE2C :  54C1F5 INTERPRET
6DEE30 :  54C484 MAIN1
6DEE34 :  544EFA CATCH
6DEE38 :  6DEE64 <not in the image>

^ ERROR #-1073741819

Regards
  Alex



Sun, 08 Feb 2004 16:33:30 GMT  
 Gray4 parser generator


Quote:


>> > For some
>> >reason I was not able to run it under Win32Forth or Spf4

>> Unless you can at least describe some symptoms, it's hard to tell
>> what's wrong.

>It crashes while executing words RULE and PARSER.
>Spf4 is case-sensitive, so I've modified gray.fs into up-case
>(Gray4spf.f); also I've modified calc.fs into up-case (Calc4spf.f).
>Then I tried to "trace" two last lines of Calc4spf.f

>\ -----------------------------------
>Firstly I've commented last line (that have PARSER word) and commented
>RULE:
> ))  expr \ RULE ( -- n )
>I've included Gray4spf.f, reply is Ok. Then I've included Calc4spf.f,
>reply is:
> Ok ( 5610388 5605880 )
>Then I execute word RULE "manually":
>NEW-CONTEXT
> Ok ( 5610388 )
>Rule-Body
> Ok ( 5610388 5606040 )

> Ok ( 5610388 5603157 )
>Next word is IF, but it does not make sense for me, because 5603157
>apparently is an address.

Yes, it is either an address (if the nonterminal already is associated
with a rule), or 0.  IF makes sense, but you may find it easier to
read if you write "0<> IF".

The problem here is that you actually should have a 0 at this place.

The result of RULE-BODY looks a bit fishy, though (160 bytes from the
start of expr; in Gforth and iforth it's just 116 bytes; unless you
have very strange alignments or sizes of data, 160 is not the right
amount):

Gforth:
.s <2> 1075173212 1075169056  ok
new-context .s <1> 1075173212  ok

iforth:
[2]FORTH> .s
  Data: 134989216 134985056 ---
System: ---
 Float: --- ok
[2]FORTH> new-context .s
  Data: 134989216 ---
System: ---
 Float: --- ok
[1]FORTH> rule-body .s
  Data: 134989216 134985172 ---
System: ---
 Float: --- ok

[2]FORTH> .s
  Data: 134989216 0 ---
System: ---
 Float: --- ok

Quote:
>Before BINARY-SET-TEST? data stack is:
>Ok ( 5611016 5603141 5603141 57 5592528 )

The 57 looks suspicious; it should be a valid address.

Quote:
> Ok ( [8].. 5603141 57 5592528 8 0 )

>Then I skip DO and execute:

You should 2DROP the loop parameters 8 0 if you skip the DO.

In my experience I debug faster by putting tracers (more elaborate
versions of .S) into the code and running it, instead of
single-stepping by hand.

- anton
--
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html



Tue, 10 Feb 2004 17:18:05 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Parser Generator/Scanner Generator for Scheme?

2. Wanted: parser-generator/lexical-analyser-generator outputting Scheme

3. Looking for a Parser/Scanner Generator

4. T-Gen -- parser generator in Smalltalk

5. Q: T-gen/Smalltalk parsers generator tools ?

6. parser generator

7. Parser / Generator Code

8. Looking for Parser Generator for VAST 4.5

9. parser/generator for GemStone?

10. Parser generator targeted to Lex and Parse libraries

11. ANN: Gray5 parser generator available

12. Gray - a parser generator in ANS Forth

 

 
Powered by phpBB® Forum Software