Merge branch 'feature/optimize-lexical-error-messages' into feature/add-naitve-print
This commit is contained in:
commit
c388edd0cf
@ -71,7 +71,7 @@ Snow 语言受到 LLM 驱动代码生成趋势的启发,强调简单而清晰的
|
|||||||
## 相关文档
|
## 相关文档
|
||||||
[Snow-Lang 指南](docs/Snow-Lang-Syntax/Snow-Lang-Syntax.md)
|
[Snow-Lang 指南](docs/Snow-Lang-Syntax/Snow-Lang-Syntax.md)
|
||||||
|
|
||||||
[Snow-Lang 语法规范](docs/Snow-Lang-Syntax/Snow-Lang-Grammar-Specification)
|
[Snow-Lang 语法规范](docs/Snow-Lang-Syntax/Snow-Lang-Grammar-Specification.md)
|
||||||
|
|
||||||
|
|
||||||
[Git 管理规范](docs/Snow-Lang-Git-Management/Snow-Lang-Git-Management.md)
|
[Git 管理规范](docs/Snow-Lang-Git-Management/Snow-Lang-Git-Management.md)
|
||||||
|
|||||||
@ -321,10 +321,8 @@ Snow-Lang 支持下列**数值类型**,用于声明变量、参数、结构体
|
|||||||
|----|--------|----------|
|
|----|--------|----------|
|
||||||
| b | byte | 7b, -2B |
|
| b | byte | 7b, -2B |
|
||||||
| s | short | 123s |
|
| s | short | 123s |
|
||||||
| i | int | 100i |
|
|
||||||
| l | long | 5l, 123L |
|
| l | long | 5l, 123L |
|
||||||
| f | float | 3.14f |
|
| f | float | 3.14f |
|
||||||
| d | double | 1.0d |
|
|
||||||
|
|
||||||
- 没有后缀的整数字面量自动为 `int`。
|
- 没有后缀的整数字面量自动为 `int`。
|
||||||
- 没有后缀的浮点字面量自动为 `double`。
|
- 没有后缀的浮点字面量自动为 `double`。
|
||||||
|
|||||||
@ -7,34 +7,34 @@ module: Main
|
|||||||
5 == 7b
|
5 == 7b
|
||||||
5 == 7l
|
5 == 7l
|
||||||
5 == 7f
|
5 == 7f
|
||||||
5 == 7d
|
5 == 7.0
|
||||||
|
|
||||||
5b == 5b
|
5b == 5b
|
||||||
5b == 5s
|
5b == 5s
|
||||||
5b == 5l
|
5b == 5l
|
||||||
5b == 5f
|
5b == 5f
|
||||||
5b == 5d
|
5b == 5.0
|
||||||
|
|
||||||
5s == 5s
|
5s == 5s
|
||||||
5s == 5l
|
5s == 5l
|
||||||
5s == 5f
|
5s == 5f
|
||||||
5s == 5d
|
5s == 5.0
|
||||||
|
|
||||||
5l == 5l
|
5l == 5l
|
||||||
5l == 5f
|
5l == 5f
|
||||||
5l == 5d
|
5l == 5.0
|
||||||
|
|
||||||
5f == 5f
|
5f == 5f
|
||||||
5f == 5d
|
5f == 5.0
|
||||||
|
|
||||||
5d == 5d
|
5.0 == 5.0
|
||||||
|
|
||||||
declare b: byte = 8b
|
declare b: byte = 8b
|
||||||
declare s: short = 8s
|
declare s: short = 8s
|
||||||
declare i: int = 8
|
declare i: int = 8
|
||||||
declare l: long = 8l
|
declare l: long = 8l
|
||||||
declare f: float = 8f
|
declare f: float = 8f
|
||||||
declare d: double = 8d
|
declare d: double = 8
|
||||||
|
|
||||||
b == b
|
b == b
|
||||||
b == s
|
b == s
|
||||||
|
|||||||
@ -42,7 +42,7 @@ import org.jcnc.snow.compiler.lexer.token.TokenType;
|
|||||||
* <li>小数点后缺失数字(如 1.)—— 抛出 LexicalException</li>
|
* <li>小数点后缺失数字(如 1.)—— 抛出 LexicalException</li>
|
||||||
* </ol>
|
* </ol>
|
||||||
* <p>
|
* <p>
|
||||||
* 支持的单字符类型后缀包括: b, s, l, f, d 及其大写形式。若需支持多字符后缀,可将该集合扩展为 Set<String>。
|
* 支持的单字符类型后缀包括: b, s, l, f 及其大写形式。若需支持多字符后缀,可将该集合扩展为 Set<String>。
|
||||||
*/
|
*/
|
||||||
public class NumberTokenScanner extends AbstractTokenScanner {
|
public class NumberTokenScanner extends AbstractTokenScanner {
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ public class NumberTokenScanner extends AbstractTokenScanner {
|
|||||||
* 包含: b, s, l, f, d 及其大写形式。
|
* 包含: b, s, l, f, d 及其大写形式。
|
||||||
* 对于多字符后缀,可扩展为 Set<String> 并在扫描尾部做贪婪匹配。
|
* 对于多字符后缀,可扩展为 Set<String> 并在扫描尾部做贪婪匹配。
|
||||||
*/
|
*/
|
||||||
private static final String SUFFIX_CHARS = "bslfdBSLFD";
|
private static final String SUFFIX_CHARS = "bslfBSLF";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断是否由该扫描器处理。
|
* 判断是否由该扫描器处理。
|
||||||
@ -177,8 +177,10 @@ public class NumberTokenScanner extends AbstractTokenScanner {
|
|||||||
|
|
||||||
/* 2-B. **非法字母**(既不是后缀,也没有空白隔开) */
|
/* 2-B. **非法字母**(既不是后缀,也没有空白隔开) */
|
||||||
} else if (Character.isLetter(next)) {
|
} else if (Character.isLetter(next)) {
|
||||||
|
var its = new IdentifierTokenScanner();
|
||||||
|
var token = its.scanToken(ctx, line, col);
|
||||||
throw new LexicalException(
|
throw new LexicalException(
|
||||||
"数字后不能紧跟未知标识符 '" + next + "'", line, col);
|
"数字后不能紧跟未知标识符 '" + token.getLexeme() + "'", line, col);
|
||||||
/* 2-C. **非法下划线** */
|
/* 2-C. **非法下划线** */
|
||||||
} else if (next == '_') {
|
} else if (next == '_') {
|
||||||
throw new LexicalException(
|
throw new LexicalException(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user