I am studying compiler design and I am trying to implement an LL(1) parser by hand. I already finished the lexical scanner and it works great. However, I'm quite new to elimination of left recursiveness and left factoring. I created a parse() method in java and it is outputting a stackoverflow. I think it is caused by infinite recurse of something in my grammar. What might be causing it? Here's the grammar I'm using:
start -> assign_var statement
assign_var -> DATATYPE VARIABLE ASSIGNMENT var assign_var | eps
var -> expression | STRING
expression -> factore'
e' -> PLUSMINUS factore' | eps
factor -> gf'
f' -> MULDIV gf' | eps
g -> VARIABLE | NUMBER | DECIMAL
statement -> STARTIF IF boolean_stmt THEN statement butif_stmt FINISHIF
statement -> STARTFROM FROM assign_var UNTIL boolean_stmt LOOP statement FINISHFROM
statement -> expression statement
statement -> WRITE g
statement -> READ g
statement -> eps
butif_stmt -> BUTIF boolean_stmt THEN statement | eps
boolean_stmt -> expression bln_optr expression
bln_optr -> EQUALITY | INEQUALITY | LESSTHANGREATERTHANEQUAL
where the capital letter words are the terminal symbols. Thank you!
Here's a bit of the java code:
public static void assign_var(){
//assign_var -> DATATYPE VARIABLE ASSIGNMENT var assign_var | eps
if (lookahead.equals("DATATYPE")){
nextToken();
if(lookahead.equals("IDENTIFIER")){
nextToken();
if(lookahead.equals("ASSIGNMENT")){
nextToken();
var();
assign_var();
}
}
}
else {} //epsilon
}
The else statement is where I'm planning to implement the eps