Question: ITCS 3 1 7 Term Project Building a Context - Free Grammar Parser for a Programming Language Due: 7 Dec 2 0 2 4 Logo

ITCS317 Term Project
Building a Context-Free Grammar Parser for a Programming Language
Due: 7 Dec 2024
Logo is a simple programming language that was created to help children learn
programming in the 1970s and 1980s
The language assumes that there is a drawing area on the screen (see Figure 1 right
panel), and a turtle which starts at the center of the screen. The programmer then
enters a set of commands for the turtle to move on this drawing area. The
movements of the turtle leave lines on the screen, and thus create a drawing. The
language has simple programming structures for repetition (i.e. loops), conditional
(i.e. if statements), as well as instructions which control the pen (or turtle).
A sample Logo program might look like this. This program draws a square which is
100 high by 100 pixels wide.
repeat 4{
forward 100;
turn right 90;
};
The following is a probable grammar for a simple version of the Logo programming
language.
The terminals in this grammar are shown in bold (Courier New). Note that NUM
denotes any nonnegative integer number (i.e.0), and ID denotes any identifier
which starts with a letter from the alphabet followed by any sequence of letters or digits. NUM can be denoted by the regular expression (0+1+2+3+4+5+6+7+8+9)+. ID
can be denoted by (a... z +A...Z)+(a...z+A...Z+0...9)*.
Also note that the language is not case sensitive, and that it is free-form so you
should ignore any whitespace in the program
program statement_list
statement_list statement |statement statement_list
statement forward expression;
| backward expression;
| turn right expression;
| turn left expression;
| while expression { statement_list };
| for ID = expression to expression step NUM
{ statement_list };
| pen on;
| pen off;
| color expression;
| assignment;
assignment ID = base
base ID | NUM |- NUM | expression
expression term
expression term addOp term
term factor
term term multOp factor
factor base
addOp +|-
multOp *|/|^
Problem:
Use ANTLR to construct the lexical analyzer and parser for the grammar
given above. Then test the ANTLR code on some input with and without syntax
errors. An IDE is available for ANTLR and is called ANTLRWORKS. The IDE has an editor and can show you errors and syntax trees in a separate window. Download ANTLR+ANTLRWORKS version 3. It is a standalone Java archive that you can use for this project. You can modify the grammar above if it will work better or to eliminate any problems as long as you
keep the language accepted by the grammar the same. Your final project developed by you should be tested by inputing a code in the Logo language given above and it should inform the user whether it contains syntax errors
or not. A syntax tree should be the output for valid programs, and you can view it through ANTLRWorks GUI.
Submit the file grammar.g file after testing it on Blackboard with screenshots of the
parsing trees for an accepted case and another for the syntax error case.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!