Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/R.sln → R.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.12
VisualStudioVersion = 15.0.26228.9
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "R", "R\R.vbproj", "{0C2EB77C-39F2-460D-A3F8-CE905F867637}"
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "+Microsoft.VisualBasic.Architecture.Framework", "..\..\..\Source\Repos\sciBASIC\Microsoft.VisualBasic.Architecture.Framework\+Microsoft.VisualBasic.Architecture.Framework.vbproj", "{FECCE1FD-E1D4-49E3-A668-60BB5E7AED99}"
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "+Microsoft.VisualBasic.Architecture.Framework", "..\runtime\sciBASIC#\Microsoft.VisualBasic.Architecture.Framework\+Microsoft.VisualBasic.Architecture.Framework.vbproj", "{FECCE1FD-E1D4-49E3-A668-60BB5E7AED99}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
File renamed without changes.
65 changes: 65 additions & 0 deletions R/Interpreter/SyntaxParser.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Imports System.Runtime.CompilerServices
Imports Microsoft.VisualBasic.Scripting.TokenIcer

Public Module SyntaxParser

Const SyntaxNotSupport$ = "The syntax is currently not support yet!"

''' <summary>
''' Convert the string token model as the language runtime model
''' </summary>
''' <param name="statement"></param>
''' <returns></returns>
<Extension> Public Function Parse(statement As Statement(Of LanguageTokens)) As PrimitiveExpression
Dim expression As PrimitiveExpression = Nothing

If TryParseObjectDeclare(statement, expression) Then
Return expression
ElseIf TryParseTypedObjectDeclare(statement, expression) Then
Return expression
End If

Dim source As New Exception(statement.GetXml)
Throw New SyntaxErrorException(SyntaxNotSupport, source)
End Function

''' <summary>
''' ```R
''' var x &lt;- "string";
''' ```
''' </summary>
''' <param name="statement"></param>
''' <returns></returns>
Public Function TryParseObjectDeclare(statement As Statement(Of LanguageTokens), ByRef out As PrimitiveExpression) As Boolean
Dim tokens = statement.tokens

If Not tokens.First.name = LanguageTokens.var Then
Return False
ElseIf Not tokens(2).name = LanguageTokens.LeftAssign Then
Return False
End If

Dim var$ = tokens(1).Text

End Function

