You can get started to ModelCC in a few very easy steps. Downloading ModelCC
Setting up ModelCC in a NetBeans Project(If you are not planning on using ModelCC in NetBeans, you may skip this section.) Whenever you want to use ModelCC in a NetBeans project, you have to add the ModelCC library to it.
(If you are not planning on using ModelCC in Eclipse, you may skip this section.) Whenever you want to use ModelCC in an Eclipse project, you have to add the ModelCC library to it.
The following class describes a very simple language. The entity MySimpleLanguage is a lexical entity that consists of an integer value, which is deducted from the @Value annotation that is assigned to an int data type. Any integer number pertains to this language. // import org.modelcc.*; public class MySimpleLanguage implements IModel { @Value private int data; public int getData() { return data; } } // Generating and Using a Parser for the Example Language ModelThe following example class describes the usage of ModelCC. A model is read from the language class, a parser is generated from the model, and the parser is used to parse an input string. // import org.modelcc.io.java.JavaModelReader; import org.modelcc.metamodel.Model; import org.modelcc.parser.fence.adapter.FenceParserGenerator; import org.modelcc.parser.Parser; public class MySimpleProgram { public static void main(String args[]) { try { // Read the language model. Model m = JavaModelReader.read(MySimpleLanguage.class); // Generate a parser from the model. Parser<MySimpleLanguage> parser = FenceParserGenerator.create(m); // Parse an input string. MySimpleLanguage result = parser.parse("35"); // Produce output. if (result != null) System.out.println(result.getData()); else System.out.println("Invalid string."); } catch (Exception e) { e.printStackTrace(); } } } // For more information, read the complete ModelCC User Manual. |