List Info

Thread: "ocaml_beginners"::[] Another Genlex question




"ocaml_beginners"::[] Another Genlex question
country flaguser name
France
2007-06-08 01:53:42

Hi !

We can tell Genlex to make a lexer with a list of reserved strings.
The different kind of spaces between them do not matter.

But please consider to deal with a language that defines characters this way :
`a is char = 'a' in OCaml.

This backquote must be close to the letter (no space between the two, otherwise would be space char = ' ').

Please how to "say" this to Genlex ?

Fabrice

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Another Genlex question
country flaguser name
France
2007-06-08 03:38:32

> Please how to "say" this to Genlex ?

Maybe it is impossible, maybe we cannot retrieve any info about the amount of space between two tokens.

I thought to use Genlex instead of ocamllex/yacc because it was to parse a lisp-like language with a very simple syntax...

__._,_.___
.

__,_._,___
"ocaml_beginners"::[] Re: Another Genlex question
country flaguser name
United States
2007-06-08 06:16:56


Hi,

I'm not sure I understood your question, but perhaps it would suffice
to "translate" your original string into a OCaml string before passing
it to the lexer : create a "translate" function such that
translate ("`a")="a" ? (the Str module may be useful here to
perform that kind of string conversion).

HTH,

Ewan

--- In ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com, Fabrice Marchant <fabrice.marchant...>
wrote:
>
&gt; Hi !
>
> We can tell Genlex to make a lexer with a list of reserved strings.
> The different kind of spaces between them do not matter.
>
> But please consider to deal with a language that defines characters this way :
> `a is char = 'a' in OCaml.
&gt;
> This backquote must be close to the letter (no space between the two, otherwise would
be space char = ' ').
>
> Please how to "say&quot; this to Genlex ?
>
> Fabrice
>

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Re: Another Genlex question
country flaguser name
France
2007-06-08 06:02:51

Thank you Ewan !

>; I'm not sure I understood your question,
You have understood the problem. Sorry for my poor english language.

> but perhaps it would suffice
> to "translate" your original string into a OCaml string before passing
> it to the lexer : create a "translate" function such that
>; translate ("`a&quot;)=&quot;a" ? (the Str module may be useful here to
> perform that kind of string conversion).

I see : will do a kind of pre-processing (with OCaml not camlp4) to
enclose in single quotes the character that follows the backquote.

Thanks for this idea : I think I can use it.

Fabrice

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Re: Another Genlex question
country flaguser name
France
2007-06-08 14:49:32

Translating the original lisp-like language strings into compatible Genlex...
`a -> 'a'

Not so simple in fact : a backquote could be inside a string ("qwe`r") or inside a comment.
Moreover the little language comments ( semicolon - ; - up to end of line ) do not follow OCaml standard.

I wonder if it wouldn't be less tricky to modify Genlex source code ?

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Re: Another Genlex question
country flaguser name
United States
2007-06-08 16:31:03

On Fri, 8 Jun 2007, Fabrice Marchant wrote:

> I wonder if it wouldn't be less tricky to modify Genlex source code ?

I was going to recommend this earlier. I think this is a good way to go.

Last year, I experimented a bit with a "little language&quot; parser with
Genlex because I wanted to focus on parsing and not worry so much about
the lexing step. Eventually, I reached a point where I couldn't get what I
wanted (changing the syntax for comments, among other things) and decided
to try to modify Genlex. I was surprised to find that it is very small,
simple, and easy to work with (so long as the language you're parsing at
least somewhat resembles OCaml =).

Good luck,
Dave

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Re: Another Genlex question
country flaguser name
France
2007-06-08 15:18:31

> > I wonder if it wouldn't be less tricky to modify Genlex source code ?
>
> I was going to recommend this earlier. I think this is a good way to go.
>
> Last year, I experimented a bit with a "little language&quot; parser with
> Genlex because I wanted to focus on parsing and not worry so much about
> the lexing step. Eventually, I reached a point where I couldn't get what I
> wanted (changing the syntax for comments, among other things) and decided
> to try to modify Genlex. I was surprised to find that it is very small,
> simple, and easy to work with (so long as the language you're parsing at
> least somewhat resembles OCaml =).
>
> Good luck,
&gt; Dave

Thanks a lot Dave !
I see it isn't 200 lines code indeed (and caml-light version is even shorter).

Best regards,

Fabrice

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Re: Another Genlex question
country flaguser name
United Kingdom
2007-06-08 18:04:46

On Friday 08 June 2007 22:31:03 Dave Benjamin wrote:
&gt; On Fri, 8 Jun 2007, Fabrice Marchant wrote:
&gt; > I wonder if it wouldn't be less tricky to modify Genlex source code ?
>
> I was going to recommend this earlier. I think this is a good way to go.

Why not just use ocamllex?

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists/?e

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] Re: Another Genlex question
country flaguser name
France
2007-06-08 17:01:38

> Why not just use ocamllex?

It is only a feeling question.

The syntax is so simple : only 3 reserved keywords "(&quot;, ")&quot; and ":&quot; with no numbers ( but this is an interesting original and experimental tiny language I hope ).

Maybe I'm primary and simple minded but I would be glad to avoid this robot shift step and to keep close to the full code.
As a beginner I want to control all the OCaml code and to understand the details.

Moreover, the generated code is so ugly with its kind of "OCaml machine language&quot; :
"0000255255216255252255248255241255240255239255
2382552372550200...."

__._,_.___
.

__,_._,___
[1-9]

about | contact  Other archives ( Real Estate discussion Medical topics )