thelink2012 / cminus

A simple compiler for a simple language
MIT License
1 stars 1 forks source link

Semantic Analysis #2

Closed thelink2012 closed 6 years ago

thelink2012 commented 6 years ago
<program> ::= <declaration-list>
<declaration-list> ::= <declaration-list> <declaration> | <declaration>
<declaration> ::= <var-declaration> | <fun-declaration>
<var-declaration> ::= <type-specifier> ID ; | <type-specifier> ID [ NUM ] ;
<type-specifier> ::= int | void
<fun-declaration> ::= <type-specifier> ID ( <params> ) <compound-stmt>
<params> ::= <param-list> | void
<param-list> ::= <param-list> , <param> | <param>
<param> ::= <type-specifier> ID | <type-specifier> ID [ ] 
<compound-stmt> ::= { <local-declarations> <statement-list> }
<return-stmt> ::= return ; | return <expression> ;
<expression> ::= <var> = <expression> | <simple-expression>
<var> ::= ID | ID [ <expression> ]

MAIS EXPRESSOES
<factor> ::= ( <expression> ) | <var> | <call> | NUM
<call> ::= ID ( <args> )
<args> ::= <arg-list> | empty
<arg-list> ::= <arg-list> , <expression> | <expression>
int input(void)  {...}
void println(int x) {...}

More Stuff

thelink2012 commented 6 years ago

After done, read https://sites.google.com/view/mata61ufba/linguagem-do-compilador?authuser=0 again to ensure it's all right

thelink2012 commented 6 years ago
void foo(void)
{
   return returns_void();
}

is actually invalid

thelink2012 commented 6 years ago

According to the spec the following shall not be valid (I guess).

void foo(int a[])
{
}

void main(void)
{
    int a[10];
    foo((a)); /* parens are not acceptable */
}

But due to the AST requirements this cannot be tested. So we'll consider this a specification error. No tests will be provided for this case.