我正在启动我的符号表,它仍然是新的,但面临 antlr 参考我的 init_declarator 规则给出的一些错误。请有任何提示
declaration
: declaration_specifiers init_declarator_list? SEMICOLON! {currentScope.defineVariable($init_declarator_list.name,$declaration_specifier.type);}
;
declaration_specifiers returns [Symbol type]
: ( type_specifier{$type = $type_specifier.type;} |type_qualifier)+
;
init_declarator_list returns [Symbol name]
: init_declarator (COMMA init_declarator)*{$name = $init_declarator.name;} -> ^(INIT_DECLARATOR_LIST init_declarator+)
;
init_declarator returns [Symbol name]
: declarator (ASSIGN^ initializer)? {$name = $declarator.name;}
;
declarator returns [Symbol name]
: pointer? direct_declarator{$name = $direct_declarator.text;}
| pointer
;
direct_declarator returns [Symbol name]
: ( IDENTIFIER| LPAREN! declarator RPAREN! )
declarator_suffix* {$name = $IDENTIFIER.text;}
;
type_specifier returns [Symbol type] : (CONST^)? (VOID{return VoidType;} | CHAR {return CharType;}| INT{return IntType;} | FLOAT{return FloatType;} );