More grammar stuff (code blocks, scopes..)

Started by
6 comments, last by Grizwald 20 years, 11 months ago
ok, while thinking about my language in the works, i realized that classes are similar to functions (they can be). I''m thinkin of having them both be the same thing in my grammar (i sound all newbie like). for instance, i could have the "class" and "function" specifiers, but all they do is change access (like how structs and classes differ in C++). i sound really incoherent, this hard to describe.
  


class MyClass (args)   //class specifier, myclass identifier.   

                       //args are like template arguments

{
    function Myfunction (args)  //standard function stuff;

    {
         function FunctionInAFunction (args) //only visible from

         {                                   //MyFunction

         
         }
         
         public function FunctionInAFunctionExposed() 
         {}
    }
}  

//the "public" says that it can be called with a call like:


MyClass.MyFunction.FunctionInAFunctionExposed(args)

  
i''m brainstorming here...just like some feedback..this is by no means what i''m doing (too C-Like...i want less syntax!) I might just have everything be statement blocks where methods and properties are public or private. and then entire blocks can be public or private by default, and then individual members can be specified:
  

public
{
  type var;
  private func    //functions and classes can be named code  

                  //blocks

  {
     type func_var;
     public type other_var;
  }
}

  
thanks for reading this incoherent bullshit. If you understand what i mean please give me some feedback. I''m not implementing the rest of my parser without all the grammar.
I love me and you love you.
Advertisement
Besides the fact that you can''t declare functions inside other functions, I don''t know what the heck you''re on about
Why not? He''s not emulating C++....anyway, I think if you could define a function inside a function it could be useful: but what is probably better, is to let function pointers be first class types, and then allow functions to return a function that is defined inside the function.... = closure...for example:

function make_incrementer(int n) {
return function increment(int in) {
return in + n;
};
};

Definitely useful.
quote:Original post by Zipster
Besides the fact that you can't declare functions inside other functions

Says who? Grizwald is designing his own language so can do whatever he likes. However, he might like to think about why C and C++ only allow you to define functions at the top-level. Along the way, he might learn some more about the relationship between classes and functions. None of this has anything to do with `grammar' though...

[edited by - SabreMan on May 7, 2003 7:25:14 AM]
Thank you sabreman. You are right though, this really isn''t grammar. All i''m really after is a language that reads like C/C++/C#/Java but is much more free. I want to have everything in scope blocks. Blocks are treated as objects, and can return values (other objects) as a function would. Blocks can also encapsulate data (like a class would). This makes the language so much more free. Blocks can be nested, and whatnot as well.
The language will contain most standard things (if/else, loops, and other stuff) along with a strong dynamically typed system. Where speed is critical, type info can be specified (anyone remember using this in QB? ) This is still just brainstorming though. this block idea really appeals to me because it will make traversing the parse tree much easier.
I love me and you love you.
My apologies, I thought you were using C++
thats ok. Its C-LIKE :D
I love me and you love you.
I think the word you''re looking for is semantics.


[My site|SGI STL|Bjarne FAQ|C++ FAQ Lite|MSDN|Jargon]
Ripped off from various people
[size=2]

This topic is closed to new replies.

Advertisement