How can I generate grammar at run-time?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I generate grammar at run-time?

Ламер
Hi,

Is it possible to generate grammar on the fly. I want to parse an input text
depending on the grammar_1 that will be taken at run-time. Parse this grammar_1, generate grammar_2
and parse the input text based on grammar_2.

e.g.
--------------------------------------------------------------------------------------------------------------------------------
 /**
  *Grammar_1, it some language that tells to my parser in which form input text will be,
  * like:
  */
  <<${title}>>, ${date}, ${time}, ${tvname} /${author}/ =${duration}=
  ${text}

 /* parse this grammar_1, generate grammar_2
  * for the input like the following one:
  */

<<Evening News>>,12 november 2009, 19:30, KazakhstanTV /Name Surname/ =4,00=
Some input text,sdlfjlskdjfk

/**
 * At the end it should retrieve variables, like
 * ${title} = Evening News
 * ${date} = 12 november 2009
 * etc.
 */
--------------------------------------------------------------------------------------------------------------------------------

Thanks in advance, any help will be appreciated

P.S. Sorry for any grammatical mistakes in English ;)


_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users
Reply | Threaded
Open this post in threaded view
|

Re: How can I generate grammar at run-time?

Oliver Gramberg

Hi, Ламер,

try to use the "--parse" action of Grammatica:

[...]
--parse <file>
      Debugs the grammar by using it to parse the specified
      file. No code has to be generated for this.
[...]
Grammatica can be used for parsing and tokenizing files, even though no parser has been generated. This feature can be very useful for testing and debugging grammars, as illustrated in the figure below.

# java -jar grammatica-1.5.jar test.grammar --parse test.data
[...]

(from http://grammatica.percederberg.net/doc/release/manual/commandline.html)

Good luck!
Oliver



Ламер <[hidden email]>
Sent by: grammatica-users-bounces+oliver.gramberg=[hidden email]

22.04.2010 05:48

Please respond to
[hidden email]

To
[hidden email]
cc
Subject
[Grammatica-users] How can I generate grammar at run-time?





Hi,

Is it possible to generate grammar on the fly. I want to parse an input text
depending on the grammar_1 that will be taken at run-time. Parse this grammar_1, generate grammar_2
and parse the input text based on grammar_2.

e.g.
--------------------------------------------------------------------------------------------------------------------------------
/**
 *Grammar_1, it some language that tells to my parser in which form input text will be,
 * like:
 */
 <<${title}>>, ${date}, ${time}, ${tvname} /${author}/ =${duration}=
 ${text}

/* parse this grammar_1, generate grammar_2
 * for the input like the following one:
 */

<<Evening News>>,12 november 2009, 19:30, KazakhstanTV /Name Surname/ =4,00=
Some input text,sdlfjlskdjfk

/**
* At the end it should retrieve variables, like
* ${title} = Evening News
* ${date} = 12 november 2009
* etc.
*/
--------------------------------------------------------------------------------------------------------------------------------

Thanks in advance, any help will be appreciated

P.S. Sorry for any grammatical mistakes in English ;)


_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users


_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users
Reply | Threaded
Open this post in threaded view
|

Re: Re: How can I generate grammar at run-time?

Ламер
thanks, but actually by saying "at run-time" I mean that
it is decided dynamically how to parse an input string. I want to write flexible
formatter of incoming documents of different structures. And metadata from that texts will be retrieved according to some files that contain grammar. It
would be useful for write another file of grammar, than rewriting the code.
;)

> Hi, Ламер,
> try to use the "--parse" action of Grammatica:
> [...]
> --parse <file>
> Debugs the grammar by using it to parse the specified
> file. No code has to be generated for this.
> [...]
> Grammatica can be used for parsing and tokenizing files, even though no parser has been generated. This feature can be very useful for testing and debugging grammars, as illustrated in the figure below.
> # java -jar grammatica-1.5.jar test.grammar --parse test.data
> [...]
> (from http://grammatica.percederberg.net/doc/release/manual/commandline.html)
> Good luck!
> Oliver
> Ламер <[hidden email]>
> Sent by: grammatica-users-bounces+oliver.gramberg=de.abb.com@nongnu.org22.04.2010 05:48
> Please respond to
> [hidden email]
> To
> [hidden email]
> cc
> Subject
> [Grammatica-users] How can I generate grammar at run-time?
> Hi,
> Is it possible to generate grammar on the fly. I want to parse an input text
> depending on the grammar_1 that will be taken at run-time. Parse this grammar_1, generate grammar_2
> and parse the input text based on grammar_2.
> e.g.
> --------------------------------------------------------------------------------------------------------------------------------
> /**
> *Grammar_1, it some language that tells to my parser in which form input text will be,
> * like:
> */
> <<${title}>>, ${date}, ${time}, ${tvname} /${author}/ =${duration}=
> ${text}
> /* parse this grammar_1, generate grammar_2
> * for the input like the following one:
> */
> <<Evening News>>,12 november 2009, 19:30, KazakhstanTV /Name Surname/ =4,00=
> Some input text,sdlfjlskdjfk
> /**
> * At the end it should retrieve variables, like
> * ${title} = Evening News
> * ${date} = 12 november 2009
> * etc.
> */
> --------------------------------------------------------------------------------------------------------------------------------
> Thanks in advance, any help will be appreciated
> P.S. Sorry for any grammatical mistakes in English ;)
> _______________________________________________
> Grammatica-users mailing list
> [hidden email]
> http://lists.nongnu.org/mailman/listinfo/grammatica-users
>

