Computing.Net > Forums > Unix > context free grammer

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

context free grammer

Reply to Message Icon

Name: Dilip Tiwari
Date: March 25, 2003 at 22:12:28 Pacific
OS: Win98 SE
CPU/Ram: P330 / 64 MB
Comment:

I have to submitt my assingments in collage and following question i am not able to solve....i need help.....

Q. Discuss usefulness of CONTEXT FREE GRAMMAR. Construct context free grammar for all conditional and looping statements in C-language.

Thanks and bye !
Dilip



Sponsored Link
Ads by Google

Response Number 1
Name: Jimbo
Date: March 26, 2003 at 00:18:20 Pacific
Reply:

Try a google search on 'context free grammar' and you will find a good amount of discussion on this topic. Also, try posting to the programming forum too.

-jim


0

Response Number 2
Name: Sarika
Date: April 4, 2003 at 00:46:08 Pacific
Reply:

Hi Dilip,
go through the reply.May be it'll be of some use

A context-free grammar is a formal grammar in which every production rule is of the form

V -> w
where V is a nonterminal symbol and w is a string consisting of terminals and/or non-terminals. The term "context-free" comes from the feature that the variable V can always be replaced by w, no matter in what context it occurs. A formal language is context-free if there is a context-free grammar which generates it.
Context-free grammars are important because they are powerful enough to describe the syntax of programming languages; in fact, almost all programming languages are defined via context-free grammars. On the other hand, context-free grammars are simple enough to allow the construction of efficient parsing algorithms which for a given string determine whether and how it can be generated from the grammar.
___________________________________________
Here is a context-free grammar for syntactically correct infix algebraic expressions in the variables x, y and z:

S -> T + S | T - S | T
T -> T * T | T / T | ( S ) | x | y | z
This grammar can for example generate the string "( x + y ) * x - z * y / ( x + x )".

Regards


0

Response Number 3
Name: Rishiraj
Date: April 21, 2003 at 05:12:22 Pacific
Reply:

A) Context Free Grammar for if……..else………if statement
---à if ( ) else if ( )

= Statement
= Expression
Non-terminal symbols are and
Terminal symbols are if and else
is the Start symbol

B) Context Free Grammar for Switch statement
---à switch ( )
---à case :
= Statement
= Expression
Non-terminal symbols are and
Terminal symbols are switch and case
The symbol at the end of the first line is the production
is the Start symbol

C) Context Free Grammar for Do……….while statement
---à do while ( ) ;
= Statement
= Expression
Non-terminal symbols are and
Terminal symbols are do and while
is the Start symbol

Hope this helps
Regards



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: context free grammer

Free BSD www.computing.net/answers/unix/free-bsd/4374.html

Free unix falvor www.computing.net/answers/unix/free-unix-falvor/7202.html

Free Shell acct anywhere ? www.computing.net/answers/unix/free-shell-acct-anywhere-/4961.html