Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

RCONST: ( 2 3 . 5 ) SCONST: Please type the coordinates of three points RCONST: ( 1 5 . 2 5 ) ICONST: (

RCONST: (23.5)
SCONST: "Please type the coordinates of three points"
RCONST: (15.25)
ICONST: (4321)
RCONST: (.725)
SCONST: "The center of the circle through these points is"
ICONST: (625)
Lines: 5
Total Tokens: 12
Identifiers: 0
Integers: 2
Reals: 3
Strings: 2
INTEGERS:
4321,625,
REALS:
23.5,15.25,.725,
STRINGS:
Please type the coordinates of three points, The center of the circle through these points is, This is the output i'm getting. The output i want is this:RCONST: (23.5)
SCONST: "Please type the coordinates of three points"
RCONST: (15.25)
ICONST: (125)
ICONST: (4321)
RCONST: (.725)
SCONST: "The center of the circle through these points is"
ICONST: (625)
Lines: 5
Total Tokens: 8
Identifiers: 0
Integers: 3
Reals: 3
Strings: 2
INTEGERS:
125,625,4321
REALS:
0.725,15.25,23.5
STRINGS:
"Please type the coordinates of three points", "The center of the circle through these points is" and this is the file contents: 23.5 "Please type the coordinates of three points"
15.25125
4321.725 'The center of the circle through these points is'
625 It's not reading integer 125 and it's giving me blank tokens Can you check my function.: this is my code: LexItem getNextToken(istream & in, int & linenum)
{
enum TokState{START, INID , ININT , INSTRING, INCOMMENT, REAL} ;
TokState lexstate = START ;
string lexeme;
bool escaped= false;
char ch;
Token tok= ERR;
while(in.get(ch))
{
switch(lexstate)
{
case START:
if(ch=='
')
{
linenum++;
}
if(isspace(ch))
{
continue;
}
lexeme=ch;
if(isalpha(ch)|| ch=='_')
{
lexstate=INID;
}
else if (isdigit(ch))
{
lexstate=ININT;
}
else if (ch =='.')
{
auto s = in.peek();
if (isdigit(s))
{
lexstate=REAL;
continue;
}
else
{
lexeme += s;
return LexItem(ERR, lexeme, linenum);
}
}
else if (ch =='\''|| ch =='"')
{
escaped=false;
lexstate=INSTRING;
continue;
}
else if (ch=='!' && in.peek()!=EOF && in.peek()=='!')
{
lexstate=INCOMMENT;
}
else
{
tok=ERR;
switch (ch)
{
case '+':
tok= PLUS;
break;
case '-':
tok = MINUS;
break;
case '*':
tok=MULT;
break;
case '/':
tok=DIV;
break;
case '=':
tok=ASSOP;
break;
case EQ:
if (lexeme =="==")
{
tok = EQ;
}
break;
case POW:
if (lexeme=="**")
{
tok=POW;
}
break;
case '>':
tok=GTHAN;
break;
case '<':
tok=LTHAN;
break;
case CAT:
if (lexeme=="//")
{
tok=CAT;
}
break;
case ',':
tok=COMMA;
break;
case '(':
tok=LPAREN;
if (in.peek()=='*')
{
lexstate= INCOMMENT;
continue;
}
break;
case ')':
tok= RPAREN;
break;
case '.':
tok = DOT;
break;
case DCOLON:

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

Building The Data Lakehouse

Authors: Bill Inmon ,Mary Levins ,Ranjeet Srivastava

1st Edition

1634629663, 978-1634629669

More Books

Students also viewed these Databases questions