You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nudt-compiler-cpp/src/antlr4/SysY.g4

36 lines
632 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

grammar SysY;
// 说明:
// - 这是一个“最小可用”的 SysY.g4用于避免空文件导致的 ANTLR 解析报错。
// - 后续请按 SysY 语言规范逐步补全 lexer/parser 规则。
// - 本工程约定ANTLR 生成的 C++ 源码/头文件不进入仓库,统一生成到构建目录(例如 build/generated/antlr4/)。
compilationUnit
: (statement)* EOF
;
statement
: 'return' expression? ';'
| ';'
;
expression
: IntegerLiteral
| Identifier
;
// -------- lexer --------
IntegerLiteral
: [0-9]+
;
Identifier
: [a-zA-Z_] [a-zA-Z0-9_]*
;
Whitespace
: [ \t\r\n]+ -> skip
;