LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-20-2010, 07:26 PM   #61
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908

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.
Old 03-20-2010, 07:28 PM   #62
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
EDIT: Be sure to note the difference between Statement and Statements.

Statements:
(any amount of Statement's)

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.)

Last edited by MTK358; 03-21-2010 at 06:40 AM.
 
Old 03-20-2010, 07:30 PM   #63
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by theNbomr View Post
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.
 
0 members found this post helpful.
Old 03-20-2010, 07:33 PM   #64
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by Sergei Steshenko View Post
So IMO it would make sense for MTK358 to first explain what he wants in English
I already did that in my previous post.
 
Old 03-20-2010, 07:38 PM   #65
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
Statements:
(any amount of Statements)

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:
  1. do you want variables to be declared before they are used ?
  2. do you want to have a notion of assignment in its C/Perl sense ?
  3. do you want an assignment to return a value, thus allowing nested assignments and "dirty" "C" code like 'if(a = b)' (yes, just one '=')
  4. 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 ';') ?
 
1 members found this post helpful.
Old 03-20-2010, 07:49 PM   #66
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by Sergei Steshenko View Post
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 View Post
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 View Post
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 View Post
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.

Last edited by MTK358; 03-20-2010 at 07:53 PM.
 
Old 03-20-2010, 07:57 PM   #67
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post

...

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.
 
0 members found this post helpful.
Old 03-20-2010, 08:01 PM   #68
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
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
 
Old 03-20-2010, 08:03 PM   #69
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by MTK358 View Post
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
Bash style?
 
Old 03-20-2010, 08:05 PM   #70
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by smeezekitty View Post
Bash style?
Kind of.

I was thinking something like bash/BASIC-like syntax with C-like functionality.
 
Old 03-20-2010, 08:07 PM   #71
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by MTK358 View Post
Kind of.

I was thinking something like bash/BASIC syntax with C capabilites.
You mean like pascal?


http://en.wikipedia.org/wiki/Pascal_...ng_language%29
 
Old 03-20-2010, 08:09 PM   #72
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I guess the control structures look kind of like what I had in mind, but the rest looks quite different.
 
Old 03-20-2010, 08:20 PM   #73
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MTK358 View Post
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 ?
 
0 members found this post helpful.
Old 03-21-2010, 06:25 AM   #74
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
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.

Last edited by MTK358; 03-21-2010 at 06:38 AM.
 
Old 03-21-2010, 08:29 AM   #75
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443

Original Poster
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I wrote a BNF grammar for most of the language:

EDIT: Revised

Everything in []s is optional
Everything in {}s can be repeated 0 or more times.

Code:
<stmts> ::= |
            { <stmt> }

<stmt> ::= <expr> "\n" |
           "if" <expr> "\n" <stmts> [ "else" "\n" <stmts> ] "fi" \n |
           "while" <expr> "\n" <stmts> "loop" "\n"

<expr> ::= <int> |
           <float> |
           <string> |
           <id> |
           <id> "++" |
           <id> "--" |
           "++" <id> |
           "--" <id> |
           <id> ":=" <expr> |
           <expr> "+" <expr> |
           <expr> "-" <expr> |
           <expr> "*" <expr> |
           <expr> "/" <expr> |
           <expr> "%" <expr> |
           <expr> "=" <expr> |
           <expr> "!=" <expr> |
           <expr> ">" <expr> |
           <expr> "<" <expr> |
           <expr> ">=" <expr> |
           <expr> "<=" <expr> |
           "not" <expr> |
           <expr> "and" <expr> |
           <expr> "nand" <expr> |
           <expr> "or" <expr> |
           <expr> "nor" <expr> |
           <expr> "xor" <expr> |
           <expr> "xnor" <expr> |
           "(" <expr> ")" |
           <id> "(" [ <expr> ] { "," <expr> } ")"

Last edited by MTK358; 03-21-2010 at 11:15 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
lex and yacc in RHEL4 birds Linux - Software 1 06-03-2009 02:56 AM
LEX and YACC with C gr33ndata Programming 4 11-18-2007 05:12 PM
Lex and Yacc on Federo 2.0 vivekian Fedora 6 05-20-2006 09:09 AM
Lex and Yacc on Mandrake 9.2.2 Anuradha Linux - Software 0 07-02-2005 03:32 AM
Lex & YACC coolfrog Programming 3 09-25-2004 07:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration