[SOLVED] 代写 C++ game compiler General Description:

30 $

File Name: 代写_C++_game_compiler_General_Description:.zip
File Size: 423.9 KB

SKU: 9761255971 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


General Description:
CS 441G – Fall 2019 Project 1.2
Version 1: 10/4/2019
This project is to implement the Lexemizer of the compiler. It’s primary purpose is to Get The Next Lexeme from the source file.
Specifications:
Complete the following class by completing the methods as described. You may add other private methods as needed.
class scanner {
public:
intopen(string source);
string getNextLexeme();
string getError();
bool isError();
private:// suggested, but not required
string error = “”;
bool is_error = false;
intlineNo = 1;
ifstream f;
};
open():
given:
returns: 1 for successful opening of the file, 0 for failure.
Opens the given file name for reading character by character. It may do any other preparatory steps needed for your implementation. Upon success, it should return 1; on failure, it should set the error to “Unable to open source
” and return 0.
getError(): returns the error member. The message should include the Line Number. isError(): returns true = an error has been detected; false = an error has NOT been detected
getNextLexeme():
returns: the next lexeme, or empty string (“”) on error or end of file (no more lexemes)
The function must implement an FSA with a Look Ahead of 1:
state = START
while (not Error and not Halt) {
c = read next char
state = transitionToNextState(state, c, lookAhead)
consume c (perform what ever action is needed with the char)
}
A main() program will be provided for testing.
the name of the source file

FSA Diagram:
A complete FSA is provided on the course website. This is basically the answer to Homework 1, except some new restrictions have been added:
– There is only one HALT state; reaching this state indicates “successful end of Lexeme”
– There is an ERR (Error) state; reaching this state indicates “game over”
Error Messages: values returned by the getError() method.
All error messages should have two lines, in the following format:
SCAN ERROR::methodName Line=nn Character=’c’(aaa)
error message
where
– methodName is the name of the method that detected the error
– nn is the line number of the source file where the error was found (first line = line 1)
– c is the character where the error was found, or UNPRINTABLE when (ascii <= 32 || asci >=127)
– aaa is the ASCII Code of c int asci = (int)c
– error message is the particular error message
General error messages:
– Unable to open input file. [in the open() method]
– Invalid character found in source. [probably in a categorizeChar() method]
FSA error messages:
STATE
CHAR_CAT
Message
START
RBRACE “}”
Beginning of comment expected.
START
any other
Invalid beginning of lexeme.
CMNT
eofl
End of comment expected.
SLIT
eol
End of line found in string literal.
SLIT
eofn
End of file found in string literal.
SLIT
other
STATE=SLIT No transition from state found. [should never occur]
SLITQ
any
Single quote expected. [should never occur]
DECPT
any except #
Digit expected. [should never occur]
none of
the above
Unknown error for STATE=state. [should never occur]
If you find other error messages that should be included, please email the instructor.
Given files:
On Multilab, found in ~kwjoiner/441/proj1.2/
– errn.pas
– pgm.pas
– jlex
– jlex.cpp
– fsa.h.txt
Test source files: errors should be found in these
Test source file: no errors
my executable.
test main(): use this as your main program; no changes
part of my fsa.h You may use these declarations, but are not required to.

Technical Issue: File Streams
You may use any file I/O functionality of C++ that you wish, as long as characters are read one at a time from the source file. Here are some items about using ifstreams:
char c, la;
ifstream f;
f.open(“sourceFileName”);
c = f.get();
if (c == -1)
doEndOfFile();
la = f.peek();
c = f.get();
f.putback(c);
// read/extract one char from file
// returns (int)-1 on End of File, no more chars to read
// retrieves but does not extract the next 1 char
// so now, la and c are the same char (la == c)
// puts the char c BACK at the front of the file stream
// however, if there is only ONE character left in the file stream:
c = f.get();
if (f.fail())
f.clear();
f.putback(c);
c = f.get();
This is an issue because:
// reads the last char and BREAKS the stream because of EOF
// the stream is broken when last char read
// “unbreaks” the stream so putback will work
// now the putback will work; without the clear(), the
// putback will not work
// reads the last char again (and breaks the stream again)
Pascal programs always end with a dot (period). If there is no whitespace or end of line after the period, the normal get()/putback() will fail on the dot, and so the last lexeme may be lost (if the clear() is not used as shown above). If there is any whitespace, eoln, comment, etc. after the final period, this would not be a problem.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 代写 C++ game compiler General Description:
30 $