This commit is contained in:
ridethepig 2023-04-28 17:57:40 +08:00
parent 31bf47eb70
commit 7c226f7d91
2 changed files with 20 additions and 20 deletions

10
.vscode/settings.json vendored
View File

@ -2,5 +2,13 @@
"clangd.arguments": [
"--compile-commands-dir=${workspaceFolder}/build"
],
"cmake.configureOnOpen": true
"cmake.configureOnOpen": true,
"antlr4.rrd.saveDir": "${workspaceFolder}/build",
"antlr4.atn.saveDir": "${workspaceFolder}/build",
"antlr4.generation": {
"mode": "internal",
"language": "C++",
"listeners": false,
"visitors": true
}
}

30
SysY.g4
View File

@ -14,7 +14,7 @@ decl
;
constDecl
: CONST_KW bType constDef (COMMA constDef)* SEMICOLON
: CONST_KW bType constDef (COMMA constDef)* ';'
;
bType
@ -31,7 +31,7 @@ constInitVal
;
varDecl
: bType varDef (COMMA varDef)* SEMICOLON
: bType varDef (COMMA varDef)* ';'
;
varDef
@ -82,11 +82,11 @@ stmt
;
assignStmt
: lVal ASSIGN exp SEMICOLON
: lVal '=' exp ';'
;
expStmt
: exp? SEMICOLON
: exp? ';'
;
conditionStmt
@ -98,15 +98,15 @@ whileStmt
;
breakStmt
: BREAK_KW SEMICOLON
: BREAK_KW ';'
;
continueStmt
: CONTINUE_KW SEMICOLON
: CONTINUE_KW ';'
;
returnStmt
: RETURN_KW (exp)? SEMICOLON
: RETURN_KW (exp)? ';'
;
exp
@ -148,8 +148,8 @@ callee
;
unaryOp
: PLUS
| MINUS
: '+'
| '-'
| NOT
;
@ -177,8 +177,8 @@ addExp
; // eliminate left-recursive
addOp
: PLUS
| MINUS
: '+'
| '-'
;
relExp
@ -280,14 +280,6 @@ fragment ESC
: '\\"' | '\\\\'
;
PLUS
: '+'
;
MINUS
: '-'
;
NOT
: '!'
;