mayankmahajan24 / QL

QL Language and Compiler, for Programming Langauges and Translators Course Fall 2015
4 stars 2 forks source link

Sast anshul mayank #14

Closed anshulkgupta closed 8 years ago

anshulkgupta commented 8 years ago

Changes to Array Initialisation:

See test-array-1.ql and test-array-n-fail.ql for this functionality.

if/else statement:

So our parse was really funny w.r.t to if/else statements because of new line symbols

if (5 > 4) { print("hello")
}
if (5 > 4) { int a = 5
print("hello")
}

the previous ones worked but not the folowing ones

if (5>4) { int a = 5 }
if (5 >4) {
    int a  = 5
}

so I changed our parser to accept the following:

/* Different forms of if_else */
if_else_stmt:
  IF LPAREN bool_expr RPAREN
    LCURLY stmt_list RCURLY
    ENDLINE %prec NOELSE                        { If($3, $6, []) }
  | IF LPAREN bool_expr RPAREN
    ENDLINE LCURLY stmt_list RCURLY
    ENDLINE %prec NOELSE                        { If($3, $7, []) }
  | IF LPAREN bool_expr RPAREN
    LCURLY stmt_list RCURLY
    ELSE LCURLY stmt_list RCURLY ENDLINE        { If($3, $6, $10) }
  | IF LPAREN bool_expr RPAREN
    ENDLINE LCURLY stmt_list RCURLY
    ELSE LCURLY stmt_list RCURLY ENDLINE        { If($3, $7, $11) }

if you stare the above code snippet it long enough, the only addition is a NEWLINE symbol. Our language obviously doesn’t ignore new line as it does other forms of whitespace.

Another error in our parser was that it didn’t allow us to change the values of variables: so

int a = 10
a = 5

would lead to a parsing error. I made a change to our parser, AST and to semantic.ml to fix this. Created an updatevar set of tests for this.