Здесь спама нет http://mail.yandex.ru/nospam/sign


_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users
Reply | Threaded
Open this post in threaded view
|

Re: Re: How can I generate grammar at run-time?

Oliver Gramberg

Hi, Ламер,

> thanks, but actually by saying "at run-time" I mean that
> it is decided dynamically how to parse an input string. I

> want to write flexible formatter of incoming documents of
> different structures. And metadata from that texts will be
> retrieved according to some files that contain grammar. It
> would be useful for write another file of grammar, than

> rewriting the code.

I'm getting lost in the details here, but it still seems to me that Grammatica's "--parse" action does the same thing as you describe. Think about it: It reads a grammar, builds a parser on the fly, and parses an input according to that grammar, all in one go. Isn't that in principle what you want to do? So, even if you cannot use Grammatica as is, have a look at the sources--it's free, isn't it?--reuse the parser generator code on a high level and roll your own!

What is your preferred programming language?

Regards
Oliver

_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users
Reply | Threaded
Open this post in threaded view
|

Re: Re: How can I generate grammar at run-time?

Per Cederberg
Exactly. Grammatica reads EBNF-files (in the grammar format) and
builds a parser on the fly. The parser source code that it generates
*also* builds that same parser on the fly at initialization.

The limitation is of course that any run-time parser based on
Grammatica can only parse LL grammars.

Cheers,

/Per

2010/4/22 Oliver Gramberg <[hidden email]>:

>
> Hi, Ламер,
>
>> thanks, but actually by saying "at run-time" I mean that
>> it is decided dynamically how to parse an input string. I
>> want to write flexible formatter of incoming documents of
>> different structures. And metadata from that texts will be
>> retrieved according to some files that contain grammar. It
>> would be useful for write another file of grammar, than
>> rewriting the code.
>
> I'm getting lost in the details here, but it still seems to me that
> Grammatica's "--parse" action does the same thing as you describe. Think
> about it: It reads a grammar, builds a parser on the fly, and parses an
> input according to that grammar, all in one go. Isn't that in principle what
> you want to do? So, even if you cannot use Grammatica as is, have a look at
> the sources--it's free, isn't it?--reuse the parser generator code on a high
> level and roll your own!
>
> What is your preferred programming language?
>
> Regards
> Oliver
>
> _______________________________________________
> Grammatica-users mailing list
> [hidden email]
> http://lists.nongnu.org/mailman/listinfo/grammatica-users
>
>


_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: How can I generate grammar at run-time?

Ламер
In reply to this post by Oliver Gramberg

thanks for replying me..

 

Actually, there is some difficulties with the grammar file.

They will be written by users, it'll be hard for them to write it.

 

Let me explain,

/* file f1 tells the structure of input string, */

<<${title}>>, ${date}, ${time} \n

${text}

 

/*input string*/

<<My news>>, 21 apr 2010, 15.45

Lot's of text coming here

 

---------------------------------------------

Output will be a HashMap

 -key-       -value-

${title}       My news

${date}      21 apr 2010

${time}      15.45

 

f1 will change for different types of input,

 

22.04.10, 11:16, "Oliver Gramberg" <[hidden email]>:


Hi, Ламер,

> thanks,but actually by saying "at run-time" I mean that
> it is decided dynamically how to parse an input string. I

> want to write flexible formatter of incomingdocuments of
> different structures. And metadata from thattexts will be
> retrieved according to some files that containgrammar. It
> would be useful for write another file of grammar, than

> rewriting the code.

I'm getting lost in the details here, but it stillseems to me that Grammatica's "--parse" action does the samething as you describe. Think about it: It reads a grammar, builds a parseron the fly, and parses an input according to that grammar, all in one go.Isn't that in principle what you want to do? So, even if you cannot useGrammatica as is, have a look at the sources--it's free, isn't it?--reusethe parser generator code on a high level and roll your own!

What is your preferred programming language?

Regards
Oliver


--
Яндекс.Почта. Письма есть. Спама - нет. http://mail.yandex.ru/nospam/sign
_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users