Skip to content

Commit

Permalink
feat: <core> setup c ident
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 3, 2020
1 parent 9f5761d commit 1678a24
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 deletions chapi-ast-c/src/main/kotlin/chapi/ast/cast/CIdentApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package chapi.ast.cast

import chapi.ast.antlr.CLexer
import chapi.ast.antlr.CParser
import org.antlr.v4.runtime.CharStreams
import org.antlr.v4.runtime.CommonTokenStream
import org.antlr.v4.runtime.tree.ParseTreeWalker

open class CIdentApp() {
open fun Analysis(Str: String) {
val context = this.Parse(Str).compilationUnit()
val listener = CIdentListener()

ParseTreeWalker().walk(listener, context)

listener.getNodeInfo()
}

open fun Parse(Str: String): CParser {
val fromString = CharStreams.fromString(Str)
val tokenSource = CLexer(fromString)
val commonTokenStream = CommonTokenStream(tokenSource)
val parser = CParser(commonTokenStream)
return parser
}

}
14 changes: 14 additions & 0 deletions chapi-ast-c/src/main/kotlin/chapi/ast/cast/CIdentListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package chapi.ast.cast

import chapi.ast.antlr.CBaseListener
import chapi.ast.antlr.CParser

open class CIdentListener() : CBaseListener() {
override fun enterFunctionDefinition(ctx: CParser.FunctionDefinitionContext?) {
super.enterFunctionDefinition(ctx)
}

fun getNodeInfo() {

}
}
18 changes: 18 additions & 0 deletions chapi-ast-c/src/test/kotlin/chapi/ast/cast/CIdentAppTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package chapi.ast.cast

import org.junit.jupiter.api.Test

import org.junit.jupiter.api.Assertions.*

internal class CIdentAppTest {
@Test
fun shouldAnalysis() {
val helloWorld = """
main()
{
printf("Hello World");
}
"""
CIdentApp().Analysis(helloWorld)
}
}

0 comments on commit 1678a24

Please # to comment.