创作一个简单的编程语言2 ,开始增加中文关键字的功能
已经基本生成了,见:https://skywalk.blog.csdn.net/article/details/151795514 现在开始增加中文关键字的功能。
前面中文关键字的时候会报错 ,所以Trae先去掉了中文关键字调试,现在都调通了再来处理中文关键字的问题
报错信息:
javac -cp ".;antlr-4.13.1-complete.jar" DebugVisitor.java && java -cp ".;antlr-4.13.1-complete.jar" DebugVisitor
DebugVisitor.java:35: 错误: 编码 GBK 的不
可映射字符 (0x83)String source = new String("(閹垫
挸宓? \"Hello from Chinese!\")".getBytes("UTF-8"), "UTF-8");
lexer grammar custom_arc_lexer;// Core Arc language keywords
FN: 'fn';
AND: 'and';
OR: 'or';
IF: 'if';
WHEN: 'when';
UNLESS: 'unless';
COND: 'cond';
CASE: 'case';
DEF: 'def';
REDEF: 'redef';
ASSIGN: 'assign';
LET: 'let';
WITH: 'with';
WITHS: 'withs';
MAC: 'mac';
DO: 'do';
DO1: 'do1';
DELAY: 'delay';
SETBANG: 'set!';
ELSE: 'else';
ARROW: '=>';// Loops and iteration
EACH: 'each';
FOR: 'for';
WHILE: 'while';
REPEAT: 'repeat';
LOOP: 'loop';
UP: 'up';// Function variants
RFN: 'rfn';
AFN: 'afn';// Error handling
CATCH: 'catch';
THROW: 'throw';
ERRSAFE: 'errsafe';
WARN: 'warn';// Atomic operations
ATOMIC: 'atomic';
ATLET: 'atlet';
ATWITH: 'atwith';
ATWITHS: 'atwiths';// Data structures
TABLE: 'table';
OBJ: 'obj';// I/O operations
// PR: 'pr';
// PRN: 'prn';
DISP: 'disp';
WRITE: 'write';
READ: 'read';
TOSTRING: 'tostring';// Module system
REQUIRE: 'require';
LOAD: 'load';// Utility functions
MAP: 'map';
KEEP: 'keep';
ACCUM: 'accum';
BEST: 'best';
SORT: 'sort';
REDUCE: 'reduce';// Boolean literals
TRUE: 'true' | '#t' | 't';
FALSE: 'false' | '#f' | 'nil';// Chinese keywords (optional)
HANSHU: '函数';
RUGUO: '如果';
FOUZE: '否则';
XUNHUAN: '循环';
FANHUI: '返回';
DINGYI: '定义';
SHEZHI: '设置';
DAYIN: '打印';// Identifiers
ID: [a-zA-Z_\u4e00-\u9fff][a-zA-Z0-9_:\u4e00-\u9fff-]*; // Added : and - for ssyntax, and Chinese characters// Numbers (supporting integers, floats, and scientific notation)
NUMBER: '-'? [0-9]+ ('.' [0-9]+)? ([eE] [+-]? [0-9]+)?;// Whitespace and comments
WS: [ \t\r\n]+ -> skip;
COMMENT: ';' ~[\r\n]* -> skip;// Symbols
LPAREN: '(';
RPAREN: ')';
LBRACK: '[';
RBRACK: ']';
LBRACE: '{';
RBRACE: '}';
QUOTE: '\'';
BACKQUOTE: '`';
COMMA: ',';
COMMA_AT: ',@';
DOT: '.';// Operators
PLUS: '+';
MINUS: '-';
MULTIPLY: '*';
DIVIDE: '/';
MODULO: '%';
EQUAL: '=';
GT: '>';
LT: '<';
GTE: '>=';
LTE: '<=';// Arc-specific operators
PLUSPLUS: '++';
MINUSMINUS: '--';
IS: 'is';
ISNT: 'isnt';
IN: 'in';
TILDE: '~';
AMPERSAND: '&';
BANG: '!';
TILDEIS: '~is';
TILDEISNT: '~isnt';// SSyntax characters (special syntax)
COLON: ':';
COLONSTAR: ':*';
COLONTILDE: ':~';
COLONBANG: ':!';
COLONDOT: ':.';
COLONAMP: ':&';// String literal
STRING: '"' ( ESC_SEQ | ~["\\] )* '"';fragment ESC_SEQ: '\\' [btnfr\\"'] // \\b \\t \\n \\f \\r \\\\ \" \'| '\\' 'x' HEX_DIGIT HEX_DIGIT;fragment HEX_DIGIT : [0-9a-fA-F];