id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
8a205076-e777-47b6-81dc-2fc03c22b07e
|
public void statementList(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//statementList-> statement statementList | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("{") || token.name.equals("(") || token.name.equals("if") || token.name.equals("while") || token.name.equals("return") || token.type.equals("ID") || token.type.equals("int") || token.type.equals("float") || token.name.equals(";"))
{
statement(x,y);
statementList(x,y);
}
}
}
|
85a4e5ac-45b2-4a3f-9c6e-b3074a5183dc
|
public void statement(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//statement-> expressionSt | compound | selectionSt | iterationSt | returns
// ( || { || if || while || return
if(!x.isEmpty())
{
imAtoken token = x.peek();
if (token.name.equals("(") || token.type.equals("int") || token.type.equals("float") || token.type.equals("ID") || token.type.equals(";"))
{
expressionSt(x,y);
}
else if (token.name.equals("{"))
{
compound(x,y);
}
else if (token.name.equals("if"))
{
selectionSt(x,y);
}
else if (token.name.equals("while"))
{
iterationSt(x, y);
}
else if (token.name.equals("return"))
{
returnSt(x,y);
}
}
}
|
2ad9c16c-0b4a-4399-93a3-dc0bd1cf65b7
|
public void param(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
// param-> typeSpec ID paramType
typeSpec(x,y);
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.type.equals("ID"))
{
for(int i = decList.size() - 1; i > 0; i--)
{
if(decList.get(i).lookUp(i).ID.equals(token.name))
{
ptype.add(decList.get(i).lookUp(i).type);
System.out.println("variable " + token.name + " has been defined before");
}
else if (i == 0)
{
System.out.println("variable " + token.name + " is not defined");
System.exit(0);
}
}
x.pop();
paramType(x,y);
}
}
}
|
e0db0e89-297a-4ef8-bd84-bbe9416fac59
|
public void paramType(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//paramType-> [ ] | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("["))
{
x.pop();
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals("]"))
{
x.pop();
}
else
{
System.out.println("Error11: expected \"]\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.print("Error: Out of Tokens");
System.exit(0);
}
}
}
}
|
eeac26b5-63f6-43b3-b7e7-d2d568670d76
|
public void parLoop(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//parLoop-> , param parLoop | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals(","))
{
x.pop();
param(x,y);
parLoop(x,y);
}
}
}
|
9737b692-24da-46bd-b668-391ffdc10d5b
|
public void parameter(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//parameter-> ID paramtype parLoop | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.type.equals("ID"))
{
for(int i = decList.size() - 1; i > 0; i--)
{
for(int v = 0; v < decList.get(i).stacker.size()-1; v++)
{
if (decList.get(i).lookUp(v).ID.equals(token.name))
{
ptype.add(decList.get(i).lookUp(i).type);
System.out.println("Variable " + token.name + " has been defined before");
}
else if (i == 0)
{
System.out.println("variable " + token.name + " is not defined");
System.exit(0);
}
}
}
x.pop();
paramType(x,y);
parLoop(x,y);
}
}
}
|
f260856b-75f0-4956-8936-720b54583554
|
public void expressionSt(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//expressionSt-> expression ; | ;
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals(";"))
{
x.pop();
}
else
{
expression(x,y);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(";"))
{
x.pop();
}
else
{
System.out.println("Error12: expected \";\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error13: Out of Tokens");
System.exit(0);
}
}
}
}
|
7f641e1c-3c28-4363-bb88-35b25cf4e051
|
public void selectionSt(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//selectionSt-> if ( expression ) statement selectFollow
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("if"))
{
//deny symbol table construction
ifWhile++;
x.pop();
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals("("))
{
x.pop();
expression(x,y);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
x.pop();
statement(x,y);
selectFollow(x,y);
}
else
{
System.out.println("Error14: expected \")\" but got " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error15: out of tokens");
System.exit(0);
}
}
}
else
{
System.out.println("Error16: out of tokens");
System.exit(0);
}
}
else
{
System.out.println("Error17: expected \"if\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error18: out of tokens");
System.exit(0);
}
}
|
42309c6c-1f1c-446f-8a71-3a32bf7adefa
|
public void iterationSt(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//iterationSt-> while ( expression ) statement
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("while"))
{
//deny symbol table construction
ifWhile++;
x.pop();
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals("("))
{
x.pop();
expression(x,y);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
x.pop();
statement(x,y);
}
else
{
System.out.println("Error19: expected \")\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
}
else
{
System.out.println("Error20: expected \"(\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error21: out of tokens");
System.exit(0);
}
}
else
{
System.out.println("Error22: expected \"while\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error23: out of tokens");
System.exit(0);
}
}
|
f202f5ab-5788-4490-901b-5a38351ad2b7
|
public void returnSt(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//returnSt-> return retFollow
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("return"))
{
x.pop();
retFollow(x,y);
}
else
{
System.out.println("Error24: expected return but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error25: out of tokens");
System.exit(0);
}
}
|
7dcf71d3-fea1-456b-84e2-0d8db0e90875
|
public void expression(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//expression-> ( expression ) expFollow | NUM expFollow | ID idFollow
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("("))
{
x.pop();
expression(x,y);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
x.pop();
expFollow(x,y);
}
else
{
System.out.println("Error26: expected ) but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error27: out of tokens");
System.exit(0);
}
}
else if(token.type.equals("int") || token.type.equals("float"))
{
NUM(x,y);
expFollow(x,y);
}
else if(token.type.equals("ID"))
{
//You need to be coding here
for(int i = decList.size() - 1; i > 0; i--)
{
for(int v = 0; v < decList.get(i).stacker.size() - 1; v++)
{
if (decList.get(i).lookUp(v).ID.equals(token.name))
{
ptype.add(decList.get(i).lookUp(i).type);
System.out.println("Variable " + token.name + " has been defined before");
}
else if (i == 0)
{
System.out.println("variable " + token.name + " is not defined");
System.exit(0);
}
}
}
//capture ID for checking
FunName = token.name;
//remove token
x.pop();
idFollow(x,y);
}
else
{
System.out.println("Error: expected stuff but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
}
|
c34b2ebf-21c6-4053-9cd9-603c3f359615
|
public void selectFollow(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//selectFollow-> else statement | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("else"))
{
x.pop();
statement(x,y);
}
}
}
|
66966a33-3673-4a05-8b3a-3e03891bb5b4
|
public void retFollow(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//retFollow-> ; | expression ;
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals(";"))
{
x.pop();
}
else
{
expression(x,y);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(";"))
{
x.pop();
}
else
{
System.out.println("Error28: expected ; but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
}
}
}
|
17aacfa1-2aea-4437-80f8-459b7d591dde
|
public void expFollow(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//expFollow-> termloop addExpLoop C
termLoop(x,y);
addExpLoop(x,y);
C(x,y);
}
|
5ac9d736-7759-4ac9-94a7-a48c45465aec
|
public void termLoop(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//termLoop-> mulop factor termLoop | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("*") || token.name.equals("/"))
{
mulop(x,y);
factor(x,y);
termLoop(x,y);
}
}
}
|
feb2cc63-6966-4d58-a35e-f63cdc95390f
|
public void C(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//C-> relop addExp | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("<=") || token.name.equals("<") || token.name.equals(">") || token.name.equals(">=") || token.name.equals("==") || token.name.equals("!="))
{
relop(x,y);
addExp(x,y);
}
}
}
|
86cca781-ecb2-43d1-b751-213240834f7e
|
public void relop(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//relop-> <= | < | > | >= | == | !=
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("<=") || token.name.equals("<") || token.name.equals(">") || token.name.equals(">=") || token.name.equals("==") || token.name.equals("!="))
{
x.pop();
}
else
{
System.out.println("Error29: expected ; but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
}
|
635dbaee-d53d-4c6a-a8c5-09a9a392a0fc
|
public void addExp(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//addExp-> term addExpLoop
term(x,y);
addExpLoop(x,y);
}
|
8d620a42-5dac-48a5-883e-c5017646137d
|
public void term(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
factor(x,y);
termLoop(x,y);
}
|
4e1fd756-f994-4705-8605-6efabf32062a
|
public void addExpLoop(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//addExpLoop-> addop term addExpLoop | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("+") || token.name.equals("-"))
{
x.pop();
term(x,y);
addExpLoop(x,y);
}
}
}
|
cfeb00ee-b639-43ed-88de-d18ee15d95ec
|
public void mulop(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("*") || token.name.equals("/"))
{
x.pop();
}
else
{
System.out.println("Error: looking for * or / and found " + token + " on line " + token.line);
System.exit(0);
}
}
}
|
cb620c77-53c1-4b8e-a5b9-8961aefffab8
|
public void factor(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//factor-> (expression) | NUM | ID factorFollow
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("("))
{
x.pop();
expression(x,y);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
x.pop();
}
else
{
System.out.println("Error30: expected ; but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error31: out of tokens");
System.exit(0);
}
}
else if(token.type.equals("int") || token.type.equals("float"))
{
if(type.equals("int") || type.equals("float"))
NUM(x,y);
}
else if(token.type.equals("ID"))
{
for(int i = decList.size() - 1; i > 0; i--)
{
for(int v = 0; v < decList.get(i).stacker.size()-1; v++)
{
if (decList.get(i).lookUp(v).ID.equals(token.name))
{
ptype.add(decList.get(i).lookUp(i).type);
System.out.println("Variable " + token.name + " has been defined before");
}
else if (i == 0)
{
System.out.println("variable " + token.name + " is not defined");
System.exit(0);
}
}
}
x.pop();
factorFollow(x,y);
}
else
{
System.out.println("Error32: expected ( or an int or a float or an ID but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
}
|
9ca68866-60d3-4e70-9513-b60c7e78c97d
|
public void factorFollow(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//factorFollow-> B | ( args)
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("("))
{
x.pop();
args(x,y);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
x.pop();
}
}
}
else
{
B(x,y);
}
}
}
|
af23bec0-ad78-4c53-ad0c-6d29da41d361
|
public void idFollow(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//idFollow-> BM | ( args ) expFollow
Boolean corCall = true;
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("("))
{
x.pop();
args(x,y);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
if(functionList.size() > 1)
{
for (int i = 0; i < functionList.size() - 1; i++)
{
if (FunName.equals(functionList.get(i).name))
{
if (!ptype.equals(functionList.get(i).pType))
{
System.out.println("function " + FunName + " not defined");
System.exit(0);
}
else
{
System.out.println("function " + FunName + " successfully called");
}
}
else if (i == ptype.size() - 1)
{
System.out.println("function " + FunName + " not defined");
System.exit(0);
}
}
}
else
{
for(int r = 0; r <= 1; r++)
{
if (FunName.equals(functionList.get(r).name))
{
if (!ptype.equals(functionList.get(r).pType))
{
System.out.println("function " + FunName + " not defined");
System.exit(0);
}
else
{
System.out.println(" function " + FunName + " successfully called");
}
}
else
{
System.out.println("function " + FunName + " not defined");
System.exit(0);
}
}
}
x.pop();
expFollow(x,y);
}
else
{
System.out.println("Error33: expected ) but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error34: out of tokens");
System.exit(0);
}
}
else
{
B(x, y);
M(x, y);
}
}
}
|
e94d3f99-1806-4501-826b-563abe49dcb3
|
public void args(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//args-> argList | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if (token.name.equals("(") || token.type.equals("int") || token.type.equals("float") || token.type.equals("ID"))
{
//capture paramtype
if(token.type.equals("ID"))
{
for(int i = decList.size() - 1; i > 0; i--)
{
for(int v = 0; v < decList.get(i).stacker.size()-1; v++)
{
if (decList.get(i).lookUp(v).ID.equals(token.name))
{
ptype.add(decList.get(i).lookUp(i).type);
System.out.println("Variable " + token.name + " has been defined before");
}
else if (i == 0)
{
System.out.println("variable " + token.name + " is not defined");
System.exit(0);
}
}
}
}
else if(!token.name.equals("("))
{
ptype.add(token.type);
}
argList(x, y);
}
}
}
|
521756e4-61f9-4a69-b17d-a5dee6f43bfb
|
public void argList(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//argList-> expression argListLoop
expression(x,y);
argsListLoop(x,y);
}
|
c2af46bb-2fcc-4b92-9dae-7caf0342c3a7
|
public void argsListLoop(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//argListLoop-> , expression argListLoop | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals(","))
{
x.pop();
expression(x,y);
argsListLoop(x,y);
}
}
}
|
8b787086-0505-46fb-8c90-a15debaa24f3
|
public void B(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//B-> [ expression ] | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("["))
{
//flag variable as an array
Array = true;
for(int i = decList.size() - 1; i > 0; i--)
{
if(decList.get(i).lookUp(i).ID.equals(token.name))
{
for(int v = 0; v < decList.get(i).stacker.size()-1; v++)
{
if(decList.get(i).stacker.get(v).Array == Array && decList.get(i).stacker.get(v).ID.equals(name))
{
ptype.add(decList.get(i).lookUp(v).type);
System.out.println("variable " + name + "is secure");
}
}
}
else if (i == 0)
{
System.out.println("variable " + name + " is not defined");
System.exit(0);
}
}
x.pop();
expression(x,y);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals("]"))
{
//reset array parameter
Array = false;
x.pop();
}
else
{
System.out.println("Error35: expected ] but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error36: out of tokens");
System.exit(0);
}
}
}
}
|
aa6b8ad0-0e61-48c0-af6d-3f89b4119ff0
|
public void M(ArrayDeque<imAtoken> x, ArrayList<Functions> y)
{
//M-> = expression | expFollow
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("="))
{
//need to compare each side
x.pop();
expression(x,y);
}
else
{
expFollow(x,y);
}
}
}
|
3add08a9-758f-491a-8714-f6839df2599a
|
public ArrayList<Functions> run(ArrayDeque<imAtoken> x)
{
while(!x.isEmpty())
{
program(x);
}
return functionList;
}
|
c3bcefa5-ab7c-428c-a0eb-8b47eae48b2c
|
public void program(ArrayDeque<imAtoken> x)
{
declist(x);
}
|
0d6dda18-66d8-4792-b76f-97340cfd3a98
|
public void declist(ArrayDeque<imAtoken> x)
{
declaration(x);
decloop(x);
}
|
3293c926-926f-4a34-80af-09fb0bd7550e
|
public void declaration(ArrayDeque<imAtoken> x)
{
if(!x.isEmpty())
{
typeSpec(x);
imAtoken token = x.peek();
if(token.type.equals("ID"))
{
//Capture the declarations ID
name = token.name;
//Remove the token
x.pop();
}
else
{
System.out.println("Error1: expected an ID but got a " + token.type + " on line " + token.line);
System.exit(0);
}
decFollow(x);
}
}
|
4c5e8e89-fd44-4740-bffc-34e20f2a9de1
|
public void decloop(ArrayDeque<imAtoken> x)
{
if(!x.isEmpty())
{
imAtoken token = x.peek();
if( token.name.equals("int") || token.name.equals("void") || token.name.equals("float") )
{
declaration(x);
decloop(x);
}
}
}
|
50162086-440b-4516-b3ba-f42ecaca7aa8
|
public void typeSpec(ArrayDeque<imAtoken> x)
{
imAtoken token = x.peek();
if( token.name.equals("int") || token.name.equals("void") || token.name.equals("float") )
{
//Capture the declarations type
type = token.name;
//Remove the token from the stack
x.pop();
}
else
{
System.out.println("Error2: expected an int, void, or float but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
|
ee4cc601-8660-4ba5-8858-37674c51ae0a
|
public void decFollow(ArrayDeque<imAtoken> x)
{
//decfollow -> (params) compound | X
boolean duplicate = true;
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("("))
{
x.pop();
params(x);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
if(functionList.size() != 0)
{
//check for duplicate function
for(int t = 0; t <= (functionList.size()-1); t++)
{
if(name.equals(functionList.get(t).name))
{
for(int s = 0; s < (functionList.get(s).pType.size()-1); s++)
{
if(!ptype.get(s).equals(functionList.get(s).pType.get(s)))
{
duplicate = false;
}
}
}
else if (t == functionList.size()-1)
{
duplicate = false;
}
}
}
else
{
duplicate = false;
}
if(!duplicate)
{
//create a Function
Functions func = new Functions(name, type, ptype, pname, isAr);
//Send function to Function list
functionList.add(func);
System.out.println("function " + type + " " + name + " found");
//reset functions
name = "";
type = "";
ptype.clear();
pname.clear();
isAr = false;
}
else
{
System.out.println("error function " + type + " " + name + " already defined");
System.exit(0);
}
//remove end token
x.pop();
compound(x);
}
}
}
else if(token.name.equals(";") || token.name.equals("["))
{
X(x);
}
else
{
System.out.println("Error3: Expected \"(\" or \";\" or \"[\" but found " + token + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error: Out of Tokens");
}
}
|
c920cf44-33c2-4f63-973b-960f9140130b
|
public void params(ArrayDeque<imAtoken> x)
{
//params-> int ID paramtype parLoop | float ID paramtype parLoop | void parameter
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("int") || token.name.equals("float"))
{
//capture parameter type
ptype.add(token.name);
//remove the token
x.pop();
if(!x.isEmpty())
{
token = x.peek();
if(token.type.equals("ID"))
{
//capture param name
pname.add(token.name);
//remove the token
x.pop();
paramType(x);
parLoop(x);
}
}
else
{
System.out.println("Error: Out of Tokens");
System.exit(0);
}
}
else
{
if(token.name.equals("void"))
{
//capture parameter type
ptype.add(token.name);
pname.add("");
//remove token
x.pop();
parameter(x);
}
else
{
System.out.println("Error4: Expected int, float, or void but found " + token + " on line " + token.line);
System.exit(0);
}
}
}
}
|
3965f426-ef8e-453f-9e9b-5b943562acd9
|
public void compound(ArrayDeque<imAtoken> x)
{
//compound-> { localDecs statementList }
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("{"))
{
x.pop();
localDecs(x);
statementList(x);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals("}"))
{
x.pop();
}
else
{
System.out.println("Error5: expected \"}\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error: Out of Tokens");
System.exit(0);
}
}
else
{
System.out.println("Error6: expected \"{\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error: Out of Tokens");
}
}
|
1efacf64-2def-4a17-84dc-04681a9a6f98
|
public void X(ArrayDeque<imAtoken> x)
{
//X-> ; | [NUM] ;
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals(";"))
{
x.pop();
}
else
{
if(token.name.equals("["))
{
x.pop();
NUM(x);
token = x.peek();
if(token.name.equals("]"))
{
x.pop();
token = x.peek();
if(token.name.equals(";"))
{
x.pop();
}
else
{
System.out.println("Error7: expected \";\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error8: expected \"]\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error9: expected \"[\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
}
else
{
System.out.println("Error: out of Tokens");
}
}
|
17de6d6e-3d7f-43dc-810d-0b87b0e1acab
|
public void NUM(ArrayDeque<imAtoken> x)
{
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.type.equals("Float") || token.type.equals("Int"))
{
x.pop();
}
else
{
System.out.println("Error10: expected an Int or a Float but found a " + token.type + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error: Out of Tokens");
}
}
|
0ea885cf-640e-4928-85a2-c6bf96936988
|
public void localDecs(ArrayDeque<imAtoken> x)
{
//localDecs-> typeSpec ID X localDecs | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("int") || token.name.equals("void") || token.name.equals("float"))
{
typeSpec(x);
token = x.peek();
if(token.type.equals( "ID"))
{
x.pop();
X(x);
localDecs(x);
}
else
{
System.out.println("Error: Expected an ID found " + token + " on line " + token.line);
System.exit(0);
}
}
}
}
|
c997d541-8ffd-4199-ba52-ab0af07bef32
|
public void statementList(ArrayDeque<imAtoken> x)
{
//statementList-> statement statementList | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("{") || token.name.equals("(") || token.name.equals("if") || token.name.equals("while") || token.name.equals("return") || token.type.equals("ID") || token.type.equals("Int") || token.type.equals("Float") || token.name.equals(";"))
{
statement(x);
statementList(x);
}
}
}
|
4f21cc92-a657-4f1a-a87c-0c1bdd4ddf7b
|
public void statement(ArrayDeque<imAtoken> x)
{
//statement-> expressionSt | compound | selectionSt | iterationSt | returns
// ( || { || if || while || return
if(!x.isEmpty())
{
imAtoken token = x.peek();
if (token.name.equals("(") || token.type.equals("Int") || token.type.equals("Float") || token.type.equals("ID") || token.type.equals(";"))
{
expressionSt(x);
}
else if (token.name.equals("{"))
{
compound(x);
}
else if (token.name.equals("if"))
{
selectionSt(x);
}
else if (token.name.equals("while"))
{
iterationSt(x);
}
else if (token.name.equals("return"))
{
returnSt(x);
}
}
}
|
5cd83a87-aaa8-4b93-acfb-fdd26fe65178
|
public void param(ArrayDeque<imAtoken> x)
{
// param-> typeSpec ID paramType
typeSpec(x);
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.type.equals("ID"))
{
x.pop();
paramType(x);
}
}
}
|
a608acc5-f21a-409b-9ff4-7dd3497ef035
|
public void paramType(ArrayDeque<imAtoken> x)
{
//paramType-> [ ] | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("["))
{
//mark as array
isAr = true;
//remove token
x.pop();
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals("]"))
{
x.pop();
}
else
{
System.out.println("Error11: expected \"]\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.print("Error: Out of Tokens");
System.exit(0);
}
}
}
}
|
3bad98ca-1de9-437b-b7c7-824b2eab73c4
|
public void parLoop(ArrayDeque<imAtoken> x)
{
//parLoop-> , param parLoop | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals(","))
{
x.pop();
param(x);
parLoop(x);
}
}
}
|
cbac18b7-10c8-4868-a2ea-ae6f7c9bf08b
|
public void parameter(ArrayDeque<imAtoken> x)
{
//parameter-> ID paramtype parLoop | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.type.equals("ID"))
{
x.pop();
paramType(x);
parLoop(x);
}
}
}
|
f5a6bce1-3919-4833-be6c-ee9c0994bac6
|
public void expressionSt(ArrayDeque<imAtoken> x)
{
//expressionSt-> expression ; | ;
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals(";"))
{
x.pop();
}
else
{
expression(x);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(";"))
{
x.pop();
}
else
{
System.out.println("Error12: expected \";\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error13: Out of Tokens");
System.exit(0);
}
}
}
}
|
951a085b-7eae-43f0-b869-5915442b812a
|
public void selectionSt(ArrayDeque<imAtoken> x)
{
//selectionSt-> if ( expression ) statement selectFollow
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("if"))
{
x.pop();
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals("("))
{
x.pop();
expression(x);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
x.pop();
statement(x);
selectFollow(x);
}
else
{
System.out.println("Error14: expected \")\" but got " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error15: out of tokens");
System.exit(0);
}
}
}
else
{
System.out.println("Error16: out of tokens");
System.exit(0);
}
}
else
{
System.out.println("Error17: expected \"if\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error18: out of tokens");
System.exit(0);
}
}
|
3a1504e9-95b5-47c6-946d-b9bff278f860
|
public void iterationSt(ArrayDeque<imAtoken> x)
{
//iterationSt-> while ( expression ) statement
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("while"))
{
x.pop();
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals("("))
{
x.pop();
expression(x);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
x.pop();
statement(x);
}
else
{
System.out.println("Error19: expected \")\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
}
else
{
System.out.println("Error20: expected \"(\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error21: out of tokens");
System.exit(0);
}
}
else
{
System.out.println("Error22: expected \"while\" but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error23: out of tokens");
System.exit(0);
}
}
|
677f7b3b-fa7d-4957-bda5-0c5656e42c31
|
public void returnSt(ArrayDeque<imAtoken> x)
{
//returnSt-> return retFollow
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("return"))
{
x.pop();
retFollow(x);
}
else
{
System.out.println("Error24: expected return but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error25: out of tokens");
System.exit(0);
}
}
|
9a949293-09ca-4f5a-af3f-3a9b8be04fd0
|
public void expression(ArrayDeque<imAtoken> x)
{
//expression-> ( expression ) expFollow | NUM expFollow | ID idFollow
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("("))
{
x.pop();
expression(x);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
x.pop();
expFollow(x);
}
else
{
System.out.println("Error26: expected ) but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error27: out of tokens");
System.exit(0);
}
}
else if(token.type.equals("Int") || token.type.equals("Float"))
{
NUM(x);
expFollow(x);
}
else if(token.type.equals("ID"))
{
x.pop();
idFollow(x);
}
else
{
System.out.println("Error: expected stuff but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
}
|
d7c79982-11f6-4298-a601-1549073f6434
|
public void selectFollow(ArrayDeque<imAtoken> x)
{
//selectFollow-> else statement | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("else"))
{
x.pop();
statement(x);
}
}
}
|
88ae7442-db23-49ed-8083-4209715a6dc7
|
public void retFollow(ArrayDeque<imAtoken> x)
{
//retFollow-> ; | expression ;
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals(";"))
{
x.pop();
}
else
{
expression(x);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(";"))
{
x.pop();
}
else
{
System.out.println("Error28: expected ; but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
}
}
}
|
018bf955-dc6a-4929-9655-fab18e189579
|
public void expFollow(ArrayDeque<imAtoken> x)
{
//expFollow-> termloop addExpLoop C
termLoop(x);
addExpLoop(x);
C(x);
}
|
88819d08-01e4-4713-bc6c-40bdf46e65e9
|
public void termLoop(ArrayDeque<imAtoken> x)
{
//termLoop-> mulop factor termLoop | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("*") || token.name.equals("/"))
{
mulop(x);
factor(x);
termLoop(x);
}
}
}
|
905d7e37-9814-45d5-899f-e07886ea59a4
|
public void C(ArrayDeque<imAtoken> x)
{
//C-> relop addExp | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("<=") || token.name.equals("<") || token.name.equals(">") || token.name.equals(">=") || token.name.equals("==") || token.name.equals("!="))
{
relop(x);
addExp(x);
}
}
}
|
f962edb6-4dab-47c6-b04a-e4f2ba29bcfb
|
public void relop(ArrayDeque<imAtoken> x)
{
//relop-> <= | < | > | >= | == | !=
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("<=") || token.name.equals("<") || token.name.equals(">") || token.name.equals(">=") || token.name.equals("==") || token.name.equals("!="))
{
x.pop();
}
else
{
System.out.println("Error29: expected ; but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
}
|
b1e2c222-6b20-4b45-abaf-a26083df6d3f
|
public void addExp(ArrayDeque<imAtoken> x)
{
//addExp-> term addExpLoop
term(x);
addExpLoop(x);
}
|
9cef22d8-1610-4e82-bb5f-1762db261369
|
public void term(ArrayDeque<imAtoken> x)
{
factor(x);
termLoop(x);
}
|
57756b4d-4567-4e75-9182-6f651dca65e7
|
public void addExpLoop(ArrayDeque<imAtoken> x)
{
//addExpLoop-> addop term addExpLoop | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("+") || token.name.equals("-"))
{
x.pop();
term(x);
addExpLoop(x);
}
}
}
|
e9c71627-04ee-4961-bf7b-c51a87998ddf
|
public void mulop(ArrayDeque<imAtoken> x)
{
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("*") || token.name.equals("/"))
{
x.pop();
}
else
{
System.out.println("Error: looking for * or / and found " + token + " on line " + token.line);
System.exit(0);
}
}
}
|
29a3e49b-70b7-4f0c-953d-a18fd2b06f86
|
public void factor(ArrayDeque<imAtoken> x)
{
//factor-> (expression) | NUM | ID factorFollow
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("("))
{
x.pop();
expression(x);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
x.pop();
}
else
{
System.out.println("Error30: expected ; but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error31: out of tokens");
System.exit(0);
}
}
else if(token.type.equals("Int") || token.type.equals("Float"))
{
NUM(x);
}
else if(token.type.equals("ID"))
{
x.pop();
factorFollow(x);
}
else
{
System.out.println("Error32: expected ( or an int or a float or an ID but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
}
|
69f55dd8-55d9-483e-9487-acdda73ec407
|
public void factorFollow(ArrayDeque<imAtoken> x)
{
//factorFollow-> B | ( args)
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("("))
{
x.pop();
args(x);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
x.pop();
}
}
}
else
{
B(x);
}
}
}
|
cc179f83-afeb-493a-a20d-47bcb8b7a2a7
|
public void idFollow(ArrayDeque<imAtoken> x)
{
//idFollow-> BM | ( args ) expFollow
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("("))
{
x.pop();
args(x);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals(")"))
{
x.pop();
expFollow(x);
}
else
{
System.out.println("Error33: expected ) but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error34: out of tokens");
System.exit(0);
}
}
else
{
B(x);
M(x);
}
}
}
|
da9cd147-cc92-477f-b9c2-a5cc19672417
|
public void args(ArrayDeque<imAtoken> x)
{
//args-> argList | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if (token.name.equals("(") || token.type.equals("Int") || token.type.equals("Float") || token.type.equals("ID"))
{
argList(x);
}
}
}
|
539af822-7e84-4edc-bef3-de972bd7704c
|
public void argList(ArrayDeque<imAtoken> x)
{
//argList-> expression argListLoop
expression(x);
argsListLoop(x);
}
|
10ce47aa-eaa0-4e3f-a157-f1804b66e9f5
|
public void argsListLoop(ArrayDeque<imAtoken> x)
{
//argListLoop-> , expression argListLoop | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals(","))
{
x.pop();
expression(x);
argsListLoop(x);
}
}
}
|
f810d243-c595-4c7d-a1d9-48ebda64b528
|
public void B(ArrayDeque<imAtoken> x)
{
//B-> [ expression ] | empty
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("["))
{
x.pop();
expression(x);
if(!x.isEmpty())
{
token = x.peek();
if(token.name.equals("]"))
{
x.pop();
}
else
{
System.out.println("Error35: expected ] but found " + token.name + " on line " + token.line);
System.exit(0);
}
}
else
{
System.out.println("Error36: out of tokens");
System.exit(0);
}
}
}
}
|
8b3489e3-709d-4d5f-9f45-d914f3df9997
|
public void M(ArrayDeque<imAtoken> x)
{
//M-> = expression | expFollow
if(!x.isEmpty())
{
imAtoken token = x.peek();
if(token.name.equals("="))
{
x.pop();
expression(x);
}
else
{
expFollow(x);
}
}
}
|
33c0a88c-8646-4859-b3d1-42b5e48ed950
|
public Functions(String x, String y, ArrayList<String> pt, ArrayList<String> pn, boolean isAr)
{
name = x;
type = y;
rType = y;
if(pt.size() == 1)
{
pType.add(pt.get(0));
}
else
{
for (int i = 0; i < pt.size() - 1; i++)
{
pType.add(pt.get(i));
}
}
if(pn.size() == 1)
{
pName.add(pt.get(0));
}
else
{
for (int i = 0; i < pn.size() - 1; i++)
{
pName.add(pn.get(i));
}
}
isArray.add(isAr);
}
|
7a368f03-2e01-4c5c-b8f8-59ab4b57fb08
|
public Declaration(String x, String y, int a, boolean ray)
{
ID = x;
type = y;
arraySize = a;
Array = ray;
}
|
2c816fd0-c881-4efd-839f-6f1700f377c9
|
public SymTable ()
{
//blank slate
}
|
b9d55ba8-77dd-4c7f-a3db-d537ab966fd4
|
public Declaration lookUp(int x)
{
Declaration dec = stacker.get(x);
return dec;
}
|
1b6ebd67-a18c-4324-879e-1aaca9b8c353
|
public void insert(Declaration x)
{
stacker.add(x);
}
|
65dc1228-606b-47f8-879c-1e533db336a6
|
public void delete()
{
}
|
733533ae-a6a7-4aaa-9402-c36b650dad61
|
public ArrayDeque<imAtoken> run(String[] args)
{
File file = new File("C:\\Users\\Drivenwanderer\\Documents\\GitHub\\LexAn\\src\\t1");
try
{
//File file = new File(args[0]);
Scanner scanner = new Scanner(file); //File Scanner
while (scanner.hasNextLine()) //until we reach the end of the file...
{
lineNum++; //Increment Line Number
String Test = scanner.nextLine(); //Scan selected Line in
for(int i = 0; i < Test.length(); i++)
{
notDim = false; //reset Delimiter flag
if((i+1) < Test.length())
{
primtest = Test.charAt(i);
SecTest = Test.charAt(i+1);
}
else
{
primtest = Test.charAt(i);
SecTest = ' ';
}
if(primtest == '/' && SecTest == '/' && Test.charAt(i+2) != '*')
{
break;
}
if(primtest == '/' && SecTest == '*')
{
multi++;
comCheck = true;
SecTest = ' ';
i++;
continue;
}
if(primtest == '*' && SecTest == '/' && comCheck && multi != 0)
{
multi--;
if(multi == 0)
{
comCheck = false;
}
SecTest = ' ';
i++;
continue;
}
if(!comCheck)
{
notDim = true;
for (String aDLim : dLim)
{
current = String.valueOf(primtest);
if (current.equals("+") || current.equals("-"))
{
notDim = String.valueOf(Test.charAt(i - 1)).equals("E");
if (String.valueOf(SecTest).equals(current)) {
notDim = false;
current = current + SecTest;
}
} else {
if (current.equals(aDLim) || current.equals(" "))
{
notDim = false;
if (current.equals("{"))
{
depth++;
}
if (current.equals("}"))
{
depth--;
}
}
}
}
if(notDim && i < Test.length())
{
analyzeMe += primtest;
}
else
{
analyzeMe = keyHunt(analyzeMe, sym);
analyzeMe = intHunt(analyzeMe, dLim);
if(!analyzeMe.equals(""))
{
analyzeMe = "";
}
if((!current.equals("")) && (!current.equals(" ") ))
{
if(current.equals("="))
{
if(String.valueOf(SecTest).equals(current))
{
current += SecTest;
i++;
}
}
if(current.equals("!") && String.valueOf(SecTest).equals("="))
{
current += SecTest;
i++;
}
if((current.equals(">") || current.equals("<")) && String.valueOf(SecTest).equals("="))
{
current += SecTest;
i++;
}
if(!(current.equals("\t") || current.equals("\r") || current.equals("\n")))
{
imAtoken token = new imAtoken("Symbol", current, depth,lineNum);
stacker.add(token);
}
}
}
}
}
}
}
catch (FileNotFoundException e) // if the file can not be scanned in....
{
e.printStackTrace(); //show me where it fails
}
if(!analyzeMe.equals(""))
{
analyzeMe = keyHunt(analyzeMe, sym);
analyzeMe = intHunt(analyzeMe, dLim);
}
return stacker;
}
|
a6364d8f-ca8a-4dc7-b886-566527c85b65
|
String keyHunt(String analyzeMe, String[] sym)
{
boolean keyCheck = false;
for (String aSym : sym) {
if (analyzeMe.equals(aSym)) {
imAtoken token = new imAtoken("Keyword", analyzeMe, depth,lineNum);
stacker.add(token);
analyzeMe = "";
keyCheck = true;
}
}
if(!keyCheck && !analyzeMe.equals(""))
{
analyzeMe = idHunt(analyzeMe);
}
return analyzeMe;
}
|
f5c22974-afe5-469d-b4bb-13274bb8dfe7
|
String idHunt(String analyzeMe)
{
boolean idCheck = true;
for(int r = 0; r < analyzeMe.length(); r++)
{
if(!Character.isLetter(analyzeMe.charAt(r)))
{
idCheck = false;
}
}
if(idCheck)
{
imAtoken token = new imAtoken("ID", analyzeMe, depth,lineNum);
stacker.add(token);
analyzeMe = "";
}
return analyzeMe;
}
|
f9000c36-d362-4623-85e5-a3600ad43a32
|
String intHunt(String analyzeMe, String[] dLim)
{
boolean intCheck = true;
boolean errorCheck = false;
for(int r = 0; r < analyzeMe.length(); r++)
{
for (String aDLim : dLim) {
String wall = String.valueOf(analyzeMe.charAt(r));
char egg = analyzeMe.charAt(r);
if (!wall.equals(aDLim) && !Character.isLetterOrDigit(egg)) {
errorCheck = true;
}
if (!Character.isDigit(analyzeMe.charAt(r))) {
intCheck = false;
}
}
}
if(errorCheck)
{
analyzeMe = checkFloat(analyzeMe);
}
if(intCheck && !analyzeMe.equals(""))
{
imAtoken token = new imAtoken("int", analyzeMe, depth, lineNum);
stacker.add(token);
analyzeMe = "";
}
return analyzeMe;
}
|
6487a41f-05f1-41e1-9b36-2aaad939f88f
|
String checkFloat(String analyzeMe)
{
int counter = 0;
//Evaluate if the word is a float.
String regex = "\\d*\\.?\\d+([E][+-]?\\d+)?";
Pattern floatPat = Pattern.compile(regex); //create a pattern to match
Matcher match = floatPat.matcher(analyzeMe); //look for a match
boolean isFloat = match.matches(); //Did it match?
if(isFloat) {
//Success, output it.
imAtoken token = new imAtoken("float", analyzeMe, depth,lineNum);
stacker.add(token);
analyzeMe = "";
}
else
{
//Check to see if there were too many decimals.
for(int i = 0; i < analyzeMe.length(); i++)
{
if(analyzeMe.charAt(i) == '.')
{
counter++;
}
}
//If there is more than 1 decimal, output an error.
if(counter > 1)
{
System.out.println("ERROR: invalid token \"" + analyzeMe + "\" found on line " + lineNum);
analyzeMe = "";
}
}
return analyzeMe;
}
|
ef1c1e2d-6374-4cff-aac3-cb74a66ff21e
|
public static void main(String[] args)
{
ArrayDeque<imAtoken> parseMe = new ArrayDeque<imAtoken>();// collection of analyzed pieces to be parsed
ArrayList<Functions> functionList = new ArrayList<Functions>();
String conti = ""; //Can it be parsed?
int[] x = new int[10];
Lex lex = new Lex(); //Lexical Analyzer creation
parseMe = lex.run(args); //Create the string from the lexical analyzer
//Call the Parser------------------------------------------------
Parser parser = new Parser(); //Parser creation
conti = parser.run(parseMe, functionList, conti); //run through parser
//Print Successful Result-----------------------------------------
System.out.println(conti);
}
|
51148922-5167-43b5-9176-2a56b4ef3346
|
public imAtoken(String t, String am, int d, int l)
{
type = t;
name = am;
depth = d;
line = l;
}
|
e7bfe583-e705-41e3-b4ce-aa579a04a502
|
public String toString()
{
return name;
}
|
86609559-87d6-4b25-a399-daf4c3f83dab
|
public Item(String description, double weight, boolean canBeTaken)
{
this.id = "" + idSiguiente;
this.idSiguiente++;
this.description = description;
this.weight = weight;
this.canBeTaken = canBeTaken;
}
|
cbb1114f-dfb3-47d0-a44d-7a01ad1ffc41
|
public String getLongDescription()
{
return "ID " + id + ": " + description + " (" + weight + " kg.)";
}
|
13a01cb6-ca91-48f2-b5fb-d1d7783eb1b0
|
public String getId()
{
return id;
}
|
1d7d1e19-2c0e-48e7-87d5-0a1ca6d10448
|
public double getWeight()
{
return weight;
}
|
dd16287b-bcd6-4520-b5a8-630c22e79355
|
public boolean canBeTaken() {
return canBeTaken;
}
|
0390a938-b54f-4d99-9761-1a31e0fc4723
|
public Parser()
{
commands = new CommandWords();
reader = new Scanner(System.in);
}
|
4b05bf47-8a98-4833-90b1-63cbb0594d9d
|
public Command getCommand()
{
String inputLine; // will hold the full input line
String word1 = null;
String word2 = null;
System.out.print("> "); // print prompt
inputLine = reader.nextLine();
// Find up to two words on the line.
Scanner tokenizer = new Scanner(inputLine);
if(tokenizer.hasNext()) {
word1 = tokenizer.next(); // get first word
if(tokenizer.hasNext()) {
word2 = tokenizer.next(); // get second word
// note: we just ignore the rest of the input line.
}
}
// Now check whether this word is known. If so, create a command
// with it. If not, create a "null" command (for unknown command).
if(commands.isCommand(word1)) {
return new Command(word1, word2);
}
else {
return new Command(null, word2);
}
}
|
8b0a1f36-c19b-49e8-b525-0ecbb81dbdef
|
public void showCommands(){
commands.showAll();
}
|
9757ac98-d44c-4d63-86e2-363473dac4a1
|
public Player()
{
currentRoom = null;
visitedRooms = new Stack<>();
mochila = new ArrayList<Item>();
cargaMaxima = CARGA_MAXIMA_POR_DEFECTO;
}
|
a25882e0-a878-402c-a686-dea0e4bf3046
|
public void goRoom(Command command)
{
if(!command.hasSecondWord()) {
// if there is no second word, we don't know where to go...
System.out.println("Go where?");
return;
}
String direction = command.getSecondWord();
// Try to leave current room.
Room nextRoom = currentRoom.getExit(direction);
if (nextRoom == null) {
System.out.println("There is no door!");
}
else {
visitedRooms.push(currentRoom);
currentRoom = nextRoom;
printLocationInfo();
}
}
|
8faaf3fe-8539-48dd-8a80-2bace036926b
|
public void look()
{
printLocationInfo();
}
|
5e934d14-a773-4ef9-9a50-59cd3c0a17ec
|
public void eat()
{
System.out.println("You have eaten now and you are not hungry any more");
}
|
c37c47a6-5622-4f12-bae4-c10e84d93e98
|
public void back()
{
if (!visitedRooms.empty()) {
currentRoom = visitedRooms.pop();
printLocationInfo();
}
else {
System.out.println("You are at the beggining of the game");
System.out.println();
}
}
|
cc08fc42-9446-4e5b-a385-c9c135fcc214
|
public void printLocationInfo()
{
System.out.println(currentRoom.getLongDescription());
}
|
371e7268-2a9f-46da-86bd-89bfb9aae60e
|
public void setCurrentRoom(Room nuevaRoom)
{
currentRoom = nuevaRoom;
}
|
4ddc302a-cf0f-416e-9ec4-9539fbebaa64
|
public void items()
{
System.out.println("En la mochila hay " + mochila.size() + " objetos:");
for(Item item : mochila)
{
System.out.println(item.getLongDescription());
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.