了解GET语法规则

时间:2019-03-02 23:45:05

标签: json get antlr grammar antlr4

我有一个antlr v4语法,我试图了解该语法的GET规则,但我不明白我在哪里错。我认为我必须使用JSON而不是MAP,但是当我使用JSON程序时抛出太多异常。

能帮我吗?

这是我生成的程序。

PROGRAM aa{
MAP m;
m = '{"aaaa":"17"}' ;
PRINT GET (m , "aaaa")  ;
}

以下是上述语言的语法。

grammar program;
prule: PROGRAM VARIABLE block;

WS: [ \t\r\n]+ -> skip;

NUMBER: '-'? '0'..'9'+([.,]'0'..'9'+)?;
TEXT: '"' .* '"';
JSON: '\'' .* '\'';
OPEN_BLOCK: '{';
CLOSE_BLOCK: '}';
ASSIGNMENT: '=';
MAPDECL: 'MAP';
DOUBLEDECL: 'DOUBLE';
TEXTDECL: 'TEXT';
BOOLDECL: 'BOOLEAN';
PRINT: 'PRINT';
OPEN_BRACKET: '(';
CLOSE_BRACKET: ')';
COMMA: ',';
PROGRAM: 'PROGRAM';
SMALLER: '<';
GREATER: '>';
TRUE: 'TRUE';
FALSE: 'FALSE';
GET: 'GET';
SEMICOLON: ';';
VARIABLE: ('a'..'z'|'A'..'Z')+;

block: OPEN_BLOCK statement+ CLOSE_BLOCK;

statement: (assignment |
            mapdecl |
            booldecl |
            doubledecl |
            textdecl |
            print
           ) SEMICOLON;


mapdecl: MAPDECL VARIABLE;
booldecl: BOOLDECL VARIABLE;
doubledecl: DOUBLEDECL VARIABLE;
textdecl: TEXTDECL VARIABLE;

print: PRINT (expression | logexpression);

assignment: VARIABLE ASSIGNMENT (expression | logexpression);
expression: factor ((OPERATOR_ADD|OPERATOR_SUB) expression)?;

factor: (NUMBER |
         TEXT |
         TRUE |
         FALSE |
         JSON |
         get |
         VARIABLE (OPEN_BRACKET (expression (COMMA expression)*)? CLOSE_BRACKET)? |
         OPEN_BRACKET op=expression CLOSE_BRACKET)
        ((OPERATOR_MULT | OPERATOR_DIV) factor)?;

get: GET OPEN_BRACKET expression COMMA TEXT CLOSE_BRACKET;

0 个答案:

没有答案