Question: I really need help with number 13. Below is my scanner.l file and my tokens.h file, it will not compile the way it needs to.

CMSC 430 Project 1 The first project involves modifying the attached lexicalanalyzer and the compilation listing generator code. You need to make the


I really need help with number 13. Below is my scanner.l file and my tokens.h file, it will not compile the way it needs to. I need to know how to format it in my scanner.l file under char_literals.

 

scanner.l

%{
#include
#include

using namespace std;

#include "listing.h"
#include "tokens.h"

%}

%option noyywrap

ws              [ \t\r]+
comment         \-\-.*\n
secondcomment   "--[^\n]*\n"
line            [\n]
id              [A-Za-z](_?[A-Za-z0-9])*
digit           [0-9]
hex             #{digit}+|[0-9a-fA-F]+
int             {digit}+
char_literal    '\\'(b|t|n|r|f|\\\\|\\'.)*'\\'
punc            [\(\),:;]

real            {digit}+(\.{digit}+)?([eE][+-]?{digit}+)?


%%

{ws}            { ECHO; }
{comment}       { ECHO; nextLine(); }
{secondcomment} { ECHO; nextLine(); }
{line}          { ECHO; nextLine(); }

"\|"            { ECHO; return(OROP); }
"!"             { ECHO; return(NOTOP); }
"-"             { ECHO; return(ADDOP); }
"/"             { ECHO; return(MULOP); }
"=>"            { ECHO; return(ARROW); }
"="             { ECHO; return(RELOP); }
"|>=|">"             { ECHO; return(RELOP); }
">="            { ECHO; return(RELOP); }
""^"             { ECHO; return(EXPOP); }
"~"             { ECHO; return(NEGOP); }
"%"             { ECHO; return(REMOP); }
"+"             { ECHO; return(ADDOP); }
"*"             { ECHO; return(MULOP); }
"&"             { ECHO; return(ANDOP); }
"begin           { ECHO; return(BEGIN_); }
case            { ECHO; return(CASE); }
character       { ECHO; return(CHARACTER); }
end             { ECHO; return(END); }
endswitch       { ECHO; return(ENDSWITCH); }
function        { ECHO; return(FUNCTION); }
integer         { ECHO; return(INTEGER); }
is              { ECHO; return(IS); }
list            { ECHO; return(LIST); }
of              { ECHO; return(OF); }
others          { ECHO; return(OTHERS); }
returns         { ECHO; return(RETURNS); }
switch          { ECHO; return(SWITCH); }
when            { ECHO; return(WHEN); }
else            { ECHO; return(ELSE); }
elsif           { ECHO; return(ELSIF); }
endfold         { ECHO; return(ENDFOLD); }
endif           { ECHO; return(ENDIF); }
fold            { ECHO; return(FOLD); }
if              { ECHO; return(IF); }
left            { ECHO; return(LEFT); }
real            { ECHO; return(REAL); }
right           { ECHO; return(RIGHT); }
then            { ECHO; return(THEN); }

{id}            { ECHO; return(IDENTIFIER); }
{hex}   { ECHO; return(INT_LITERAL); }
{real}          { ECHO; return(REAL_LITERAL); }
{char_literal}          { ECHO; return(CHAR_LITERAL); }
{punc}          { ECHO; return(yytext[0]); }
.               { ECHO; appendError(LEXICAL, yytext); }
%%

int main()
{
   firstLine();
   
   FILE *file = fopen("lexemes.txt", "wa");
   int token = yylex();    
   while (token)
   {
       fprintf(file, "%d %s\n", token, yytext);
       token = yylex();
   }
   lastLine();
   fclose(file);
   return 0;
}

token.h

 

#ifndef TOKENS_H

#define TOKENS_H


 

enum Tokens {

    ADDOP = 256,

    MULOP,

    ANDOP,

    RELOP,

    ARROW,

    BEGIN_,

    CASE,

    CHARACTER,

    END,

    ENDFOLD,  // Added for 'endfold'

    ENDIF,    // Added for 'endif'

    ELSE,     // Added for 'else'

    ELSIF,    // Added for 'elsif'

    FOLD,     // Added for 'fold'

    IF,       // Added for 'if'

    LEFT,

    REAL,

    RIGHT,

    THEN,     //Added for 'then'

    OROP,     //Added for '|'

    NOTOP,    //Added for '!'

    REMOP,    //Added for '%'

    EXPOP,    //Added for '^'

    NEGOP,    //Added for '~'

    IDENTIFIER,

    INT_LITERAL,

    HEX_INT,       //Added for hexadecimal integers

    REAL_LITERAL,  //Added for real literals

    CHAR_LITERAL,  //Added for char literals

    ENDSWITCH,

    FUNCTION,

    INTEGER,

    IS,

    LIST,

    OF,

    OTHERS,

    RETURNS,

    SWITCH,

    WHEN

};


 

#endif

CMSC 430 Project 1 The first project involves modifying the attached lexical analyzer and the compilation listing generator code. You need to make the following modifications to the lexical analyzer, scanner.1: 1. The following reserved words should be added: else, elsif, endfold, endif, fold, if, left, real, right, then Each reserved words should be a separate token. The token name should be the same as the lexeme, but in all upper case. 2. Two additional logical operators should be added. The lexeme for the first should be and its token should be CROP. The second logical operator added should be and its token should be NOTOP. 3. Five relational operators should be added. They are =, , >,>= and

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithms Questions!

Q:

IL