Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are given the following KangarooCode.txt file int a; int b; a = 3 ; b = a + 1 ; class A { String
You are given the following KangarooCode.txt file
int a;
int b;
a ;
b a ;
class A
String name "sara";
class Nested
if b a ; endif
if a
a a ;
b b ;
endif
print a;
print b;
print name;
print "Last Block";
class B
int x;
int getDubX
return x;
This file has a sample code for a new
programming Language. The code includes implementation to complete some mathematical calculation using a
particular programming syntax structure.
Please write a Grammar using ANTLR for parsing the code and its tokens. YOUR GRAMMAR MUST PRODUCE THE SAME PARSE TREE LIKE THE ONE IN THE PICTURE.
Here is an example of ANTLR grammar:
grammar Expr;
Parser rules
The start rule; begin parsing here.
prog: stat ;
stat:
expr NEWLINE
ID expr NEWLINE
NEWLINE
;
expr:
expr expr
expr expr
INT
ID
expr
;
Tokens Rules
ID: azAZ ; match identifiers
INT: ; match integers
NEWLINE: r
; return newlines to parser
WS: t skip; toss out whitespace
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started