// QuickScript 语法文件// ANTLR 4.13.2grammar QuickScriptFixed;// 自定义令牌类型CONST: 'const';// ===== 解析器规则 =====// 程序入口program: statement* EOF;// 语句statement: expressionStmt| variableDeclaration| constDeclaration| ifStatement| whileStatement| forStatement| doStatement| returnStatement| breakStatement| continueStatement| blockStatement| emptyStatement;// 表达式语句expressionStmt: expression Semicolon;// 变量声明variableDeclaration: type Identifier Assign expression Semicolon| VAR Identifier Assign expression Semicolon;// 常量声明constDeclaration: CONST type Identifier Assign expression Semicolon;// If 语句ifStatement: IF LeftParen expression RightParen statement (ELSE statement)?;// While 语句whileStatement: WHILE LeftParen expression RightParen statement;// For 语句forStatement: FOR LeftParen (expression Semicolon | varDecl Semicolon) expression? Semicolon expression? RightParen statement;// Do 语句doStatement: DO statement WHILE LeftParen expression RightParen Semicolon;// Return 语句returnStatement: RETURN expression? Semicolon;// Break 语句breakStatement: BREAK Semicolon;// Continue 语句continueStatement: CONTINUE Semicolon;// 代码块blockStatement: LeftBrace statement* RightBrace;// 空语句emptyStatement: Semicolon;// 变量声明简化版varDecl: type Identifier Assign expression;// ===== 表达式 =====expression: LogicalOrExpression;LogicalOrExpression: LogicalAndExpression (LogicalOr LogicalAndExpression)*;LogicalAndExpression: BitwiseOrExpression (LogicalAnd BitwiseOrExpression)*;BitwiseOrExpression: BitwiseXorExpression (BitwiseOr BitwiseXorExpression)*;BitwiseXorExpression: BitwiseAndExpression (BitwiseXor BitwiseAndExpression)*;BitwiseAndExpression: EqualityExpression (BitwiseAnd EqualityExpression)*;EqualityExpression: RelationalExpression (Equal RelationalExpression)*;RelationalExpression: ShiftExpression (Relational ShiftExpression)*;ShiftExpression: AdditiveExpression (Shift AdditiveExpression)*;AdditiveExpression: MultiplicativeExpression (Add MultiplicativeExpression)*;MultiplicativeExpression: PowerExpression (Mul PowerExpression)*;PowerExpression: UnaryExpression (Power UnaryExpression)*;UnaryExpression: Unary primary| primary;// 一元运算符Unary: Plus | Minus | LogicalNot | BitwiseNot;// 二元运算符LogicalOr: '||';LogicalAnd: '&&';BitwiseOr: '|';BitwiseXor: '^';BitwiseAnd: '&';Equal: '==' | '!=';Relational: '<' | '>' | '<=' | '>=';Shift: '<<' | '>>';Add: '+' | '-';Mul: '*' | '/' | '%';Power: '**';// 字面量literal: IntegerLiteral| FloatLiteral| StringLiteral| BooleanLiteral| NullLiteral;// 类型type: INT | INT64 | UINT | UINT64 | FLOAT | DOUBLE | BOOL | STRING | CHAR | VOID;// ===== Lexer 规则 =====// 字面量IntegerLiteral: [0-9]+;FloatLiteral: [0-9]+ '.' [0-9]+;StringLiteral: '"' (~["\\\r\n] | '\\' .)* '"';BooleanLiteral: TRUE | FALSE;NullLiteral: NULL;// 关键字(优先级最高)IF: 'if';ELSE: 'else';WHILE: 'while';DO: 'do';FOR: 'for';BREAK: 'break';CONTINUE: 'continue';RETURN: 'return';VAR: 'var';// 类型关键字INT: 'int';INT64: 'int64';UINT: 'uint';UINT64: 'uint64';FLOAT: 'float';DOUBLE: 'double';BOOL: 'bool';STRING: 'string';CHAR: 'char';VOID: 'void';// 其他关键字TRUE: 'true';FALSE: 'false';NULL: 'null';// 标识符(必须在所有关键字之后)Identifier: [a-zA-Z_][a-zA-Z0-9_]*;// 运算符Plus: '+';Minus: '-';Multiply: '*';Divide: '/';Modulo: '%';Assign: '=';LogicalNot: '!';BitwiseNot: '~';// 标点符号Semicolon: ';';LeftParen: '(';RightParen: ')';LeftBrace: '{';RightBrace: '}';// 空白符(跳过)WS: [ \t\r\n\u000C]+ -> skip;// 注释(跳过)LINE_COMMENT: '//' ~[\r\n]* -> skip;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。