Description
I only need Project 3, But you should work on project 1 & Project 2 to get the idea..Also attach an video showing the output and how it runs as shown exactly in the pdf. Also follow the requirements
Unformatted Attachment Preview
How to Install Antlr4
1. Install Java (version 1.19 stable subversion) [The JDK should be installed not just the
2.
3.
4.
5.
6.
7.
JRE]
Create a directory on CSIS virtual desktop called something like C:Javalib or whatever
you need to call it.
Use antlr-4.11.1-complete.jar file provided in zip file or Download antlr-4.11.1complete.jar from https://www.antlr.org/download.html and save to the directory
C:JavaLib or whatever called the directory in part 2.
Add C:JavaLib (or whatever you path chosen in part 2) to PATH environment variable
using System Properties dialog > Environment variables.
Using System Properties dialog > Environment variables > Create or append
to CLASSPATH variable: .;C:Javalibantlr-4.11.1-complete.jar;
Put (copy or move from provided zip file) the file antlr4.bat to C:JavaLib or whatever
called the directory in part 2. The file should contain the line:
java org.antlr.v4.Tool %*
Put (copy or move from provided zip file) the file a grun.bat to C:JavaLib or whatever
called the directory in part 2.The file should contain
@ECHO OFF
SET TEST_CURRENT_DIR=%CLASSPATH:.;=%
if “%TEST_CURRENT_DIR%” == “%CLASSPATH%” ( SET
CLASSPATH=.;%CLASSPATH% )
@ECHO ON
java org.antlr.v4.gui.TestRig %*
To Test installation:
Create a command line window (using cmd command) and type what is underlined: antlr4
You should see:
java org.antlr.v4.Tool
ANTLR Parser Generator Version 4.11.1
-o ___
specify output directory where all output is generated
-lib ___
specify location of grammars, tokens files
…
Check https://www.antlr.org/ for any further questions or information you may have.
CS 435 Project 1
Scanner for Simple_PL1
Overview of Assignment
Complete a “hand-written” scanner for Simple_PL1.
This project must be written in C (code files “.c” and “.h”) using Visual Studio 2022.
Simple_PL1 Lexical Specification
For definitions below: letter = [a..zA..Z] digit = [0..9].
Token Name (used
internally by compiler)
ID
READ
Regular expression
definition
WRITE
write
NUMBER
ASSIGN
PLUS
MINUS
TIMES
DIV
SEMICOLON
COMMA
LPAREN
RPAREN
SCAN_EOF
digit digit*
:=
+
*
/
;
,
(
)
(letter|_)(letter|digit|_)*
read
Lexeme examples
max, a_1, _a1,
note: read is an identifier,
but is reserved and needs
to be returned from
scanner as distinct token.
note: write is an identifier,
but is reserved and needs
to be returned from
scanner as distinct token.
1, 21, 1024
scanner returns this when
the source end-of-file is
reached.
WHAT TO SUBMIT: Name your Visual Studio 2022 solution/project:
CS435P01. After completing the project, Zip the entire
solution/project folder and test cases. Name your zip file CS435P01.
I will grade your project by running it against a collection of test files.
Example: The command line should be:
C:> CS435P01YourLastName.exe src1.txt
See the example shown below illustrating the input – output relationship.
Project 1 Scanner for Simple_PL1
Page 1 of 5
x := 3;
y := 4;
read(x);
z1 := x + y;
write( x, y, z1,x*y/2-23 );
⇒
ID, x
ASSIGN
NUMBER, 3
SEMICOLON
ID, y
ASSIGN
NUMBER, 4
SEMICOLON
READ
LPAREN
ID, x
RPAREN
SEMICOLON
ID, z1
ASSIGN
ID, x
PLUS
ID, y
SEMICOLON
WRITE
LPAREN
ID, x
COMMA
ID, y
COMMA
ID, z1
COMMA
ID, x
TIMES
ID, y
DIV
NUMBER, 2
MINUS
NUMBER, 23
RPAREN
SEMICOLON
TO DO: Write a driver program to test your scanner. You must use the command-line
parameters to access the source file, i.e. argv[1]. Open the source file, read it and
output all tokens on separate lines. For identifiers and numbers, you must also output
the lexeme as shown above in the example.
You must use the internal names for tokens shown above in your scanner. That is, the
scanner should return these names to your driver program. For the purpose of testing
the scanner, you’ll need a corresponding array of strings that represent the internal
Token name. You’ll also need a lexeme char array (c-string).
Although it is poor programming practice to use global variables, for this project, you
will be allowed to use global variables current_token and lexeme. You can also use the
src file pointer variable as a global, so you don’t have to pass that as a parameter to
the scanner.
Shown below is some starting code.
Project 1 Scanner for Simple_PL1
Page 2 of 5
Outline of Scanner and Driver for testing the Scanner. Written in C.
//starter code for Simple_PL1 scanner
#include //for c I/o
#include // for exit()
#include // for isalpha(), isalnum(), …
enum tokenType {
READ, WRITE, ID, NUMBER, LPAREN, RPAREN, SEMICOLON, COMMA, ASSIGN, PLUS, MINUS, TIMES, DIV, SCAN_EOF
};
char *mnemonic[] = { “READ”, “WRITE”, “ID”, “NUMBER”, “LPAREN”, “RPAREN”, “SEMICOLON”, “COMMA”,
“ASSIGN”, “PLUS”, “MINUS”, “TIMES”, “DIV”, “SCAN_EOF”};
void lexical_error(char ch)
{
fprintf(stderr, “Lexical Error. Unexpected character: %c.n”, ch);
}
char lexeme[256] = { ‘