swp-uebersetzerbau-ss13 / common

Shared files between teams.
1 stars 0 forks source link

Grammar #5

Closed flofreud closed 11 years ago

flofreud commented 11 years ago

Comments and Discussion for Grammar See Wiki page: Grammar

fub-frank commented 11 years ago

Can identifiers shadow identifiers with the same name of outer blocks? Example given:

int a;
{
    boolean a;
}

where { and } denote a block.

There are two possibilities:

  1. (with shadowing) boolean a shadows int a. Within the block the address a always references the boolean. Outside of the block address a references the int
  2. (without shadowing) boolean a triggers a parse error / semantic error because a variable named "a" already exists.
flofreud commented 11 years ago

Probably I misread the grammar but if the goal for MS1 is to support:

The grammar only allow to return a loc:

stmt -> return loc
loc -> loc [assign] | id | loc.id

This means, it is invalid to write

return 9+3;

The minimum version would be:

long i;
i = 9 + 3;
return i;

We could either request a change of the grammar or support assignment and declaration by MS1. I think there should be no problems for implementation to modify the grammar:

stmt -> return assign | print assign
fub-frank commented 11 years ago

return we need to support also declarations and assignments, right?

plus type casting. The TAC is complete for MS1. You can have a look over there.

The grammar only allow to return a loc:

Yes and this is how the abstract syntax tree is designed

public interface ReturnNode {
    public IdentifierNode getRightValue();
}

where IdentifierNode is the loc from the grammar. If we want to change the grammar we have to edit the AST. But actually i see no problem in using variable names for print only.

flofreud commented 11 years ago

I ask because the latest proposal for the Lexer does not covers the declarations and statements.

jvf commented 11 years ago

Am i right to assume, that the terminal definition is to be seen as the pattern specification for the lexemes?

If so, i think there is a problems with the integralDigits. I think the + or - in front of a digit should not be treated as part of the lexeme in the lexer, but as its own token.

flofreud commented 11 years ago

I removed it from the num and real beginning and made the real have always at least one pre-seperator digit, a dot and at least one post-seperator digit. This should make the parsing easier. The - for E is still there.