* [Caml-list] Camlp4-tutorial-Example @ 2002-09-02 19:52 Oliver Bandel 2002-09-02 20:52 ` Oliver Bandel 0 siblings, 1 reply; 7+ messages in thread From: Oliver Bandel @ 2002-09-02 19:52 UTC (permalink / raw) To: caml-list Hi, I'm experimenting with the Code of the Camlp4-Tutorial. The simple calculator in Chapter 2 (Grammar-/Plexer-Module) works very fine for calculation. What does not work, is the raising of an error, as explained in the tutorial. I added the expr_eoi-code, described in the example and it does not raise an exception. it simply evaluates the expression, prints the result and stopps. IMHO the example-parser is not correct (Version of the tutorial: 29 December 2001). Any Hints? TIA, Oliver ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Camlp4-tutorial-Example 2002-09-02 19:52 [Caml-list] Camlp4-tutorial-Example Oliver Bandel @ 2002-09-02 20:52 ` Oliver Bandel 2002-09-02 21:43 ` Oliver Bandel 2002-09-03 7:08 ` Daniel de Rauglaudre 0 siblings, 2 replies; 7+ messages in thread From: Oliver Bandel @ 2002-09-02 20:52 UTC (permalink / raw) To: caml-list On Mon, 2 Sep 2002, Oliver Bandel wrote: > Hi, > > I'm experimenting with the Code of the Camlp4-Tutorial. > > The simple calculator in Chapter 2 (Grammar-/Plexer-Module) > works very fine for calculation. What I do not understand: This calculator knows that * and / have higher Priority than + and -. How is this achieved? I didn't find any entries, that provide priority-distinction between +,-,*,/. Is the Grammar-Module magic? (Gramagic?) Ciao, Oliver ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Camlp4-tutorial-Example 2002-09-02 20:52 ` Oliver Bandel @ 2002-09-02 21:43 ` Oliver Bandel 2002-09-03 7:08 ` Daniel de Rauglaudre 1 sibling, 0 replies; 7+ messages in thread From: Oliver Bandel @ 2002-09-02 21:43 UTC (permalink / raw) To: caml-list On Mon, 2 Sep 2002, Oliver Bandel wrote: > > On Mon, 2 Sep 2002, Oliver Bandel wrote: > > > Hi, > > > > I'm experimenting with the Code of the Camlp4-Tutorial. > > > > The simple calculator in Chapter 2 (Grammar-/Plexer-Module) > > works very fine for calculation. > > What I do not understand: > This calculator knows that * and / have higher Priority > than + and -. > How is this achieved? ...looks like what is mentioned as "levels" in the tutorial means that it is meant as "priority levels"? What comes later has higher priority? Ciao, Oliver ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Camlp4-tutorial-Example 2002-09-02 20:52 ` Oliver Bandel 2002-09-02 21:43 ` Oliver Bandel @ 2002-09-03 7:08 ` Daniel de Rauglaudre 2002-09-04 19:46 ` Oliver Bandel 2002-09-06 23:10 ` Oliver Bandel 1 sibling, 2 replies; 7+ messages in thread From: Daniel de Rauglaudre @ 2002-09-03 7:08 UTC (permalink / raw) To: caml-list Hi, On Mon, Sep 02, 2002 at 10:52:27PM +0200, Oliver Bandel wrote: > What I do not understand: > This calculator knows that * and / have higher Priority > than + and -. > How is this achieved? By the order of the rules. The rules with same priority are grouped together: [ ... | ... | ... ] and there is another level of parentheses (of bracket parentheses) separated by vertical bars to indicate the priority: [ [ ... | ... | ... ] (* lowest priority *) | [ ... | ... | ... ] ... | [ ... | ... | ... ] (* highest priority *) ] > I didn't find any entries, that provide priority-distinction > between +,-,*,/. Forget Yacc! :-) > Is the Grammar-Module magic? > (Gramagic?) What do you mean by "magic"? -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Camlp4-tutorial-Example 2002-09-03 7:08 ` Daniel de Rauglaudre @ 2002-09-04 19:46 ` Oliver Bandel 2002-09-06 23:10 ` Oliver Bandel 1 sibling, 0 replies; 7+ messages in thread From: Oliver Bandel @ 2002-09-04 19:46 UTC (permalink / raw) To: Daniel de Rauglaudre; +Cc: caml-list Hi, On Tue, 3 Sep 2002, Daniel de Rauglaudre wrote: > Hi, > > On Mon, Sep 02, 2002 at 10:52:27PM +0200, Oliver Bandel wrote: > > > What I do not understand: > > This calculator knows that * and / have higher Priority > > than + and -. > > How is this achieved? > > By the order of the rules. The rules with same priority are grouped > together: > [ ... | ... | ... ] > > and there is another level of parentheses (of bracket parentheses) > separated by vertical bars to indicate the priority: > [ > [ ... | ... | ... ] (* lowest priority *) > | [ ... | ... | ... ] ... > | [ ... | ... | ... ] (* highest priority *) > ] [...] Ok, that was surprising. But it's a very good idea. :) BTW: The problem in the tutorial, I mentioned was my own: I wrote wrong code. But the reason was, that I didn't understand how the Camlp4 really works (the Grammar-Module). I now print the tutorial out to paper, and hope I will see problems better than on screen. But in general, Ocaml-Software seems to be written for many-years-Ocaml-programmers: They are very fluently in understanding the mli-files and using them as sufficient for programming. Maybe I should read more informations7documentations about the Module-system, so that I can rely on the same mechanism: Reading the mli-files to understand the programs. But nevertheless, an overwiev-documentation is always a good Idea. I hope that I will understand the Camlp4-tutorial, now where I can write my comments on the paper. ;-) > > > I didn't find any entries, that provide priority-distinction > > between +,-,*,/. > > Forget Yacc! :-) OK, I decided to forget it now. What is yacc? ;-) > > > Is the Grammar-Module magic? > > (Gramagic?) > > What do you mean by "magic"? It was a joke. :) It looked like the Camlp4-Preprocessor and the Grammar-Module did know, what to do, and how to handle mathematical operations. After experimenting with changing the levels of the tutorial's code, I thought, that the levels may be levels of priority. I thought, not to read it in the tutorial, but maybe I have not seen it there. I will reread the tutorial in a more patient manner. Ciao, Oliver ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Camlp4-tutorial-Example 2002-09-03 7:08 ` Daniel de Rauglaudre 2002-09-04 19:46 ` Oliver Bandel @ 2002-09-06 23:10 ` Oliver Bandel 2002-09-07 15:52 ` Daniel de Rauglaudre 1 sibling, 1 reply; 7+ messages in thread From: Oliver Bandel @ 2002-09-06 23:10 UTC (permalink / raw) To: Daniel de Rauglaudre; +Cc: caml-list Hi, I started again with reading the Camlp4-tutorial. I now see more clear here. On Tue, 3 Sep 2002, Daniel de Rauglaudre wrote: > Hi, > > On Mon, Sep 02, 2002 at 10:52:27PM +0200, Oliver Bandel wrote: > > > What I do not understand: > > This calculator knows that * and / have higher Priority > > than + and -. > > How is this achieved? > > By the order of the rules. The rules with same priority are grouped > together: > [ ... | ... | ... ] > > and there is another level of parentheses (of bracket parentheses) > separated by vertical bars to indicate the priority: > [ > [ ... | ... | ... ] (* lowest priority *) > | [ ... | ... | ... ] ... > | [ ... | ... | ... ] (* highest priority *) > ] If you would add this to the tutorial, this would be very helpful for people, first reading it. Another question: As far as I see, an expression in the Used Grammar/Plexer combination needs to give back *one* certain type. In the examples until page 13 it's always an int, was is returned back after parsing. What, if I need a string? Yes, i've seen that it is possible to get back functions that, if applied, will give the resulting int. But a) it's again int and b) all functions have same type. What if I need a function that returns back a string? Or do I have to look at it in other ways? Well, in Ocaml (it's big plus) it's necessary to have correct types in the program, so if I want to get back int as well as string, I may define a type type myresult = Int of int | String of string Is this a way, you can recommend? Ciao, Oliver P.S.: I looked at the example with List.assoc on page 11 and 12. I think that's a way to implement own variables of a simple language. Very easy, and again surprising. (Here again: how to use string-variables in a language to implement?) ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Camlp4-tutorial-Example 2002-09-06 23:10 ` Oliver Bandel @ 2002-09-07 15:52 ` Daniel de Rauglaudre 0 siblings, 0 replies; 7+ messages in thread From: Daniel de Rauglaudre @ 2002-09-07 15:52 UTC (permalink / raw) To: caml-list Hi, On Sat, Sep 07, 2002 at 01:10:53AM +0200, Oliver Bandel wrote: > Yes, i've seen that it is possible to get back functions > that, if applied, will give the resulting int. > But a) it's again int and b) all functions have same type. > What if I need a function that returns back a string? No problem. A grammar entry, like a function, can return any type. But if you want that the arithmetic calculator of the example in the Camlp4 tutorial can return any type, in this case, it is not a problem of the Camlp4 grammar, but a problem of typing in OCaml. How would you make a function returning values of several possible types? Indeed with the type like you say: > type myresult = Int of int | String of string > P.S.: I looked at the example with List.assoc on page 11 and 12. > I think that's a way to implement own variables of a simple > language. Very easy, and again surprising. > (Here again: how to use string-variables in a language > to implement?) In this case, the "env" list of the example must be of type: (string * myresult) list ref And yo must enter the variable "foo" by: env := ("foo", Int 27) :: env -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2002-09-07 15:52 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-09-02 19:52 [Caml-list] Camlp4-tutorial-Example Oliver Bandel 2002-09-02 20:52 ` Oliver Bandel 2002-09-02 21:43 ` Oliver Bandel 2002-09-03 7:08 ` Daniel de Rauglaudre 2002-09-04 19:46 ` Oliver Bandel 2002-09-06 23:10 ` Oliver Bandel 2002-09-07 15:52 ` Daniel de Rauglaudre
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox