Pretty syntax analysis errors
This commit is contained in:
parent
a94802b571
commit
b8545a143b
@ -48,7 +48,11 @@ restmult -> MUL prefixexpr restmult
|
||||
| MOD prefixexpr restmult
|
||||
| .
|
||||
|
||||
prefixexpr -> NOT prefixexpr | ADD prefixexpr | SUB prefixexpr | PTR prefixexpr | postfixexpr .
|
||||
prefixexpr -> NOT prefixexpr
|
||||
| ADD prefixexpr
|
||||
| SUB prefixexpr
|
||||
| PTR prefixexpr
|
||||
| postfixexpr .
|
||||
|
||||
postfixexpr -> primary postfixop .
|
||||
postfixop -> PTR postfixop | .
|
||||
|
@ -11,6 +11,7 @@ var e = 'a', "test", 4
|
||||
var f = 1 * 3
|
||||
var g = 1 * 'a'
|
||||
var h = 4 * "aaa"
|
||||
var i =
|
||||
|
||||
fun a() =
|
||||
1, 'a', "a",
|
||||
|
@ -0,0 +1 @@
|
||||
var
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Implementacija programskega jezika PINS'25.
|
||||
*
|
||||
*
|
||||
* @author bostjan.slivnik@fri.uni-lj.si
|
||||
*/
|
||||
module pins25 {
|
||||
|
@ -130,7 +130,7 @@ public class LexAn implements AutoCloseable {
|
||||
Report.Location start = currentLocation();
|
||||
switch (buffChar) {
|
||||
case -1: // EOF
|
||||
buffToken = new Token(new Report.Location(0, 0), Token.Symbol.EOF, null);
|
||||
buffToken = new Token(start, Token.Symbol.EOF, null);
|
||||
return;
|
||||
|
||||
case '\'':
|
||||
|
@ -91,7 +91,7 @@ public class SynAn implements AutoCloseable {
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Report.Error(token, "Unexpected symbol '" + token.lexeme() + "', expected FUN or VAR.");
|
||||
throw new Report.Error(token, "Unexpected symbol '" + token.lexeme() + "', expected definition.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,25 +198,37 @@ public class SynAn implements AutoCloseable {
|
||||
check(Token.Symbol.END);
|
||||
break;
|
||||
|
||||
default:
|
||||
case IDENTIFIER:
|
||||
case LPAREN:
|
||||
case ADD:
|
||||
case SUB:
|
||||
case NOT:
|
||||
case PTR:
|
||||
case INTCONST:
|
||||
case CHARCONST:
|
||||
case STRINGCONST:
|
||||
System.out.println("statement -> expression exprassign");
|
||||
parseExpression();
|
||||
parseExpressionAssign();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Report.Error(token, "Unexpected symbol '" + token.lexeme() + "', expected statement.");
|
||||
}
|
||||
}
|
||||
|
||||
private void parseRestStatementDefinitions() {
|
||||
switch (lexAn.peekToken().symbol()) {
|
||||
case IN:
|
||||
System.out.println("reststmtdefs -> ε");
|
||||
break;
|
||||
|
||||
case FUN:
|
||||
case VAR:
|
||||
System.out.println("reststmtdefs -> definition reststmtdefs");
|
||||
parseDefinition();
|
||||
parseRestStatementDefinitions();
|
||||
break;
|
||||
|
||||
case IN:
|
||||
System.out.println("reststmtdefs -> ε");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,7 +268,7 @@ public class SynAn implements AutoCloseable {
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Report.Error(token, "Unexpected symbol '" + token.lexeme() + "', expected integer, character or string constant.");
|
||||
throw new Report.Error(token, "Unexpected symbol '" + token.lexeme() + "', expected constant.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -302,12 +314,32 @@ public class SynAn implements AutoCloseable {
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Report.Error(token, "Unexpected symbol '" + token.lexeme() + "', expected integer, character or string constant.");
|
||||
throw new Report.Error(token, "Unexpected symbol '" + token.lexeme() + "', expected constant.");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkExpression() {
|
||||
Token token = lexAn.peekToken();
|
||||
switch (token.symbol()) {
|
||||
case IDENTIFIER:
|
||||
case LPAREN:
|
||||
case ADD:
|
||||
case SUB:
|
||||
case NOT:
|
||||
case PTR:
|
||||
case INTCONST:
|
||||
case CHARCONST:
|
||||
case STRINGCONST:
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new Report.Error(token, "Unexpected symbol '" + token.lexeme() + "', expected expression.");
|
||||
}
|
||||
}
|
||||
|
||||
private void parseExpression() {
|
||||
checkExpression();
|
||||
|
||||
System.out.println("expression -> conjexpr restdisj");
|
||||
parseConjunctionExpression();
|
||||
parseRestDisjunctions();
|
||||
@ -323,6 +355,8 @@ public class SynAn implements AutoCloseable {
|
||||
}
|
||||
|
||||
private void parseConjunctionExpression() {
|
||||
checkExpression();
|
||||
|
||||
System.out.println("conjexpr -> cmpexpr restconj");
|
||||
parseComparisonExpression();
|
||||
parseRestConjunctionExpressions();
|
||||
@ -340,6 +374,8 @@ public class SynAn implements AutoCloseable {
|
||||
}
|
||||
|
||||
private void parseComparisonExpression() {
|
||||
checkExpression();
|
||||
|
||||
System.out.println("cmpexpr -> addexpr restcmp");
|
||||
parseAdditionExpression();
|
||||
parseRestComparisons();
|
||||
@ -366,6 +402,8 @@ public class SynAn implements AutoCloseable {
|
||||
}
|
||||
|
||||
private void parseAdditionExpression() {
|
||||
checkExpression();
|
||||
|
||||
System.out.println("addexpr -> multexpr restadd");
|
||||
parseMultiplicationExpression();
|
||||
parseRestAdditions();
|
||||
@ -389,6 +427,8 @@ public class SynAn implements AutoCloseable {
|
||||
}
|
||||
|
||||
private void parseMultiplicationExpression() {
|
||||
checkExpression();
|
||||
|
||||
System.out.println("multexpr -> prefixexpr restmult");
|
||||
parsePrefixExpression();
|
||||
parseRestMultiplicationExpressions();
|
||||
@ -413,6 +453,8 @@ public class SynAn implements AutoCloseable {
|
||||
}
|
||||
|
||||
private void parsePrefixExpression() {
|
||||
checkExpression();
|
||||
|
||||
Token token = lexAn.peekToken();
|
||||
switch (token.symbol()) {
|
||||
case ADD:
|
||||
@ -432,6 +474,8 @@ public class SynAn implements AutoCloseable {
|
||||
}
|
||||
|
||||
private void parsePostfixExpression() {
|
||||
checkExpression();
|
||||
|
||||
System.out.println("postfixexpr -> primary postfixop");
|
||||
parsePrimary();
|
||||
parsePostfixOperator();
|
||||
|
Loading…
x
Reference in New Issue
Block a user