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