''' <summary>
''' ```R
''' var x as string &lt;- "string";
''' ```
''' </summary>
''' <param name="statement"></param>
''' <returns></returns>
Public Function TryParseTypedObjectDeclare(statement As Statement(Of LanguageTokens), ByRef out As PrimitiveExpression) As Boolean
Dim tokens = statement.tokens

If Not tokens.First.name = LanguageTokens.var Then
Return False
ElseIf Not tokens(2).Text = "as" Then
Return False
End If

Dim var$ = tokens(1).Text

End Function
End Module
2 changes: 1 addition & 1 deletion R/R/TokenIcer.vb → R/Interpreter/TokenIcer.vb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Imports Microsoft.VisualBasic.Emit.Marshal
Imports Microsoft.VisualBasic.Language
Imports Microsoft.VisualBasic.Scripting.TokenIcer
Imports Microsoft.VisualBasic.Text
Imports langToken = Microsoft.VisualBasic.Scripting.TokenIcer.Token(Of R.LanguageTokens)
Imports langToken = Microsoft.VisualBasic.Scripting.TokenIcer.Token(Of SMRUCC.Rsharp.LanguageTokens)

Public Module TokenIcer

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
Binary file added R/R#.ico
Binary file not shown.
30 changes: 24 additions & 6 deletions R/R/R.vbproj → R/R.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0C2EB77C-39F2-460D-A3F8-CE905F867637}</ProjectGuid>
<OutputType>Exe</OutputType>
<StartupObject>R.Module1</StartupObject>
<RootNamespace>R</RootNamespace>
<StartupObject>SMRUCC.Rsharp.Module1</StartupObject>
<RootNamespace>SMRUCC.Rsharp</RootNamespace>
<AssemblyName>R</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>Console</MyType>
Expand Down Expand Up @@ -46,6 +46,9 @@
<PropertyGroup>
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>R#.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand All @@ -68,9 +71,17 @@
<Import Include="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup>
<Compile Include="Interpreter\SyntaxParser.vb" />
<Compile Include="Module1.vb" />
<Compile Include="LangModels.vb" />
<Compile Include="TokenIcer.vb" />
<Compile Include="LanguageTokens.vb" />
<Compile Include="runtime\BindVariable.vb" />
<Compile Include="runtime\Expression\OperatorExpression.vb" />
<Compile Include="runtime\Expression\FunctionExpression.vb" />
<Compile Include="runtime\Expression\LiteralExpression.vb" />
<Compile Include="runtime\Expression\PrimitiveExpression.vb" />
<Compile Include="runtime\TypeCodes.vb" />
<Compile Include="runtime\Variable.vb" />
<Compile Include="Interpreter\TokenIcer.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
Expand Down Expand Up @@ -108,10 +119,17 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Source\Repos\sciBASIC\Microsoft.VisualBasic.Architecture.Framework\+Microsoft.VisualBasic.Architecture.Framework.vbproj">
<Project>{fecce1fd-e1d4-49e3-a668-60bb5e7aed99}</Project>
<ProjectReference Include="..\..\runtime\sciBASIC#\Microsoft.VisualBasic.Architecture.Framework\+Microsoft.VisualBasic.Architecture.Framework.vbproj">
<Project>{FECCE1FD-E1D4-49E3-A668-60BB5E7AED99}</Project>
<Name>+Microsoft.VisualBasic.Architecture.Framework</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="LibraryManager\" />
<Folder Include="StatMachine\" />
</ItemGroup>
<ItemGroup>
<Content Include="R#.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
</Project>
56 changes: 56 additions & 0 deletions R/runtime/BindVariable.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Imports System.Reflection
Imports Microsoft.VisualBasic.Emit.Delegates

''' <summary>
''' ``R#``脚本会通过这个变量对象将包之中的模块变量或者Class之中的共享变量作为一个R的内部变量
''' </summary>
Public Class BindVariable : Inherits Variable

''' <summary>
''' 编译之后所产生的变量值的设置或者获取的过程
''' </summary>
ReadOnly getValue As Func(Of Object), setValue As Action(Of Object)

''' <summary>
''' 这个属性获取的是包之中的模块变量的值
''' </summary>
''' <returns></returns>
Public Overrides Property Value As Object
Get
Return getValue()
End Get
Set(value As Object)
Call setValue(value)
MyBase.Value = value
End Set
End Property

''' <summary>
''' 这个变量对象在运行时环境之中的原来的位置
''' </summary>
''' <returns></returns>
Public ReadOnly Property Source As String

Sub New(field As FieldInfo)
Call Me.New(src:=field)

With field
getValue = StaticFieldGet(.DeclaringType, .Name)
setValue = StaticFieldSet(.DeclaringType, .Name)
End With
End Sub

Private Sub New(src As MemberInfo)
Name = src.Name
Source = src.Source
End Sub

Sub New([property] As PropertyInfo)
Call Me.New(src:=[property])

With [property]
getValue = StaticPropertyGet(.DeclaringType, .Name)
setValue = StaticPropertySet(.DeclaringType, .Name)
End With
End Sub
End Class
3 changes: 3 additions & 0 deletions R/runtime/Expression/FunctionExpression.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Public Class FunctionExpression

End Class
11 changes: 11 additions & 0 deletions R/runtime/Expression/LiteralExpression.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Imports Microsoft.VisualBasic.Scripting.TokenIcer

''' <summary>
''' 数字,字符串,逻辑值之类的值表达式,也可以称作为常数
''' </summary>
Public Class LiteralExpression : Inherits PrimitiveExpression

Sub New(token As Token(Of LanguageTokens))

End Sub
End Class
6 changes: 6 additions & 0 deletions R/runtime/Expression/OperatorExpression.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
''' <summary>
''' Logical and arithmetic expression
''' </summary>
Public Class OperatorExpression

End Class
6 changes: 6 additions & 0 deletions R/runtime/Expression/PrimitiveExpression.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
''' <summary>
''' The very base expression in the R# language
''' </summary>
Public Class PrimitiveExpression

End Class
Loading