程序代做 COP5556-7863(12397) – Program Language

COP5556-7863(12397) – Program Language
Provided Code
ILexer.java Interface for the Lexer itself, your
lexer class should implement this interface

Copyright By PowCoder代写 加微信 powcoder

Token.java Interface for the Tokens, your token
class should implement this interface. Also, the
enum Kind, which distinguishes the different
tokens is defined in this interface. When
determining the position of a token in the input
source code, start counting both lines and
columns at 1.
CompilerComponent Factory.java Factory class
to provide instantiations of your lexer. You will
need to modify a line or two in this class.
PLCException.java The superclass of all the
Exceptions that we will throw in the compiler
LexicalException.java The Exception that should
be thrown for all errors in the input that are
discovered during lexing.
LexerTests.java Example Junit tests. This class
will be expanded with additional tests and used
for grading so it is essential that your code runs
with this code and passes these tests. The
examples also demonstrate how to write tests,
including tests where an exception is expected
You may (and should!) add additional tests to this
class; your version will not be graded.
For you to develop:
A class (or classes) that implements the IToken
interface and represents tokens.

For you to develop:
A class (or classes) that implements the IToken
interface and represents tokens.
A class that implements the ILexer interface and
tokenizes its input according to the given lexical
structure.
o repeatedly invoking next() should return all
of the tokens in order. After all the tokens
have been returned, subsequent calls
should return a token with kind EOF.
o If an error is discovered, throw a
LexicalException. The error message will
not be graded but you will appreciate it
later if your error messages are
informative.
o You may implement your lexer so that it
generates tokens on demand, or you may
compute all the tokens first and then return
them when requested. If you choose the
latter approach, make sure that no
exceptions are thrown until the error
occurs. (For example, if the input is “123
@” the first call to next should return a
NUM_LIT token with 123. The second call
should throw an exception.) The ERROR
kind may be useful for managing
exceptions, it is not required to be used and
no Tokens with kind ERROR should ever
be returned from next() or peek().
Modify CompilerComponentFactory.java so that
its getLexer method returns an instance of your

Lexical Structure
«token> == sident> | | «string lit> I. 1.1: | (1)| +1-|*|/|% (updated 9/6 3pm)
|?!|:=|=1#|<|<-|>|>= | «reserved>
:= (a*| A.ZI_ IS ) (a2| A.ZI I$|0.9 )* but not
:= 0 | (1. 9) (0. 9)*
‹string lit> I=
(updated 9/3 10:21 am)
#= | |
-= TRUE I FALSE
«keywords> == CONST | VAR | PROCEDURE | CALL | BEGIN | END
TIF I THEN I WHILE I DO
«comment> == // (NOT(Tv)* ((Ar’le) in) EOF
In the above (borrowing Java notation) . In’ represents the LF or NL ascii control character. Tr
represents the CR ascii control character. Depending on the platform, a line will end with either
In’ or ‘l’ln’. This does not matter for recognizing tokens, but does matter for the token’s line
number in the source code.
You mav assume that a r’ without a following \n’ will not occur in your input. Therefore a
comment starts with //, and ends with either r’In’. In’, or the end of the input. EOF means the
end of the input.
== (ht/vr|\)+
In the definition of white space, the alternatives are (borrowing Java notation again): space, tab,
and «comment> serve to separate tokens, but are otherwise ignored

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com