Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please can you write the code in c++.If possible use and IDE to run it.Thank you. CS 280 Fall 2020 Programming Assignment 1 February 22,
please can you write the code in c++.If possible use and IDE to run it.Thank you.
CS 280 Fall 2020 Programming Assignment 1 February 22, 2021 Due Date: Wednesday, March 10, 2021, 23:59 Total Points: 20 In this programming assignment, you will be building a lexical analyzer for small programming language and a program to test it. This assignment will be followed by two other assignments to build a parser and interpreter to the same language. Although, we are not concerned about the syntax definitions of the language in this assignment, we intend to introduce it ahead of Programming Assignment 2 in order to show the language reserved words, constants, and operators. The syntax definitions of a Fortran-Like small programming language are given below using EBNF notations. The details of the meanings (i.e. semantics) of the language constructs will be given later on. Prog - PROGRAM IDENT (Decl) Stmt) END PROGRAM IDENT Decl Type : VarList Type = INTEGER | REAL CHAR Vartist - Var (Var) Stmt - Assigstmt | TfStmt | Print Stmt ReadStmt PrintStnt :- PRINT , Exprlist IfStmt = IF (LogicExpr) THEN (Stmt) END IF Assign Stmt Var - Expr ReadStmt = READ Varlist ExprList - Expr t Expr) Expr - Term {{+1-) Term) Term - SFactor (17) SFactor! SFactor - Sign Factor | Factor LogicExpr Expr ( 1 ) Expr Var - IDENT Sign- + 1 - Factor - IDENTI ICONST | RCONST I SCONSTI (Expr) Based on the language definitions, the lexical rules of the language and the assigned tokens to terminals are as follows: 1. The language has identifiers, referred to by ident terminal, which are defined to be a letter followed by zero or more letters or digit. It is defined as: ident :- Letter ((Letter Digit)) Letter :- [a-zA-Z] Digit :- [0-9] The token for an identifier is IDENT. as: 2. Integer constants, referred to by iconst terminal, are defined as one or more digits. It is defined iconst :- (0-9]+ The token for an integer constant is ICONST. 3. Real constants, referred to by rconst terminal, are defined as zero or more digits followed by a decimal point (dot) and one or more digits. It is defined as: Rconst :-([0-9]*)\.([0-9]+) The token for a real constant is RCONST. For example, real number constants such as 12.0 and 2 are accepted, but 2. is not. 4. String literals, referred to by sconst terminal, are defined as a sequence of characters delimited by single or double quotes, that should all appear on the same line. The assigned token for a string constant is SCONST. For example, "Hello to cs 280." Or 'Hello to cs 280.' are string literals. There are no escape characters. However, a string delimited by single quotes can have double quotes character as one of the characters of the string, and similarly a string delimited by double quotes characters can have a single quote as one of the characters of the string. For example, "welcome to smith's home" or 'welcome smith" home' are acceptable strings. to 5. The reserved words of the language are: program, end, print, read, if, then, integer, real, char. These reserved words have the following tokens, respectively: PROGRAM, END, PRINT, READ, IF, THEN, INTEGER, REAL, and CHAR. 6. The operators of the language are: +, -, ././/. =, (.), -, <. these operators are for add subract multiply divide concatenate assignment left parenthesis right equality and less than operations. they have the following tokens respectively: plus minus mult div. concat assop lparen rparen equal lthan. colon comma characters terminals with tokens: coma a comment is defined by all exclamation mark to end of line. does not overlap one recognized ignored token. white spaces skipped. however between used improve readability can be as way delimit tokens. an error will denoted err file done lexical analyzer requirements: you write function called getnexttoken driver program testing it. getnext token must signature: lexitem inte linenumber first argument reference istream object that should read from. second integer contains current line number update this every time it reads anewline from input stream returns object. class string lexeme data members. header lex.h provided you. definition enumerated type symbols use provided. may change note performs following: any detected result in returned value when was detected. also both unrecoverable. once either shouldn call again separated but most cases required be. example sequence iconst iconst. similarly world sconst sconst. . recommended implement source main test another file. takes several command flags. notations each flag follows: if present printed seen followed its parentheses. prints out unique constants numeric order real alphabetical identifiers filename passed function. your open filename. apply rules: arguments begin dash appear multiple times. only last considered. there at name specified on more print new message allowed stop running. no found running other flags permitted. unrecognized where whatever given cannot n corresponding then invalid constant message: repeatedly until or err. summary information handles flags-sconsts.- iconsts rconsts and-ids order. follows lines: l lines counting zero further printed. v option per output format capital letters lparen. case ident rconst space identifier literal center circle through points them would be: the-sconsts cause label strings itself without double quotes sconsts nothing the-iconsts integers: reals: the-ids identifiers: comma-separated list idents note: set files associated programming vocareum automatic grading based files. check implementation. available compressed archive cases.zip canvas assignment. table below. submission guidelines submit implementation vocareum. propagated work directory. submissions after due date accepted fixed penalty saturday pm march successful compilation empty integers reals keywords valid closing comments symbol matching quote overlapping two fortran-like total cs fall february date: wednesday points: building small language assignments build parser interpreter same language. although we concerned about syntax definitions intend introduce ahead show reserved words operators. below using ebnf notations. details meanings semantics constructs later on. prog stmt decl : varlist char vartist var assigstmt tfstmt readstmt printstnt :- exprlist ifstmt="IF" assign expr t term sfactor sign factor logicexpr sign- identi i sconsti rules assigned has referred terminal which letter digit. as: digit ident. digits. digits decimal point rconst. such not. literals delimited single literals. escape characters. character string. smith home acceptable strings. are: char.> Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started