"Samay Gupta" <23*6*5*
8@s*u*e*t*u*a*e*u*a*> wrote:
> ml language rule #7 states that "variables do not need to be defined before being used in an expression", is the line number 3 in following ml code legit ml expression/statement?
>
> x <-5
> print x
> y
> print y
This is invalid syntax.
>program:
> ( program-item )*
A program is made up of zero or more program items.
>program-item:
> statement
> | function identifier ( identifier )*
> ←–tab–→ statement1
> ←–tab–→ statement2
> ....
A program item is either a statement or a function, a function can have zero or more identifiers.
>statement:
> identifier "<-" expression
> | print expression
> | return expression
> | functioncall
A statement is either an assignment or a print statement or a return statement or a function call (note there is no expression on their own here).
>expression:
> term [ ("+" | "-") expression ]
An expression is a term joined with zero or one expressions with either a plus or a minus (expression is called recursively so this can be infinitely long)
>term:
> factor [ ("*" | "/") term ]
A term is a factor joined with zero or one terms with either multiplication or division (also recursive so can be infinitely long).
>factor:
> realconstant
> | identifier
> | functioncall
> | "(" expression ")"
A factor is a real constant or identifier or function call or expression surrounded by brackets.
>functioncall:
> identifier "(" [ expression ( "," expression )* ] ")"
A function call is an identifier followed by two brackets, inside of which can be zero or one expressions followed by zero or more expressions with a comma between them.