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
ITCS Term Project
Building a ContextFree Grammar Parser for a Programming Language
Due: Dec
Logo is a simple programming language that was created to help children learn
programming in the s and s
The language assumes that there is a drawing area on the screen see Figure 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 ie loops conditional
ie 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
high by pixels wide.
repeat
forward ;
turn right ;
;
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 ie 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 ID
can be denoted by a z AZazAZ
Also note that the language is not case sensitive and that it is freeform so you
should ignore any whitespace in the program
program statementlist
statementlist statement statement statementlist
statement forward expression;
backward expression;
turn right expression;
turn left expression;
while expression statementlist ;
for ID expression to expression step NUM
statementlist ;
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 ANTLRANTLRWORKS version 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
