Here's 미안 지금 구문 분석을 시도 문법의 일부 :
제곱 된 대괄호 평균 1 또는 없음 중괄호는 0 이상을 의미합니다.
public void Cocol(){
lookahead = in.next();
if(lookahead.equals("COMPILER")){
match("COMPILER");
match("ident");
ScannerSpecification();
match("END");
match("ident");
match(".");
}
else{
System.out.println("SYNTAX ERROR: \nCOMPILER expected, Found: "+lookahead);
try {
ArrayList<Integer> line = findLineOf(lookahead);
System.out.println("Line: "+line);
} catch (Exception ex) {
Logger.getLogger(ScannerCocol.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public void ScannerSpecification(){
// 1 o mas veces “CHARACTERS” { SetDecl }
if(lookahead.equals("CHARACTERS")){
match("CHARACTERS");
// 0 or More SETDecl
}
if (lookahead.equals("KEYWORDS")){
//PENDING....
}
if(WhiteSpaceDecl()){
//PENDING....
}
boolean res=match(".");
if(res==false){
System.out.println("SYNTAX ERROR: \n \".\" expected, Found: "+lookahead);
//Encontrando linea
try {
ArrayList<Integer> line = findLineOf(lookahead);
System.out.println("Line: "+line);
} catch (Exception ex) {
Logger.getLogger(ScannerCocol.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public boolean match(String terminal){
boolean result;
if(terminal.equals("number")){
result = automataNumber.simularAFN(lookahead, automataNumber.inicial, conjuntoSimbolos);
return result;
}
else if(terminal.equals("ident")){
result = automataident.simularAFN(lookahead,automataident.inicial,conjuntoSimbolos);
return result;
}
else if(terminal.equals("string")){
result = automataString.simularAFN(lookahead,automataString.inicial,conjuntoSimbolos);
return result;
}
else if(terminal.equals("char")){
result = automataChar.simularAFN(lookahead,automataChar.inicial,conjuntoSimbolos);
return result;
}
else{
if(this.lookahead.equals(terminal)){
lookahead= in.next();
return true;
}
else{
System.out.println("Error: Se esperaba: "+terminal);
return false;
}
}
문제 미안 베란다는 I합니다 (SetDecl에 예를 들어) 제조 0 이상의 유도를 검색해야하는 경우에있다. 필자가 필적 할 수 없을 때까지 계속 프로덕션을 일치시켜야한다는 것을 알고 있지만 입력을 계속 읽어야 할 때 오류를보고해야 할 때 어떻게 식별해야하는지 알지 못합니다.
누구든지 나에게 아이디어를 줄 수 있습니까?
안녕하세요. 네가 준 규칙이 내가 필요한 것일 뿐이라고 생각해. 이 권리를 얻는 지 알고 싶습니다. 중괄호 사이에 터미널이없는 경우 첫 번째 개체를 확인하고 일치하는지 확인해야합니다. 오류를보고하지 않고 입력하십시오. 첫 번째가 아닌 다른 개체에서 오류가 발견되면 어떻게합니까? while 루프를 확인하는 중입니까? 나는 그것이보고없이 계속되어야한다고 생각하거나 나는 틀렸어? –
@PabloEstrada : 100 % 맞음. while 루프는 0 회 이상의 반복을 나타내고 0 회 반복은 항상 일치 할 수 있기 때문에 항상 성공합니다. "하나 이상의 X"의 경우 "if (! X()) false를 반환하고 while (X());를 true로 반환하는"X [X] "를 효과적으로 수행합니다. – rici