954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Convert expression to BNF

how can i change this x=x+y of a c++ to a bnf form?

Lun
Newbie Poster
14 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

BNF is a way of describing the grammar for the language.

It it not a means of describing random program snippets such as this.

You might begin with
<assignment> ::= <variable> "=" <expression>

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

thanx..

i did it that way but i guess something is wrong with my code... it doesn't want to run when i put something like x=1 or either x=x+1

Lun
Newbie Poster
14 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

Run?
What are you trying to 'run' ?

Post what you tried.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

i have this program with me that i programmed but i am just stuck... i don't really know where it went wrong..... and it's my first time to program in c++... would you like to look at the code?

Lun
Newbie Poster
14 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

>would you like to look at the code?
This just slows down the process. Post your code, tell us what errors you're getting, and someone will get to it. "Will you look at the code?", "Can anyone help?", etc.. will invariably be answered with "Yes! Ask already!", so why not skip that part and just ask your question?

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

yes ma'am sorry for that...

don't mean to

Lun
Newbie Poster
14 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

I'm confused as to where 'bnf' fits into the discussion.

If you have some C++ code, then just post it already and stop with the 1 or 2 line posts which don't convey any information that anyone else could use to help you.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

help!! do i need to change to get x=1.....?

//<ass>-><var>=<expr>
void assignment()
{
 if(nextToken == VARIABLE_TOK)
 {
  lex();
  if(nextToken==EQUAL_TOK)
  {
   lex();
   logical_expr();
   if(nextToken==END_STMT_TOK)
   {
    cout << "end statement: ok"<< endl;
    cout << END_STMT_TOK<< endl;
   cout << "assignment function: ok"<< endl;
   }
    else cout <<"put an end stmt ."<<endl;
  }
    else cout << "invalid it should be = operator only!"<< endl;
 }
  else cout << "invalid it should be variable only!"<< endl;
}
Lun
Newbie Poster
14 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You