I'm trying to create an ANTLR 4 grammar to understand this code:
package main () {
name1;
name2;
}
Here is what I have so far:
grammar Crimson;
// Parser rules
program
: packageDefinitionList EOF
;
packageDefinitionList
: packageDefinition
;
packageDefinition
: Package Identifier parameterList packageBody
;
parameterList
: parameter*
;
parameter
: parameterType Identifier
;
packageBody
: statement*
;
parameterType
: Integer | Boolean
;
statement
: Identifier
;
// Lexer rules
Package
: 'package'
;
Integer
: 'int'
;
Boolean
: 'bool'
;
Identifier
: NonDigit
;
fragment NonDigit
: [a-zA-Z_]
;
CodePudding user response:
Hmm alright I guess the website was having a bad day? Maybe the versions are incompatible or something...
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug ANTLR4 grammar",
"type": "antlr-debug",
"request": "launch",
"input": "Crimson\\CSharp\\Antlr\\test.crm",
"grammar": "Crimson\\CSharp\\Antlr\\crimson.g4",
"startRule": "program",
"printParseTree": true,
"visualParseTree": true
}
]
}
CodePudding user response:
I believe that your example is valid (although missing whitespace rule and others) and I looked at the JSON result from my antlr server and it does, in fact, yield an incorrect bit of JSON. I created a bug for you: