Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

urgent help with C++ code i will up vote!!!! In this programming assignment, you will be building a lexical anatyee for small jeogranining tanguage called

urgent help with C++ code i will up vote!!!!
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
In this programming assignment, you will be building a lexical anatyee for small jeogranining tanguage called Simpeo Pirl Lhe isphi, and a program to test. it This assignment wil be followed by two other assignments to build a panser and an intergreter to the SPL lunguge Although. we are not concemed about the syntax definitions of the language in this assignent, we intend to initroduce it ahead of Progamining Avigrnent 2 in arder to detemine ther. language tempinals reserved words, constants, identifierls), and operators. The syntax definitions of the SPL language are given below using EBNF notations. However, the details of the meaninge (i.e, semantics) of the language constructs will be given later on. 1. Prog sin Stmitist 2. Stmitist := Stint Stint 3. Stmit st- AssignStme | Writelinstmt | 1istmit. 4. WritelnStmt =- WRITELN (ExprList) 5. IIStrnt = IF (Expr) 'T Stmtuist '' [ ELSE T StmtList 'Y' ] 6. Assignstmt : = Var = Expr 7. Var Me- NIDENT I SIDENT 8. ExprList :- Expr [, Expr] 9. Expr :in RelExpr (ceeql=-t) RelExpr ) 10. RelExpr:=: AddExpr [ (tgt) AddExpr ] 11. AddExpr = MultExpr (1+11 ) MultExpr ) 12. Multexpr = ExponExpr (()/) ExponExpr } 13. ExponExpr = - UnaryExpr (^ UnaryExpr) 14. UnaryExpr:= (11+)) PrimaryExpr 15. PrimaryExpr = IDENT / SIDENT / NIDENT / ICONST / RCONST / SCONST / (Expr) For details of the assignment description and requirements see the programming assignment statement and the class slides. lex.h CS280 * Spring 2023 *) \#ifndef LEX_H_ \#define LEX_H \#include \#include \#include 1/ keywords WRITELN, IF, ELSE, If an identifiers IDENT, NIDENT, SIDENT, II an integer, real, and string constant ICONST, RCONST, SCONST, II the numeric operators, assignment, parens, braces, numeric and string comparison operators PLUS, MINUS, MULT, DIV, EXPONENT, ASSOP, LPAREN, RPAREN, LBRACES, RBRACES, NGTHAN, NLTHAN, CAT, SREPEAT, SEQ, SLTHAN, SGTHAN, COMMA, SEMICOL, II any error returns this token ERR, DONE, I/ when completed (EOF), return this token \}i //Class definition of Lexitem class Lexitem \{ Token token; string lexeme; int lnum; public: Lexitem() \{ token = ERR; \} lnum =1 LexItem(Token token, string lexeme, int line) \{ this->oken = token; this lexeme = lexeme; \} this lnum = line; bool operator = (const Token token) const \{ return this > token = token; \} bool operator 1= (const Token token) const \{ return this->token 1= token; ; } ) Token GetToken() const \{return token; \} string GetLexeme() const \{ return lexeme; int GetLinenum() const \{return lnum; \} extern ostream\& operator (ostream\& out, const Lexiteme tok); extern Lexitem id or kw(const stringe lexeme, int linenum); extern Lexitem getNextToken(istreame in, inte Lnenum); allflags x+ Edit View NIDENT (\$r) ASSOP ICONST (50) SEMICOL SIDENT (Gflag) ASSOP SCONST (true) SEMICOL IDENT (if) L.PAREN SIDENT (GElag) MINUS IDENT ( seq ) SCONST (true) RPAREN LBRACES NIDENT (\$y 1) ASSOP SEMICOL RBRACES IDENT (Else) LBRACES NIDENT ($y,1) ASSOP RCONSTLPAREN(7.5) RPAREN SEMICOL RBRACES IDEar (writeln) sconst (value = ) cowmA conmA NIDE Corve corens copen ntoker (sy_-1) staricor ilisesing Totil rtemp 10 RPAREN SEMICOL RBRACES IDENT (writeln) SCONST (Value = ) COMMA NIDENT ($r) COMMA SCONST ($y1=) COMMA NIDENT ($Y1) SEMICOL Lines: 9 Total Tokens: 39 Identifiers: 9 Numbers: 3 Strings: 3 IDENTIFIERS: $Y_1,$r,$y_1,@Flag,@flag,Else, if, seq, writeln NUMBERS: 5 7.5 50 STRINGS: \$\$y_1 =. 'Value =. 'true' UNRECOGNIZED FLAG {-hello } CANNOT OPEN THE FILE cantopen Lines: 0 Empty File. IDENT (PROGRAM) IDENT (progi) NIOENT ( $1) CATASSOP Iconst (5) SEMICOL SIOENT (Ay y ) SEMICOL. STDENT (str) SCSOP CAT SIDENT (eyi) SEMICOL IDtur (float) IDENT (2) RCOnsTASsop(6.8) compe Compen IDLHT ( 45) COMMA IorNT (r25) Assop HCOMSAS50P(50) semicot IOENT ( FiO) Lines: 1e Total tokens: 28 Identifiers: 11 Nambers: 3 iotanes: 1 atrifis: SCONST(Please type the "coordinates" of three points) SCONST (The center of the circle through these points is) SCONST(Its radius is) Lines: 6 Total Tokens: 3 Identifiers: Numbers: 0 Strings: 3 STRINGS: 'Its radius is ' "Please type the "coordinates" of three points' 'The center of the circle through these points is' plus: welt DIV DIY Mrwis MINIS EXPONENT EXPONENT EXPONENT NEQ SREPEAT SEQ SLTHAN SGTHAN SEQ SLTHAN SGTHAN SGTHAN Lines: 9 Total Tokens: 22 Identifiers: Numbers: Strings

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

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago