Skip to content

buddy-compiler/FeGen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FeGen: a Python-embedded DSL and a framework for rapid prototyping DSL Compiler

FeGen is designed to bridge syntax definition and MLIR code generation. It enables developers to define both grammatical rules and semantic bindings within FeGen DSL, streamlining the process of prototype compiler construction.

This repository shows the implementation of FeGen.

How to use?

  1. Define Your Grammar Class
from FeGen import *

class MyGrammar(FeGenGrammar):
    def __init__(self):
        super().__init__()
  1. Add Lexer and Parser Methods to Your Class
    @lexer
    def Number(self):
        """
        Number ::= [1-9][0-9]*|[0-9]
        """
        return newTerminalRule(regular_expr("[1-9][0-9]*|[0-9]"))
      
    ...
    
    @parser
    def module(self):
        """
        module: structDefine* funcDefine+
        """
        r_one_or_more = one_or_more(self.function_definition(), self.NEWLINE()) 
        r = newParserRule(r_one_or_more)
        funcs = r_one_or_more.get_attr("funcop", flatten=True)
        self.themodule = builtin.ModuleOp(funcs) # xDSL
        return r
    ...
  1. Create Instance and Get Start
...
g = MyGrammar()
mylexer = g.lexer()
myparser = g.parser(mylexer, start="module")
cstroot = myparser.parse(code)
cstroot.visit()
themodule = g.themodule
...

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published