Compare commits
1 Commits
line-symbo
...
2025-predr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
352085b499 |
26
grammar.txt
26
grammar.txt
@@ -69,4 +69,28 @@ restinits -> COMMA initializer restinits | .
|
|||||||
initializer -> INTCONST intconstmult | CHARCONST | STRINGCONST .
|
initializer -> INTCONST intconstmult | CHARCONST | STRINGCONST .
|
||||||
intconstmult -> MUL const | .
|
intconstmult -> MUL const | .
|
||||||
|
|
||||||
const -> INTCONST | CHARCONST | STRINGCONST .
|
const -> INTCONST | CHARCONST | STRINGCONST .
|
||||||
|
|
||||||
|
|
||||||
|
--------------------------------------------------------------------
|
||||||
|
|
||||||
|
//LEFT ASOC.
|
||||||
|
exp0 = exp0 op other | other
|
||||||
|
|
||||||
|
|
|
||||||
|
v
|
||||||
|
|
||||||
|
exp0 = other exp0'
|
||||||
|
exp0' = op other exp0' | .
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//RIGHT ASOC.
|
||||||
|
exp0 = other op exp0 | other
|
||||||
|
|
||||||
|
|
|
||||||
|
v
|
||||||
|
|
||||||
|
exp0 = other exp0'
|
||||||
|
exp0' = op exp0 | .
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
fun putint(n)
|
// line1 --
|
||||||
|
line2 -----x
|
||||||
|
line3
|
||||||
|
|
||||||
fun main() =
|
fun main() = 0
|
||||||
putint(__LINE__)
|
|
||||||
@@ -148,11 +148,7 @@ public record Token(Report.Location location, Symbol symbol, String lexeme) impl
|
|||||||
/**
|
/**
|
||||||
* Simbol {@code )}.
|
* Simbol {@code )}.
|
||||||
*/
|
*/
|
||||||
RPAREN,
|
RPAREN;
|
||||||
/**
|
|
||||||
* Simbol {@code __LINE__}.
|
|
||||||
*/
|
|
||||||
LINE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -247,7 +247,13 @@ public class LexAn implements AutoCloseable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (buffChar != '\n' && buffChar != -1) {
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
while (buffChar != -1) {
|
||||||
|
if (buffChar == '\n' && !builder.toString().endsWith("--")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
builder.append((char) buffChar);
|
||||||
nextChar();
|
nextChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +325,6 @@ public class LexAn implements AutoCloseable {
|
|||||||
case "let" -> Token.Symbol.LET;
|
case "let" -> Token.Symbol.LET;
|
||||||
case "in" -> Token.Symbol.IN;
|
case "in" -> Token.Symbol.IN;
|
||||||
case "end" -> Token.Symbol.END;
|
case "end" -> Token.Symbol.END;
|
||||||
case "__LINE__" -> Token.Symbol.LINE;
|
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -452,15 +457,6 @@ public class LexAn implements AutoCloseable {
|
|||||||
symbol = Token.Symbol.IDENTIFIER;
|
symbol = Token.Symbol.IDENTIFIER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (symbol == Token.Symbol.LINE) {
|
|
||||||
buffToken = new Token(
|
|
||||||
new Report.Location(startLocation, endLocation),
|
|
||||||
Token.Symbol.INTCONST,
|
|
||||||
Integer.toString(startLocation.begLine())
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffToken = new Token(
|
buffToken = new Token(
|
||||||
new Report.Location(startLocation, endLocation),
|
new Report.Location(startLocation, endLocation),
|
||||||
symbol,
|
symbol,
|
||||||
|
|||||||
Reference in New Issue
Block a user