Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey guys,

i am making my programming language and i have the ability to write and set variables. one more thing that i would like to add is 'if' statements. my programming language script is now this:

VB
Imports System
Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox2.Text = TextBox2.Text & String.Empty
        For Each a As String In TextBox1.Text.Split(ControlChars.Lf)
            If a.StartsWith("vw ") Then
                TextBox2.Text &= IIf(String.IsNullOrEmpty(TextBox2.Text), _
                    String.Empty, vbCrLf) & System.Text.RegularExpressions.Regex.Match( _
                    TextBox1.Text, String.Format("(?<=vs {0},).*", a.Substring(3)), _
                    RegexOptions.CultureInvariant).Value
            End If
        Next
    End Sub
End Class


and the grammar is:

function operation1,operation2,operation3
| vs name,value
| vw name
| if value,expression,statement endif

vs = variable set
vw = variable write
if = if statement

in other words, the if statement if like if value = expression do statement. but i cut out the '=' sign and the 'do' word and replaced them with commas. can someone please give me an updated version of my code that has that if statement?
Posted

1 solution

For comparing value = expression, the expression is to be evaluated, as it may contain operators.
I think this Code Project article may be helpful to evaluate the expression
An expression evaluator written in VB.NET[^]
After evaluating the expression, let us say the result is expressionResult. Now the Value can be compared as below
If Value = expressionResult Then
'Do Some thing.
Again if the statement, is something to be instantiated or run then, System.Reflection, Process etc. are to be used.
 
Share this answer
 
Comments
Member 8378691 15-Apr-12 0:04am    
thanks for this link. i will try it out but seeing as though its you that told gave me this link, i am sure it will be a great help.
VJ Reddy 15-Apr-12 0:19am    
You're welcome and Thank you.
Member 8378691 15-Apr-12 0:32am    
i just looked at the source code and for once, i understand most of it. i have looked and studies programming language source codes for programming languages similar to the GfnCompiler and after a couple months, i starts to understand and write in that manner. i think that helps me to read this. this is really good and i will study the code and make my programming language like this. i am going away for a week from tomorrow so you wont here from me for a while. but you have and hopefuly be a good help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900