Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test pull request (to be closed) #3

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void prog(FILE *fd, int *lineCount) {
* declaration of one or more variables.
*/
void declListVar(FILE *fd, int *lineCount, struct Token token) {
// if const, read next
// if const (optional), read next
if (token.signCode == CONST) {
token = lexerGetNextChar(fd, lineCount);
}
Expand Down Expand Up @@ -66,7 +66,7 @@ void tipo(FILE *fd, int *lineCount, struct Token token) {
* Variable declaration is valid:
* Simply declaring a identifier, or optionally initializing it.
* Can declare as array using curly braces with size given by number or id. Can
* optionally initialize it with square brackets.
* optionally initialize it with square brackets (C notation).
*/
void declVar(FILE *fd, int *lineCount, struct Token token) {
// id mandatory.
Expand All @@ -91,8 +91,8 @@ void declVar(FILE *fd, int *lineCount, struct Token token) {
exit(EXIT_FAILURE);
}

// array: should deal with multidimensional arrays (declaration) and
// initialization
// array: TODO: should deal with multidimensional arrays (declaration) and
// initialization. Declaration is ok. Initialization is tricky
} else if (token.category == SIGN && token.signCode == OPEN_BRACK) {
arrayDeclaration(fd, lineCount, token);
}
Expand All @@ -110,12 +110,11 @@ void arrayDeclaration(FILE *fd, int *lineCount, struct Token token) {
// consume next
token = lexerGetNextChar(fd, lineCount);
if (token.category != SIGN && token.signCode != CLOSE_BRACK) {

fprintf(stderr, "Syntax error: expected array bracket closing\n");
exit(EXIT_FAILURE);

} else {
token = lexerGetNextChar(fd, lineCount);

if (token.category == SIGN && token.signCode == OPEN_BRACK) {
// dealing with multidimensional arrays
continue;
Expand All @@ -124,14 +123,14 @@ void arrayDeclaration(FILE *fd, int *lineCount, struct Token token) {
// consume next
token = lexerGetNextChar(fd, lineCount);
if (token.category != SIGN && token.signCode != OPEN_CURLY) {

// it's optional in the grammar.
arrayInitialization(fd, lineCount, token);
break;
}
// it's optional in the grammar.
arrayInitialization(fd, lineCount, token);
break;

} else {
// no array declaration. what to do?
break;
}
}
}
Expand Down