Closed archanox closed 2 months ago
https://github.com/antlr/antlr4
grammar RGBDS; // Lexer rules NUMBER: [0-9]+; IDENTIFIER: [a-zA-Z_][a-zA-Z0-9_]*; COMMENT: ';' ~[\r\n]* -> skip; WHITESPACE: [ \t\r\n]+ -> skip; // Assembly instructions and directives opcode: IDENTIFIER; // Labels label: IDENTIFIER ':'; // Instructions instruction: opcode (NUMBER | IDENTIFIER)?; // Main entry point statement: label? instruction?; // Parsing multiple statements program: statement+;
using Antlr4.Runtime; using System; class Program { static void Main(string[] args) { string input = @" label1: nop ld a, 5 "; AntlrInputStream inputStream = new AntlrInputStream(input); RGBDSLexer lexer = new RGBDSLexer(inputStream); CommonTokenStream tokenStream = new CommonTokenStream(lexer); RGBDSParser parser = new RGBDSParser(tokenStream); RGBDSParser.ProgramContext context = parser.program(); Console.WriteLine(context.ToStringTree(parser)); } }
Yeah nah. Requires Java...
https://github.com/antlr/antlr4