Answered step by step
Verified Expert Solution
Link Copied!

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 =3;
b = a +1;
class A {
String name = "sara";
class Nested {
if (b ==4) a =2; endif
if (a ==3)
a = a +1;
b = b +6;
endif
print a;
print b;
print name;
{{{{print "Last Block"; }}}}
}
}
class B {
int x;
int getDubX(){
return 2*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 ANTLR4 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: [a-zA-Z]+ ; // match identifiers
INT: [0-9]+ ; // match integers
NEWLINE: '\r'?'
' ; // return newlines to parser
WS: [\t]+-> skip; // toss out whitespace
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 3 Lnai 6323

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

3642159389, 978-3642159381

More Books

Students also viewed these Databases questions

Question

Identify conflict triggers in yourself and others

Answered: 1 week ago