ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
But English sucks for stuff like that. That's why things like BNF were invented. And once you've created that unambiguous description, you're pretty much just a 'make' away from the final product.
--- rod.
1 members found this post helpful.
Click here to see the post LQ members have rated as the most helpful post in this thread.
But English sucks for stuff like that. That's why things like BNF were invented. And once you've created that unambiguous description, you're pretty much just a 'make' away from the final product.
--- rod.
Of course. But the sarcastic point is that BNF itself is explained in (terms of) English.
So IMO it would make sense for MTK358 to first explain what he wants in English, and then his explanation/desires will be formalized into something conceptually similar to BNF and friends.
Statement:
expression \n
---or---
while Expression \n Statements loop \n
---or---
if Expression \n Statements fi \n
---or---
if Expression \n Statements else \n Statements fi \n
Expression:
(any expression that evaluates to a value, including math ops, variable assignments , boolean ops, function calls, etc.)
I suggested first English, not that formal explanation.
For example:
do you want variables to be declared before they are used ?
do you want to have a notion of assignment in its C/Perl sense ?
do you want an assignment to return a value, thus allowing nested assignments and "dirty" "C" code like 'if(a = b)' (yes, just one '=')
do you want to have the possibility for while/if/else body to have more than one "action" (by "action" I mean C/Perl executable statement separated by ';') ?
do you want variables to be declared before they are used ?
For the interpreter version, I don't care, but for the compiler version, yes.
Quote:
Originally Posted by Sergei Steshenko
do you want to have a notion of assignment in its C/Perl sense ?
You mean assigning an expression to a variable? Yes, using the := operator. +=, -=, *=, /=, and %= (and maybe more) will also be available.
Quote:
Originally Posted by Sergei Steshenko
do you want an assignment to return a value, thus allowing nested assignments and "dirty" "C" code like 'if(a = b)' (yes, just one '=')
Yes.
But := will be the assignment op (like "=" in C) (it will evaluate to the new value of the variable being assigned to), and = will be the comparison op (like "==" in C).
Quote:
Originally Posted by Sergei Steshenko
do you want to have the possibility for while/if/else body to have more than one "action" (by "action" I mean C/Perl executable statement separated by ';') ?
What do you mean?
They can contain multiple statements, each on its own line (no semicolons). See my "pseudo-BNF" description that I previously posted.
What do you mean?
They can contain multiple statements, each on its own line (no semicolons).
In "C"
Code:
if(a > b)
c = d;
e = f; // misleading indentation !!!
the 'e = f' will always be executed - regardless of 'a > b'.
So, in C/Perl (and not only them) there is a notion of code block (denoted by '{', '}'), i.e. if the above both assignments are both meant to be conditional, one should write
Code:
if(a > b)
{
c = d;
e = f;
}
.
So, do you want code blocks ? And, I guess, you've already guessed that I'm pushing you towards 'code block' language construct.
In my language they will all be blocks by default, there will be no way not to make a block.
For example:
Code:
if a > b
c = d # Both are executed only if (a > b) != 0
e = f
fi
OK, so you want blocks, but the question remains - if you have an 'if' with and 'else' how do you denote the 'if' block and how do you denote the 'else' block ?
The keyword if followed by an expression and a newline starts a block.
The keyword fi ends a block started by if
The keyword else on its own line can optionally be inserted within the block, separating it.
I am really getting annoyed by this. All this is explained clearly and simply in post #62. If you can't understand that diagram, then of all seriousness I don't think you're the right one to help me with this.
And BNF is described in English not because English is good, but because it's the only thing you can be sure a person understands beforehand.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.