Rutgers University Lexical and Syntax Project Java Coding Task
Description
If you want the pdf to the textbook in case you want even more information here it is.https://drive.google.com/file/d/1fLM3TqCVzOEizgyPL…
Post
Write an EBNF rule that describes the for statement of Java or C++. Write the recursive-descent subprogram in Java or C++ for this rule.
&
Write an EBNF rule that describes the while statement of Java or C++. Write the recursive-descent subprogram in Java or C++ for this rule.
void ifstmt(void) {if (nextToken != IF_CODE) error();else { lex();if (nextToken != LEFT_PAREN) error();else { lex();boolexpr();if (nextToken != RIGHT_PAREN)error(); else {lex();statement();if (nextToken == ELSE_CODE) {lex(); statement();}} } } }this is what the if statment looks like, (for refernce).
basic general idea of this question is.
I don’t need a very complicated or long answer, you know what i mean? It doesnt even have to be completely correct but a general ballpark.
Unformatted Attachment Preview
Pascal Programming Language (subset)
Design and implement a Lexical Analyzer for a subset of the Pascal Programming Language.
Your program should be able to accept as input a file containing statements in Pascal and
correctly perform a lexical analysis of each statement.
Samples of the output and sample C code for a lexical analyzer for tokens and lexemes can be
found in the textbook Chapter 4.2. The chapter is also screenshotted below.
1. You will need to create a list (some structure to store) of the reserved words for Pascal.
(See the link to the Pascal site).
https://www.tutorialspoint.com/pascal/pascal_basic_syntax.htm
2. You will need to create a list of various operators used in Pascal by category, for example
token ASSIGN_OP
lexeme :=
3. You will need to create a list of acceptable characters for variables and constants.
4. You will need to write code to test the validity of identifiers, If a string does not match
any of the categories, you should indicate that as UNKNOWN.
I will post the ámple code&ile you can use to test your Lexical Analyzer.
Sample Code
PROGRAM ChangeMaker;
(* Make change for a dollar *)
VAR
Cost: INTEGER;
Remainder: INTEGER;
Quarters: INTEGER;
Nickels: INTEGER;
Pennies: INTEGER;
Dimes: INTEGER;
BEGIN
(* Input the Cost *)
Write(‘Enter the cost in cents: ‘);
Read(Cost);
(* Make the Change *)
Remainder := 100 – Cost;
Quarters := Remainder DIV 25;
Remainder := Remainder MOD 25;
Dimes := Remainder DIV 10;
Remainder := Remainder MOD 10;
Nickels := Remainder DIV 5;
Remainder := Remainder MOD 5;
Pennies := Remainder;
(* Output the coin count *)
Writeln(‘The change is ‘);
WriteLn(Quarters: 2, ‘ quarters’);
WriteLn(Dimes: 2, ‘ dimes’);
WriteLn(Nickels: 2, ‘ nickels’);
WriteLn(Pennies: 2, ‘ pennies’);
END. (* ChangeMaker *)
Chapter 4.2: Concepts of Programming Languages
Purchase answer to see full
attachment
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."