-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
chapi-ast-c/src/main/kotlin/chapi/ast/cast/CIdentListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
chapi-ast-c/src/test/kotlin/chapi/ast/cast/CIdentAppTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |