Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Required to build a parser, combined with a tokenizer, for a small subset of the

ID: 3800367 • Letter: R

Question

Required to build a parser, combined with a tokenizer, for a small subset of the ML language,

Sequence of statements and variable declarations. At this level, your parser
needs to recognize the input program as a sequence of statements described by the
following ambiguous BNF.

p ::= epsilon | p s
c ::= c ; d | d
s ::= e2 ; | d ; | while e do s
d ::= val identifier : t = e2
t ::= int | real | unit | bool

t ref | t list
| t list
| t * t
e2 ::= e
| e := e2
| let c in p e2 end
| if e then e2 else e2
| ( p e2 )

Here e is a non-terminal de ned above, and identi er is a token representing all
variable names. The other terminals are simply keywords or separators. Again all
productions at the same line have the same precedence, and productions listed at ear-
lier lines have higher precedence than those listed at later lines. Example statements
include if (a < b) then a else b let val a : int ref = ref 1 in a:=3; !a+b end; while
(!a < b) do a := !a + 1; val a : real ref = ref 2.0 ;

Doing a project of the above:

total 152
-rw-r----- 1 skhan3 skhan3 166 Feb 28 14:13 proj.l
-rw-r----- 1 skhan3 skhan3 21 Feb 28 14:13 test.inp
-rw-r----- 1 skhan3 skhan3 206 Feb 28 14:13 proj.y
-rw-r----- 1 skhan3 skhan3 219 Feb 28 14:13 Makefile
-rw-r----- 1 skhan3 skhan3 549 Feb 28 14:13 driver.c
-rw-r----- 1 skhan3 skhan3 21 Feb 28 14:19 test2.inp
-rw-rw---- 1 skhan3 skhan3 45700 Feb 28 15:24 lex.yy.c
-rw-rw---- 1 skhan3 skhan3 1426 Feb 28 15:24 proj.output
-rw-rw---- 1 skhan3 skhan3 42570 Feb 28 15:24 proj.tab.c
-rwxrwx--- 1 skhan3 skhan3 28953 Feb 28 15:24 proj

Please point out the changes in the right files.

Thanks you !!!

==========================================================================

Extend the above parser to support function definitions and function
calls. In particular, the non-terminal d at level 2 needs to be extended to support the
syntax of a function declaration defined as
fd ::= fun id ( x1 : t1, ..., xm : tm) : t = e2
In particular each function declaration starts with the fun keyword, followed by the
name of the function and a tuple of variables, each of the form name : type to de ne a
parameter of the function. Finally, the : t notations declares the type of the function
return value, and it is followed by an equal operator and then a single expression which
is the body of the function. An example function declaration could be fun rst(y :
int list) : int = hd(y).
Further, the expression non-terminal e needs to be extended to support the syntax
of a function call, in the format of e1(e2,...,en), where each e1, e2,...,en is a single
expression or a tuple of expressions separated by `,': e.g., foo(a) and gcd(a,b).

This is again the second part of the above project.

Please points out changes in the right files.

-rw-r----- 1 skhan3 skhan3 166 Feb 28 14:13 proj.l
-rw-r----- 1 skhan3 skhan3 21 Feb 28 14:13 test.inp
-rw-r----- 1 skhan3 skhan3 206 Feb 28 14:13 proj.y
-rw-r----- 1 skhan3 skhan3 219 Feb 28 14:13 Makefile
-rw-r----- 1 skhan3 skhan3 549 Feb 28 14:13 driver.c
-rw-r----- 1 skhan3 skhan3 21 Feb 28 14:19 test2.inp
-rw-rw---- 1 skhan3 skhan3 45700 Feb 28 15:24 lex.yy.c
-rw-rw---- 1 skhan3 skhan3 1426 Feb 28 15:24 proj.output
-rw-rw---- 1 skhan3 skhan3 42570 Feb 28 15:24 proj.tab.c
-rwxrwx--- 1 skhan3 skhan3 28953 Feb 28 15:24 proj

Thanks you !!!

Explanation / Answer

p ::= epsilon | p s
c ::= c ; d | d
s ::= e2 ; | d ; | while e do s
d ::= val identifier : t = e2
t ::= int | real | unit | bool

t ref | t list
| t list
| t * t
e2 ::= e
| e := e2
| let c in p e2 end
| if e then e2 else e2
| ( p e2 )

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote