TestLeftRecursion for Java is working

This commit is contained in:
Sam Harwell 2015-01-25 23:04:54 -06:00
parent 6890d0bfdd
commit c9c32c2c4f
127 changed files with 1377 additions and 1426 deletions

View File

@ -1,5 +1,6 @@
TestFolders ::= [ TestFolders ::= [
"CompositeLexers": [], "CompositeLexers": [],
"LeftRecursion": [],
"LexerErrors": [], "LexerErrors": [],
"LexerExec": [], "LexerExec": [],
"Listeners": [], "Listeners": [],

View File

@ -1,3 +1,16 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"Expr": {<grammar("Expr")>}
]
Rule() ::= "prog"
grammar(grammarName) ::= <<
grammar <grammarName>; grammar <grammarName>;
prog: stat ; prog: stat ;
stat: expr NEWLINE # printExpr stat: expr NEWLINE # printExpr
@ -19,3 +32,4 @@ ID : [a-zA-Z]+ ; // match identifiers
INT : [0-9]+ ; // match integers INT : [0-9]+ ; // match integers
NEWLINE:'\r'? '\n' ; // return newlines to parser (is end-statement signal) NEWLINE:'\r'? '\n' ; // return newlines to parser (is end-statement signal)
WS : [ \t]+ -> skip ; // toss out whitespace WS : [ \t]+ -> skip ; // toss out whitespace
>>

View File

@ -0,0 +1,7 @@
import "AmbigLR.stg"
Input() ::= "1<\n>"
Output() ::= ""
Errors() ::= ""

View File

@ -0,0 +1,7 @@
import "AmbigLR.stg"
Input() ::= "a = 5<\n>"
Output() ::= ""
Errors() ::= ""

View File

@ -0,0 +1,7 @@
import "AmbigLR.stg"
Input() ::= "b = 6<\n>"
Output() ::= ""
Errors() ::= ""

View File

@ -0,0 +1,7 @@
import "AmbigLR.stg"
Input() ::= "a+b*2<\n>"
Output() ::= ""
Errors() ::= ""

View File

@ -0,0 +1,7 @@
import "AmbigLR.stg"
Input() ::= "(1+2)*3<\n>"
Output() ::= ""
Errors() ::= ""

View File

@ -1,3 +1,16 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>; grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : declarator EOF ; // must indicate EOF can follow s @after {<ToStringTree("$ctx"):writeln()>} : declarator EOF ; // must indicate EOF can follow
declarator declarator
@ -12,3 +25,4 @@ e : INT ;
ID : 'a'..'z'+ ; ID : 'a'..'z'+ ;
INT : '0'..'9'+ ; INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ; WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "Declarations.stg"
Input() ::= "a"
Output() ::= <<
(s (declarator a) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Declarations.stg"
Input() ::= "(*a)[]"
Output() ::= <<
(s (declarator (declarator ( (declarator * (declarator a)) )) [ ]) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Declarations.stg"
Input() ::= "*a"
Output() ::= <<
(s (declarator * (declarator a)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Declarations.stg"
Input() ::= "**a"
Output() ::= <<
(s (declarator * (declarator * (declarator a))) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Declarations.stg"
Input() ::= "a[3]"
Output() ::= <<
(s (declarator (declarator a) [ (e 3) ]) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Declarations.stg"
Input() ::= "b[]"
Output() ::= <<
(s (declarator (declarator b) [ ]) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Declarations.stg"
Input() ::= "(a)"
Output() ::= <<
(s (declarator ( (declarator a) )) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Declarations.stg"
Input() ::= "a[]()"
Output() ::= <<
(s (declarator (declarator (declarator a) [ ]) ( )) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Declarations.stg"
Input() ::= "a[][]"
Output() ::= <<
(s (declarator (declarator (declarator a) [ ]) [ ]) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Declarations.stg"
Input() ::= "*a[]"
Output() ::= <<
(s (declarator * (declarator (declarator a) [ ])) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,20 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "a"
grammar(grammarName) ::= <<
grammar <grammarName>;
a @after {<ToStringTree("$ctx"):writeln()>} : a ID
| ID
;
ID : 'a'..'z'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "DirectCallToLeftRecursiveRule.stg"
Input() ::= "x"
Output() ::= <<
(a x)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "DirectCallToLeftRecursiveRule.stg"
Input() ::= "x y"
Output() ::= <<
(a (a x) y)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "DirectCallToLeftRecursiveRule.stg"
Input() ::= "x y z"
Output() ::= <<
(a (a (a x) y) z)<\n>
>>
Errors() ::= ""

View File

@ -1,3 +1,16 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>; grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : e EOF ; // must indicate EOF can follow s @after {<ToStringTree("$ctx"):writeln()>} : e EOF ; // must indicate EOF can follow
e : e '.' ID e : e '.' ID
@ -11,3 +24,4 @@ e : e '.' ID
ID : 'a'..'z'+ ; ID : 'a'..'z'+ ;
INT : '0'..'9'+ ; INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ; WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "Expressions.stg"
Input() ::= "a"
Output() ::= <<
(s (e a) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Expressions.stg"
Input() ::= "1"
Output() ::= <<
(s (e 1) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Expressions.stg"
Input() ::= "a-1"
Output() ::= <<
(s (e (e a) - (e 1)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Expressions.stg"
Input() ::= "a.b"
Output() ::= <<
(s (e (e a) . b) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Expressions.stg"
Input() ::= "a.this"
Output() ::= <<
(s (e (e a) . this) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Expressions.stg"
Input() ::= "-a"
Output() ::= <<
(s (e - (e a)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Expressions.stg"
Input() ::= "-a+b"
Output() ::= <<
(s (e (e - (e a)) + (e b)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,100 @@
//TestFolders ::= [
//]
TestTemplates ::= [
"Simple_1": [],
"Simple_2": [],
"Simple_3": [],
"DirectCallToLeftRecursiveRule_1": [],
"DirectCallToLeftRecursiveRule_2": [],
"DirectCallToLeftRecursiveRule_3": [],
"SemPred": [],
"TernaryExpr_1": [],
"TernaryExpr_2": [],
"TernaryExpr_3": [],
"TernaryExpr_4": [],
"TernaryExpr_5": [],
"TernaryExpr_6": [],
"TernaryExpr_7": [],
"TernaryExpr_8": [],
"TernaryExpr_9": [],
"Expressions_1": [],
"Expressions_2": [],
"Expressions_3": [],
"Expressions_4": [],
"Expressions_5": [],
"Expressions_6": [],
"Expressions_7": [],
"JavaExpressions_1": [],
"JavaExpressions_2": [],
"JavaExpressions_3": [],
"JavaExpressions_4": [],
"JavaExpressions_5": [],
"JavaExpressions_6": [],
"JavaExpressions_7": [],
"JavaExpressions_8": [],
"JavaExpressions_9": [],
"JavaExpressions_10": [],
"JavaExpressions_11": [],
"JavaExpressions_12": [],
"Declarations_1": [],
"Declarations_2": [],
"Declarations_3": [],
"Declarations_4": [],
"Declarations_5": [],
"Declarations_6": [],
"Declarations_7": [],
"Declarations_8": [],
"Declarations_9": [],
"Declarations_10": [],
"ReturnValueAndActions_1": [],
"ReturnValueAndActions_2": [],
"ReturnValueAndActions_3": [],
"ReturnValueAndActions_4": [],
"LabelsOnOpSubrule_1": [],
"LabelsOnOpSubrule_2": [],
"LabelsOnOpSubrule_3": [],
"ReturnValueAndActionsAndLabels_1": [],
"ReturnValueAndActionsAndLabels_2": [],
"ReturnValueAndActionsAndLabels_3": [],
"ReturnValueAndActionsAndLabels_4": [],
"MultipleAlternativesWithCommonLabel_1": [],
"MultipleAlternativesWithCommonLabel_2": [],
"MultipleAlternativesWithCommonLabel_3": [],
"MultipleAlternativesWithCommonLabel_4": [],
"PrefixOpWithActionAndLabel_1": [],
"PrefixOpWithActionAndLabel_2": [],
"PrefixOpWithActionAndLabel_3": [],
"AmbigLR_1": [],
"AmbigLR_2": [],
"AmbigLR_3": [],
"AmbigLR_4": [],
"AmbigLR_5": [],
"WhitespaceInfluence_1": [],
"WhitespaceInfluence_2": [],
"PrecedenceFilterConsidersContext": [],
"MultipleActions_1": [],
"MultipleActions_2": [],
"MultipleActions_3": [],
"MultipleActionsPredicatesOptions_1": [],
"MultipleActionsPredicatesOptions_2": [],
"MultipleActionsPredicatesOptions_3": [],
"SemPredFailOption": [],
"TernaryExprExplicitAssociativity_1": [],
"TernaryExprExplicitAssociativity_2": [],
"TernaryExprExplicitAssociativity_3": [],
"TernaryExprExplicitAssociativity_4": [],
"TernaryExprExplicitAssociativity_5": [],
"TernaryExprExplicitAssociativity_6": [],
"TernaryExprExplicitAssociativity_7": [],
"TernaryExprExplicitAssociativity_8": [],
"TernaryExprExplicitAssociativity_9": [],
"ReturnValueAndActionsList1_1": [],
"ReturnValueAndActionsList1_2": [],
"ReturnValueAndActionsList1_3": [],
"ReturnValueAndActionsList1_4": [],
"ReturnValueAndActionsList2_1": [],
"ReturnValueAndActionsList2_2": [],
"ReturnValueAndActionsList2_3": [],
"ReturnValueAndActionsList2_4": []
]

View File

@ -1,3 +1,16 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>; grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : e EOF ; // must indicate EOF can follow s @after {<ToStringTree("$ctx"):writeln()>} : e EOF ; // must indicate EOF can follow
expressionList expressionList
@ -22,7 +35,7 @@ e : '(' e ')'
| ('~'|'!') e | ('~'|'!') e
| e ('*'|'/'|'%') e | e ('*'|'/'|'%') e
| e ('+'|'-') e | e ('+'|'-') e
| e ('\<\<' | '>>>' | '>>') e | e ('\<\<' | '>\>>' | '\>>') e
| e ('\<=' | '>=' | '>' | '\<') e | e ('\<=' | '>=' | '>' | '\<') e
| e 'instanceof' e | e 'instanceof' e
| e ('==' | '!=') e | e ('==' | '!=') e
@ -41,8 +54,8 @@ e : '(' e ')'
|'&=' |'&='
|'|=' |'|='
|'^=' |'^='
|'>>=' |'\>>='
|'>>>=' |'>\>>='
|'\<\<=' |'\<\<='
|'%=') e |'%=') e
; ;
@ -54,3 +67,4 @@ type_: ID
ID : ('a'..'z'|'A'..'Z'|'_'|'$')+; ID : ('a'..'z'|'A'..'Z'|'_'|'$')+;
INT : '0'..'9'+ ; INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ; WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "JavaExpressions.stg"
Input() ::= "a|b&c"
Output() ::= <<
(s (e (e a) | (e (e b) & (e c))) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "JavaExpressions.stg"
Input() ::= "a.f(x)==T.c"
Output() ::= <<
(s (e (e (e (e a) . f) ( (expressionList (e x)) )) == (e (e T) . c)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "JavaExpressions.stg"
Input() ::= "a.f().g(x,1)"
Output() ::= <<
(s (e (e (e (e (e a) . f) ( )) . g) ( (expressionList (e x) , (e 1)) )) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "JavaExpressions.stg"
Input() ::= "new T[((n-1) * x) + 1]"
Output() ::= <<
(s (e new (type_ T) [ (e (e ( (e (e ( (e (e n) - (e 1)) )) * (e x)) )) + (e 1)) ]) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "JavaExpressions.stg"
Input() ::= "(a|b)&c"
Output() ::= <<
(s (e (e ( (e (e a) | (e b)) )) & (e c)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "JavaExpressions.stg"
Input() ::= "a > b"
Output() ::= <<
(s (e (e a) > (e b)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "JavaExpressions.stg"
Input() ::= "a >> b"
Output() ::= <<
(s (e (e a) \>> (e b)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "JavaExpressions.stg"
Input() ::= "a=b=c"
Output() ::= <<
(s (e (e a) = (e (e b) = (e c))) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "JavaExpressions.stg"
Input() ::= "a^b^c"
Output() ::= <<
(s (e (e a) ^ (e (e b) ^ (e c))) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "JavaExpressions.stg"
Input() ::= "(T)x"
Output() ::= <<
(s (e ( (type_ T) ) (e x)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "JavaExpressions.stg"
Input() ::= "new A().b"
Output() ::= <<
(s (e (e new (type_ A) ( )) . b) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "JavaExpressions.stg"
Input() ::= "(T)t.f()"
Output() ::= <<
(s (e (e ( (type_ T) ) (e (e t) . f)) ( )) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,3 +1,16 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>; grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : e; s @after {<ToStringTree("$ctx"):writeln()>} : e;
e : a=e op=('*'|'/') b=e {} e : a=e op=('*'|'/') b=e {}
@ -6,3 +19,4 @@ e : a=e op=('*'|'/') b=e {}
; ;
INT : '0'..'9'+ ; INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ; WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "LabelsOnOpSubrule.stg"
Input() ::= "4"
Output() ::= <<
(s (e 4))<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "LabelsOnOpSubrule.stg"
Input() ::= "1*2/3"
Output() ::= <<
(s (e (e (e 1) * (e 2)) / (e 3)))<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "LabelsOnOpSubrule.stg"
Input() ::= "(1/2)*3"
Output() ::= <<
(s (e (e ( (e (e 1) / (e 2)) )) * (e 3)))<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,28 @@
/**
* This is a regression test for antlr/antlr4#625 "Duplicate action breaks
* operator precedence"
* https://github.com/antlr/antlr4/issues/625
*/
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : e ;
e : a=e op=('*'|'/') b=e {}{}
| INT {}{}
| '(' x=e ')' {}{}
;
INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,29 @@
/**
* This is a regression test for antlr/antlr4#625 "Duplicate action breaks
* operator precedence"
* https://github.com/antlr/antlr4/issues/625
*/
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : e ;
e : a=e op=('*'|'/') b=e {}{<True()>}?
| a=e op=('+'|'-') b=e {}\<p=3>{<True()>}?\<fail='Message'>
| INT {}{}
| '(' x=e ')' {}{}
;
INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "MultipleActionsPredicatesOptions.stg"
Input() ::= "4"
Output() ::= <<
(s (e 4))<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "MultipleActionsPredicatesOptions.stg"
Input() ::= "1*2/3"
Output() ::= <<
(s (e (e (e 1) * (e 2)) / (e 3)))<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "MultipleActionsPredicatesOptions.stg"
Input() ::= "(1/2)*3"
Output() ::= <<
(s (e (e ( (e (e 1) / (e 2)) )) * (e 3)))<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "MultipleActions.stg"
Input() ::= "4"
Output() ::= <<
(s (e 4))<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "MultipleActions.stg"
Input() ::= "1*2/3"
Output() ::= <<
(s (e (e (e 1) * (e 2)) / (e 3)))<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "MultipleActions.stg"
Input() ::= "(1/2)*3"
Output() ::= <<
(s (e (e ( (e (e 1) / (e 2)) )) * (e 3)))<\n>
>>
Errors() ::= ""

View File

@ -1,3 +1,23 @@
/**
* This is a regression test for antlr/antlr4#433 "Not all context accessor
* methods are generated when an alternative rule label is used for multiple
* alternatives".
* https://github.com/antlr/antlr4/issues/433
*/
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>; grammar <grammarName>;
s : e {<writeln("$e.v")>}; s : e {<writeln("$e.v")>};
e returns [int v] e returns [int v]
@ -14,3 +34,4 @@ INT : '0'..'9'+ ;
INC : '++' ; INC : '++' ;
DEC : '--' ; DEC : '--' ;
WS : (' '|'\n') -> skip ; WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "MultipleAlternativesWithCommonLabel.stg"
Input() ::= "4"
Output() ::= <<
4<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "MultipleAlternativesWithCommonLabel.stg"
Input() ::= "1+2"
Output() ::= <<
3<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "MultipleAlternativesWithCommonLabel.stg"
Input() ::= "1+2*3"
Output() ::= <<
7<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "MultipleAlternativesWithCommonLabel.stg"
Input() ::= "i++*3"
Output() ::= <<
12<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,34 @@
/**
* This is a regression test for antlr/antlr4#509 "Incorrect rule chosen in
* unambiguous grammar".
* https://github.com/antlr/antlr4/issues/509
*/
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Input() ::= "aa"
Rule() ::= "prog"
Output() ::= <<
(prog (statement (letterA a)) (statement (letterA a)) \<EOF>)<\n>
>>
Errors() ::= ""
grammar(grammarName) ::= <<
grammar <grammarName>;
prog
@after {<ToStringTree("$ctx"):writeln()>}
: statement* EOF {};
statement: letterA | statement letterA 'b' ;
letterA: 'a';
>>

View File

@ -1,3 +1,16 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>; grammar <grammarName>;
s : e {<writeln("$e.result")>} ; s : e {<writeln("$e.result")>} ;
e returns [String result] e returns [String result]
@ -8,4 +21,4 @@ e returns [String result]
ID : 'a'..'z'+ ; ID : 'a'..'z'+ ;
INT : '0'..'9'+ ; INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ; WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "PrefixOpWithActionAndLabel.stg"
Input() ::= "a"
Output() ::= <<
a<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "PrefixOpWithActionAndLabel.stg"
Input() ::= "a+b"
Output() ::= <<
(a+b)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "PrefixOpWithActionAndLabel.stg"
Input() ::= "a=b+c"
Output() ::= <<
((a=b)+c)<\n>
>>
Errors() ::= ""

View File

@ -1,3 +1,16 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>; grammar <grammarName>;
s : e {<writeln("$e.v")>}; s : e {<writeln("$e.v")>};
e returns [int v, <StringList()> ignored] e returns [int v, <StringList()> ignored]
@ -9,3 +22,4 @@ e returns [int v, <StringList()> ignored]
INT : '0'..'9'+ ; INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ; WS : (' '|'\n') -> skip ;
>>

View File

@ -1,3 +1,16 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>; grammar <grammarName>;
s : q=e {<writeln("$e.v")>}; s : q=e {<writeln("$e.v")>};
e returns [int v] e returns [int v]
@ -12,3 +25,4 @@ e returns [int v]
ID : 'a'..'z'+ ; ID : 'a'..'z'+ ;
INT : '0'..'9'+ ; INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ; WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActionsAndLabels.stg"
Input() ::= "4"
Output() ::= <<
4<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActionsAndLabels.stg"
Input() ::= "1+2"
Output() ::= <<
3<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActionsAndLabels.stg"
Input() ::= "1+2*3"
Output() ::= <<
7<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActionsAndLabels.stg"
Input() ::= "i++*3"
Output() ::= <<
12<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,36 @@
/**
* This is a regression test for antlr/antlr4#677 "labels not working in
* grammar file".
* https://github.com/antlr/antlr4/issues/677
*
* <p>This test treats {@code ,} and {@code >>} as part of a single compound
* operator (similar to a ternary operator).</p>
*/
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : expr EOF;
expr:
a=expr '*' a=expr #Factor
| b+=expr (',' b+=expr)* '\>>' c=expr #Send
| ID #JustId //semantic check on modifiers
;
ID : ('a'..'z'|'A'..'Z'|'_')
('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;
WS : [ \t\n]+ -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActionsList1.stg"
Input() ::= "a*b"
Output() ::= <<
(s (expr (expr a) * (expr b)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActionsList1.stg"
Input() ::= "a,c>>x"
Output() ::= <<
(s (expr (expr a) , (expr c) \>> (expr x)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActionsList1.stg"
Input() ::= "x"
Output() ::= <<
(s (expr x) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActionsList1.stg"
Input() ::= "a*b,c,x*y>>r"
Output() ::= <<
(s (expr (expr (expr a) * (expr b)) , (expr c) , (expr (expr x) * (expr y)) \>> (expr r)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,34 @@
/**
* This is a regression test for antlr/antlr4#677 "labels not working in
* grammar file".
* https://github.com/antlr/antlr4/issues/677
*
* <p>This test treats the {@code ,} and {@code >>} operators separately.</p>
*/
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : expr EOF;
expr:
a=expr '*' a=expr #Factor
| b+=expr ',' b+=expr #Comma
| b+=expr '\>>' c=expr #Send
| ID #JustId //semantic check on modifiers
;
ID : ('a'..'z'|'A'..'Z'|'_')
('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;
WS : [ \t\n]+ -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActionsList2.stg"
Input() ::= "a*b"
Output() ::= <<
(s (expr (expr a) * (expr b)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActionsList2.stg"
Input() ::= "a,c>>x"
Output() ::= <<
(s (expr (expr (expr a) , (expr c)) \>> (expr x)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActionsList2.stg"
Input() ::= "x"
Output() ::= <<
(s (expr x) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActionsList2.stg"
Input() ::= "a*b,c,x*y>>r"
Output() ::= <<
(s (expr (expr (expr (expr (expr a) * (expr b)) , (expr c)) , (expr (expr x) * (expr y))) \>> (expr r)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActions.stg"
Input() ::= "4"
Output() ::= <<
4<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActions.stg"
Input() ::= "1+2"
Output() ::= <<
3<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActions.stg"
Input() ::= "1+2*3"
Output() ::= <<
7<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "ReturnValueAndActions.stg"
Input() ::= "(1+2)*3"
Output() ::= <<
9<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,29 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Input() ::= "x y z"
Rule() ::= "s"
Output() ::= <<
(s (a (a (a x) y) z))<\n>
>>
Errors() ::= ""
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : a ;
a : a {<True()>}? ID
| ID
;
ID : 'a'..'z'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,31 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Input() ::= "x y z"
Rule() ::= "s"
Output() ::= <<
(s (a (a x) y z))<\n>
>>
Errors() ::= <<
line 1:4 rule a custom message<\n>
>>
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : a ;
a : a ID {<False()>}?\<fail='custom message'>
| ID
;
ID : 'a'..'z'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,21 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : a ;
a : a ID
| ID
;
ID : 'a'..'z'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "Simple.stg"
Input() ::= "x"
Output() ::= <<
(s (a x))<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Simple.stg"
Input() ::= "x y"
Output() ::= <<
(s (a (a x) y))<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "Simple.stg"
Input() ::= "x y z"
Output() ::= <<
(s (a (a (a x) y) z))<\n>
>>
Errors() ::= ""

View File

@ -1,3 +1,16 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>; grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : e EOF ; // must indicate EOF can follow or 'a\<EOF>' won't match s @after {<ToStringTree("$ctx"):writeln()>} : e EOF ; // must indicate EOF can follow or 'a\<EOF>' won't match
e : e '*' e e : e '*' e
@ -8,3 +21,4 @@ e : e '*' e
; ;
ID : 'a'..'z'+ ; ID : 'a'..'z'+ ;
WS : (' '|'\n') -> skip ; WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,30 @@
/**
* This is a regression test for antlr/antlr4#542 "First alternative cannot
* be right-associative".
* https://github.com/antlr/antlr4/issues/542
*/
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : e EOF; // must indicate EOF can follow or 'a\<EOF>' won't match
e :\<assoc=right> e '*' e
|\<assoc=right> e '+' e
|\<assoc=right> e '?' e ':' e
|\<assoc=right> e '=' e
| ID
;
ID : 'a'..'z'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -0,0 +1,9 @@
import "TernaryExprExplicitAssociativity.stg"
Input() ::= "a"
Output() ::= <<
(s (e a) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "TernaryExprExplicitAssociativity.stg"
Input() ::= "a+b"
Output() ::= <<
(s (e (e a) + (e b)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "TernaryExprExplicitAssociativity.stg"
Input() ::= "a*b"
Output() ::= <<
(s (e (e a) * (e b)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "TernaryExprExplicitAssociativity.stg"
Input() ::= "a?b:c"
Output() ::= <<
(s (e (e a) ? (e b) : (e c)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "TernaryExprExplicitAssociativity.stg"
Input() ::= "a=b=c"
Output() ::= <<
(s (e (e a) = (e (e b) = (e c))) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -0,0 +1,9 @@
import "TernaryExprExplicitAssociativity.stg"
Input() ::= "a?b+c:d"
Output() ::= <<
(s (e (e a) ? (e (e b) + (e c)) : (e d)) \<EOF>)<\n>
>>
Errors() ::= ""

Some files were not shown because too many files have changed in this diff Show More