LangProc / langproc-2019-cw

Master repo for Language Processors 2019/2020 coursework component
5 stars 7 forks source link

Unnamed Parameters #16

Open jrrrp opened 4 years ago

jrrrp commented 4 years ago

They're not explicitly listed but I might as well check: are unnamed parameters to be implemented? Ie abstract parameters.

Edit: And also with this the whole idea of abstract declarators?

ymherklotz commented 4 years ago

Could you clarify what you mean by unnamed or abstract parameters?

I don't believe these are valid C. Everything that is in ANSI C89 could be tested, except for the features that were explicitly listed shouldn't be supported.

JaafarRammal commented 4 years ago

@jrpdotjpg an example would be helpful :octocat:

jrrrp commented 4 years ago

Yes sorry, the question wasn't exactly clear. I meant to say will function declarations like int func(int) be tested, which I'm pretty sure are in C90.

JaafarRammal commented 4 years ago

This is completely valid and would look like this:

Screen Shot 2020-03-06 at 12 29 30 AM

We just need a confirmation if this is to be implemented (as it would complicate things in the function definition / declaration)

jrrrp commented 4 years ago

Yes it's valid, but will it be tested?

These are old C-style function declarations, which are not going to be tested according to spec if I remember correctly.

K&R are different to this, they just have identifiers without types

JaafarRammal commented 4 years ago

Update: according to the C grammar, it is valid. According to this online compiler, the following code will not compile:

int f(int ){
    return 3;
}

int main()
{
    return f(3);
}
jrrrp commented 4 years ago

Ah, seems these are just to be used with function prototypes: int f(int);

JaafarRammal commented 4 years ago

So basically a valid code is:

int f(int);
int main(){return f(3);}
int f(int x){return x;}

It compiles. It also doesn't differ at all from implementing the following on both the parsing and assembly generation levels (just make the identifier optional):

int f(int x);
int main(){return f(3);}
int f(int x){return x;}

I would say make the rule:

spec=declarationSpecifiers dec=abstractDeclarator?

and since you know it's valid input, dec will always be there during a definition (you can still check if the node is null). You also will never need dec when declaring the function, only the type and the order of the types is necessary

ymherklotz commented 4 years ago

Yes, function prototypes could be tested. Unnamed parameters in function definitions are not valid C90 so should not be supported.

AdrianKoch3010 commented 4 years ago

What about function declarations that don't give any information about the parameters.

The following would be valid c

int foo();
int main(){ return foo(7, 'a'); }
int foo(int x, char c) { return x; }
ymherklotz commented 4 years ago

I would say you can assume that prototypes will actually match up with their declarations and contain the type information.