All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.modelcc.language.lexis.TokenBuilder Maven / Gradle / Ivy

Go to download

ModelCC is a model-based parser generator (a.k.a. compiler compiler) that decouples language specification from language processing, avoiding some of the problems caused by grammar-driven parser generators. ModelCC receives a conceptual model as input, along with constraints that annotate it. It is then able to create a parser for the desired textual language and the generated parser fully automates the instantiation of the language conceptual model. ModelCC also includes a built-in reference resolution mechanism that results in abstract syntax graphs, rather than mere abstract syntax trees.

The newest version!
/*
 * ModelCC, distributed under ModelCC Shared Software License, www.modelcc.org
 */

package org.modelcc.language.lexis;


import org.modelcc.language.Builder;
import org.modelcc.language.LanguageException;
import org.modelcc.language.factory.SymbolIdentifier;
import org.modelcc.language.metamodel.LanguageModel;
import org.modelcc.language.metamodel.SimpleLanguageElement;
import org.modelcc.lexer.Token;

/**
 * Token builder.
 *
 * @author Fernando Berzal ([email protected])
 */
public class TokenBuilder extends Builder 
{	
	/**
	 * Constructor
	 * @param model Language model
	 */
	public TokenBuilder (LanguageModel model)
	{
		super(model);
	}
	
	
    /**
     * Instantiates an object given a token.
     * @param t token to be built.
     * @return Instantiated object, null if the object could not be instantiated or the object constraints were not met.
     */
	public Object build (Token t) 
	{
		Object value = t.getValue();
        SymbolIdentifier eid = (SymbolIdentifier)t.getType();
        SimpleLanguageElement element = (SimpleLanguageElement) eid.getElement();

        try {
        	return instantiate(element, value);
        } catch (LanguageException error) {
        	return null;
        }
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy