Poll

What method would you prefer to translate BASIC to a cross platform binary executable.

Daniel's uCalc Transform --> C++
1 (33.3%)
ScriptBasic --> Nimrod --> C (project abandoned by John)
0 (0%)
Nimrod --> C
0 (0%)
Python --> Nimrod --> C
1 (33.3%)
C BASIC (Charles Pegge's BASIC wrapper for C)
1 (33.3%)
Other (post your idea)
0 (0%)

Total Members Voted: 2

Author Topic: BAS2NIM  (Read 45969 times)

kryton9

  • Guest
Re: BAS2NIM
« Reply #45 on: October 14, 2013, 06:39:52 PM »
Hmmmm, I wonder if the labels for goto's need the : afterwards. The line number didn't in your code John.
Will have to try that out.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #46 on: October 14, 2013, 06:49:32 PM »
In ScriptBasic line numbers are labels. SB allow a special type of line number label that allows code to follow without the : to emulate old school BASIC. Any other label requires the : label designator.

kryton9

  • Guest
Re: BAS2NIM
« Reply #47 on: October 14, 2013, 10:36:20 PM »
Thanks for the clarification!

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #48 on: October 14, 2013, 11:14:44 PM »
I have created this thread specifically as a shared effort to get a functional traditional BASIC to Nimrod translator working using the keyword list below. (the list might change slightly if we missed something to make this micro-BASIC language functional) Think of this as a code challenge if you wish. Each member here on All BASIC that would like to participate should create a workspace post. Use that post for your project and the already existing BAS2NIM thread for discussions. I'm going to write my attempt in ScriptBasic. If Daniel would like to show off his uCalc Transform tool, this would be a great time for it. If other members have a better way / language to accomplish the task, please show us.

  • DIM
  • FOR
  • NEXT
  • IF  (single line IF/THEN/ELSE)
  • WHILE
  • WEND
  • LET (required)
  • GOTO
  • GOSUB
  • RETURN
  • PRINT
  • END
  • ASC
  • VAL
  • STR
  • MID
  • LEFT
  • INSTR
  • UCASE
  • LCASE
  • UBOUND
  • LBOUND

« Last Edit: October 16, 2013, 12:41:56 PM by John »

kryton9

  • Guest
Re: BAS2NIM
« Reply #49 on: October 15, 2013, 12:56:25 PM »
Oh wow John, you are now 2 steps ahead of me. I am going to finish my end today to see the magic your code will do.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #50 on: October 15, 2013, 01:20:11 PM »
Quote
Oh wow John, you are now 2 steps ahead of me. I am going to finish my end today to see the magic your code will do.

Sounds great Kent. Looking forward to see it work.


Daniel Corbier

  • Guest
Re: BAS2NIM
« Reply #51 on: October 15, 2013, 07:04:24 PM »
I just released uCalc Transform just moments ago.  Sorry for the delay in response.  I plan to take a look at this thread & other messages and get back with everybody tomorrow.  I'm interested in this project.

kryton9

  • Guest
Re: BAS2NIM
« Reply #52 on: October 16, 2013, 01:23:52 PM »
I will put all my latest code and files here at the end of the day from the https://c9.io/scriptbasic/nimrod site.

Running and using instructions:
Files with .sb extension from the linux command line scriba filename.sb
Files with .bas extension, these are just for viewing via any editor of various basic tests.
Files with .nim extenstion, these are Nimrod source files. Here is how to compile from
the command line.
nimrod c test.nim                       this compiles, but full of debug info.
./test                                          this runs the executable in linux, if compiled on it.
nimrod c -d:release test.nim      this compiles to a nice small release version.

my stuff is under: projects/Kent

update date: 10/18/2013

There are 3 projects regarding basic to nimrod in my folder.
Each project is in its own sub-folder.

These are starts to give BASIC users and developers a
possible start to working in and with Nimrod.

Folder basic:
    This is just a start of a simple basic module
    to use from within Nimrod.
   
    basic.nim: this is the source code for the
    basic module.
   
    test.nim: this is Nimrod code written in Basic,
    using the basic module.
   
   
Folder sb2nim:
    This is trying to do a side by side comparison
    of Basic and Nimrod. The basic used on the
    right-side is ScriptBasic. The left side
    is one of the ways to do the similar thing
    in Nimrod.
   
    sb2nim.nim: is the Nimrod source with the 2 languages.
   
 Folder test-john-stuff
    This is adding to the code started by John
    in his folder: John and filename: bas2nim.sb
    It is written in ScriptBasic and is acting
    as the start of a translator.
   
    b2nV2.sb: this is my additions to John's code.
   
    test2.bas: a simple basic program example
                     to use for testing.
       
    test2.nim: this is the output from running b2nV2.sb
                     it is the generated translated Nimrod code.
« Last Edit: October 18, 2013, 12:17:42 AM by kryton9 »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #53 on: October 16, 2013, 03:49:14 PM »
It isn't much but it does prove the concept works.

ScriptBasic BAS2NIM translator
Code: [Select]
' BAS2NIM - ScriptBasic
' Last Update: 2013-10-15
' Contributors: John Spikowski & Kent Sarikaya

' BASIC keyword dictionary

keywords{"DIM"}[0]=ADDRESS(Convert_DIM())
keywords{"FOR"}[0]=ADDRESS(Convert_FOR())
keywords{"NEXT"}[0]=ADDRESS(Convert_NEXT())
keywords{"IF"}[0]=ADDRESS(Convert_IF())
keywords{"WHILE"}[0]=ADDRESS(Convert_WHILE())
keywords{"WEND"}[0]=ADDRESS(Convert_WEND())
keywords{"LET"}[0]=ADDRESS(Convert_LET())
' keywords{"GOTO"}[0]=ADDRESS(Convert_GOTO())
' keywords{"GOSUB"}[0]=ADDRESS(Convert_GOSUB())
' keywords{"RETURN"}[0]=ADDRESS(Convert_RETURN())
keywords{"PRINT"}[0]=ADDRESS(Convert_PRINT())
keywords{"END"}[0]=ADDRESS(Convert_END())
keywords{"ASC"}[0]=ADDRESS(Convert_ASC())
keywords{"VAL"}[0]=ADDRESS(Convert_VAL())
keywords{"STR"}[0]=ADDRESS(Convert_STR())
keywords{"MID"}[0]=ADDRESS(Convert_MID())
keywords{"LEFT"}[0]=ADDRESS(Convert_LEFT())
keywords{"LEFT"}[0]=ADDRESS(Convert_INSTR())
keywords{"UCASE"}[0]=ADDRESS(Convert_UCASE())
keywords{"LCASE"}[0]=ADDRESS(Convert_LCASE())
keywords{"UBOUND"}[0]=ADDRESS(Convert_UBOUND())
keywords{"LBOUND"}[0]=ADDRESS(Convert_LBOUND())


' BASIC Directives

SUB Convert_DIM
END SUB

SUB Convert_FOR
  IF BASIC LIKE "FOR * = * TO *" THEN
    expr[1] = JOKER(1)
    expr[2] = JOKER(2)
    expr[3] = JOKER(3)
    ' Translate
    PRINT Nimrod
  ELSE IF BASIC LIKE "FOR * = * TO * STEP *" THEN
    expr[1] = JOKER(1)
    expr[2] = JOKER(2)
    expr[3] = JOKER(3)
    expr[4] = JOKER(4)
    ' Translate
    PRINT Nimrod
  ELSE
    END
  END IF 
END SUB

SUB Convert_NEXT
END SUB

SUB Convert_IF
END SUB

SUB Convert_WHILE
END SUB

SUB Convert_WEND
END SUB

SUB Convert_LET
  IF BASIC LIKE "LET *" THEN
    PRINT "var ", JOKER(1), "\n"
  ELSE
    END
  END IF
END SUB

' SUB Convert_GOTO
' END SUB

' SUB Convert_GOSUB
' END SUB

' SUB Convert_RETURN
' END SUB

SUB Convert_PRINT
  IF BASIC LIKE "PRINT *" THEN
    PRINT "stdout.write(", JOKER(1), ")\n"
  ELSE
    END
  END IF
END SUB

SUB Convert_END
END SUB


' BASIC Functions

SUB Convert_ASC
 
END SUB

SUB Convert_VAL
END SUB

SUB Convert_STR
END SUB

SUB Convert_MID
END SUB

SUB Convert_LEFT
END SUB

SUB Convert_INSTR
END SUB

SUB Convert_UCASE
END SUB

SUB Convert_LCASE
END SUB

SUB Convert_UBOUND
END SUB

SUB Convert_LBOUND
END SUB


' MAIN

filename_argument = COMMAND()
OPEN filename_argument FOR INPUT AS #1
WHILE NOT(EOF(1))
  LINE INPUT #1, BASIC
  BASIC = CHOMP(BASIC)
  sp = INSTR(BASIC, " ")
  test_keyword = LEFT(BASIC, sp -1)
  IF keywords{test_keyword}[0] <> undef THEN
    success = ICALL(keywords{test_keyword}[0])
  ELSE
    END
  END IF
WEND

First BASIC program
Code: [Select]
LET A = "Hello BAS2NIM"
PRINT A,"\n"

jrs@laptop:~/bas2nim$ scriba bas2nim.sb firstpgm.bas
var A = "Hello BAS2NIM"
stdout.write(A,"\n")
jrs@laptop:~/bas2nim$ scriba bas2nim.sb firstpgm.bas > t_nim02.nim
jrs@laptop:~/bas2nim$ nimrod c t_nim02.nim
config/nimrod.cfg(36, 11) Hint: added path: '/home/jrs/.babel/libs/' [Path]
Hint: used config file '/home/jrs/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: t_nim02 [Processing]
gcc -c -w -I/home/jrs/nimrod/lib -o /home/jrs/bas2nim/nimcache/t_nim02.o /home/jrs/bas2nim/nimcache/t_nim02.c
gcc   -o /home/jrs/bas2nim/t_nim02  /home/jrs/bas2nim/nimcache/system.o /home/jrs/bas2nim/nimcache/t_nim02.o  -ldl
Hint: operation successful (7440 lines compiled; 0.236 sec total; 12.122MB) [SuccessX]
jrs@laptop:~/bas2nim$ ./t_nim02
Hello BAS2NIM
jrs@laptop:~/bas2nim$

Code: [Select]
LET A = "Hello BAS2NIM"
PRINT A

jrs@laptop:~/bas2nim$ scriba bas2nim.sb firstpgm.bas
var A = "Hello BAS2NIM"
stdout.write(A)
jrs@laptop:~/bas2nim$ scriba bas2nim.sb firstpgm.bas > t_nim02.nim
jrs@laptop:~/bas2nim$ nimrod c t_nim02.nim
config/nimrod.cfg(36, 11) Hint: added path: '/home/jrs/.babel/libs/' [Path]
Hint: used config file '/home/jrs/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: t_nim02 [Processing]
gcc -c -w -I/home/jrs/nimrod/lib -o /home/jrs/bas2nim/nimcache/t_nim02.o /home/jrs/bas2nim/nimcache/t_nim02.c
gcc   -o /home/jrs/bas2nim/t_nim02  /home/jrs/bas2nim/nimcache/system.o /home/jrs/bas2nim/nimcache/t_nim02.o  -ldl
Hint: operation successful (7440 lines compiled; 0.242 sec total; 12.122MB) [SuccessX]
jrs@laptop:~/bas2nim$ ./t_nim02
Hello BAS2NIMjrs@laptop:~/bas2nim$

« Last Edit: October 16, 2013, 08:26:24 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #54 on: October 16, 2013, 08:55:37 PM »
Quote
# undef is not supported in Nimrod yet
# can't figure out how to do this in Nimrod, if possible
# to mix and leave entries in arrays empty as in SB

ScriptBasic is typeless and requires no setup of variables to use them. If you try to access a variable that hasn't been assigned, you will get an undef. ScriptBasic also has an undef function that returns a variable to it's unassigned state. This is a SB thing and you shouldn't waste your time trying to emulate it. We aren't writing a ScriptBasic to C (via Nimrod) translator, SB already compiles to C.

All variables being passed through the translator should be declared. I would still like to use PBCC 5 as the target first BASIC.

« Last Edit: October 16, 2013, 08:58:01 PM by John »

Daniel Corbier

  • Guest
Re: BAS2NIM
« Reply #55 on: October 16, 2013, 08:59:24 PM »
Version 2.0 now includes a directory full of PowerBASIC snippets, many of which are actually applicable to any kind of BASIC dialect.  Of particular interest, you may want to look at files like ImplicitDim.uc or PrettyBas.uc to see how it handles keywords.  They basically use the public domain keyword list I downloaded from PB.  This line, in one step, opens the file, and creates a regular expression that handles all the keywords of that file.  Check out those examples in the download to see how they work in context.

Code: [Select]
{@Eval: "{'"+Retain(FileText("PBKeywords.txt"), "{keyword:'[a-z0-9_]+'}", Delim("\b|"))+"\b'}"}
Also note how many of the transforms use the {@Eval: } construct, which lets you dynamically compute things you can add to the text.

BTW, when I click on the c9.io link I just get a blank page.


Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #56 on: October 16, 2013, 09:07:28 PM »
Quote
BTW, when I click on the c9.io link I just get a blank page.

It was setup as a private workspace. Public workspaces are viewable to anyone but need permission for write and terminal access. Just request R/W access and I'll approve you and you will have full rights as we do.

Let me know what Cloud9 IDE user name you're using if it isn't obvious.

« Last Edit: October 16, 2013, 09:11:42 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #57 on: October 16, 2013, 09:42:30 PM »
ImplicitDim.bas
Code: [Select]
Global MyGlobal_A As Long, MyGlobal_B As Dword

Function MyFunction(x, y, z) As Long
   Dim MyString As String, abcd As Long

   Print x, y, z
   Print a, b, c
   Print MyGlobal_A, MyGlobal_B
   Print MyString, abcd
   
   Function = Len(MyString)
End Function

Sub MySub(ByRef Arg_A As Extended, ByVal Arg_B As Long, ByVal Arg_C!)
   Dim MyLocal_A As String, MyLocal_B As Long

   Print Implicit_X, Implicit_Y, Implicit_Z
   Print Arg_A, Arg_B, Arg_C!
   Print MyGlobal_A, MyGlobal_B
   Print MyLocal_A, MyLocal_B
End Function

ImplicitDim.uc
Code: [Select]
# ImplicitDim.uc - uCalc Transformation file
# This file was saved with uCalc Transform 2.0 on 10/15/2013 7:08:31 PM
# Comment: Declares variables (with Dim) that were not explicitely declared before

ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, OutputFile, BatchAction, SEND
ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle
ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique

FindMode: Replace

# Definitions


# Search Criteria

Criteria: 0
Enabled: True
Exclude: False
Comment: Declares variables (with Dim) that were not explicitely declared before
Selected: False
Highlight: False
ForeColor: ControlText
BackColor: Aqua
FontName:
FontSize:
FontStyle:
CaseSensitive: False
QuoteSensitive: True
CodeBlockSensitive: True
FilterEndText:
FilterSeparator: {#10}
FilterSort: False
FilterSortFunc:
FilterStartText:
FilterUnique: False
Min: 0
Max: -1
MinSoft: 0
MaxSoft: -1
BatchAction: Transform
OutputFile:
SEND:
StartAfter: 0
StopAfter: -1
SkipOver: False
ParentChild: 0
Pass: 0
PassOnce: True
Precedence: 0
RightToLeft: False

Criteria: 1
Find:
Replace: {@Define:: Token: \x27.* ~~ Properties: ucWhitespace}
         {@Eval: Dim Globals As Table, CurrentRoutine As String}

Criteria: 2
Comment: Teporarily adds Dim keyword in front of args for further parsing
Pass: 1

Criteria: 3
Selected: True
Find: {nl}{routine: Sub | Function } {etc}({args})
Replace: {nl}{routine} {etc}(Dim {args})

Criteria: 4
SkipOver: True
Find: {nl}Function =
Replace: [Skip over]

Criteria: 5
Comment: Inserts explicitly Dimmed variable names in global or local tables
Pass: 2

Criteria: 6
Find: Global {variable:1}
Replace: {Self}{@Eval: Insert(Globals, "{variable}")}

Criteria: 7
BackColor: Silver
Find: { {nl}{ Macro | Type | Union | % | $ | Declare {func:1} } | . | @ } {name:1}
Replace: {Self}{@Eval: Insert(Globals, "{name}")}

Criteria: 8
BackColor: Lime
Find: {nl}{ Sub | Function }{" +"}{RoutineName:"[a-z0-9_]+"}
Replace: {Self}{@Define:
            Var: {RoutineName}ExplicitDim As Table
            Var: {RoutineName}ImplicitDim As Table
         }{@Eval: SetVar(CurrentRoutine, "{RoutineName}"); Insert(Globals,"{RoutineName}")}

Criteria: 9
BackColor: Pink
Find: {declare: Dim [[Optional] { ByVal | ByRef }] | Local | Static } {variable:1}
Replace: {Self}{@Eval: Insert(~Eval(CurrentRoutine)ExplicitDim, "{variable}")}

Criteria: 10
Comment: Temporarily inserts declaration for each individual variable a lines with a list of multiple vars, for easier parsing
BackColor: SlateBlue
PassOnce: False
Find: {declare: Global | Dim | Local | Static } {variable},
Replace: {declare} {variable} :: {declare}

Criteria: 11
Comment: Places non-Dimmed variable names in separate local tables
Pass: 3

Criteria: 12
Find: {variable:"[a-z][a-z0-9_]*"}
Replace: {Self}{@Eval:
            IIf(Handle(Globals, "{variable}")==0 And Handle(~Eval(CurrentRoutine)ExplicitDim, "{variable}")==0,
                Insert(~Eval(CurrentRoutine)ImplicitDim, "{variable}"); "")
         }

Criteria: 13
SkipOver: True
Find: {@Eval: "{'"+Retain(FileText("PBKeywords.txt"), "{keyword:'[a-z0-9_]+'}", Delim("\b|"))+"\b'}"}
Replace: [Skip over]

Criteria: 14
BackColor: Brown
Find: {"\n"}{ Sub | Function }{" +"}{RoutineName:"[a-z0-9_]+"}
Replace: {Self}{@Eval: SetVar(CurrentRoutine, "{RoutineName}")}

Criteria: 15
Comment: Inserts local Dim statements for variables that were not dimmed
Pass: 4

Criteria: 16
BackColor: Purple
Find: {nl}{ Sub | Function }{" +"}{RoutineName:"[a-z0-9_]+"} {etc}
Replace: {Self}
            Dim {@Eval: Range(1, Count({RoutineName}ImplicitDim), "ReadKey({RoutineName}ImplicitDim, x)", Delim(", "))} ' Implicit

Criteria: 17
Comment: Clean up (temp declaration statements removed)
Pass: 5

Criteria: 18
BackColor: Violet
Find: :: {declare:1}
Replace: ,

Criteria: 19
BackColor: CornflowerBlue
Find: (Dim {args})
Replace: ({@Eval: Replace("{args}", ":: Dim", ",")})

Criteria: 20
Find: Dim {nl}
Replace: {Nothing}

# End Search

PrettyBas.bas
Code: [Select]
' The source code below is intentionally formatted incorrectly.
' PrettyBas.uc will correct spacing & indentation and will add color.
' There are two ways to test PrettyBas.uc with this file:
' A. Right-click this file from within uCalc and select:
'      Open With Indentation/Color
'      (In this case \PrettyBas.uc from the .\Transforms\ directory is used
       and is part of the setup defined in .\FileTypes\Bas)
' B. To fiddle with the transform interactively click the folder button
     and choose PrettyBas.uc as a transform:
'    (In this case \PrettyBas.uc from the .\Examples\PowerBASIC\ directory is used)

#Compile Exe
#Dim All
   #Include "Win32API.inc" ' Includes the API for Windows

Type MyType ' These will be indented properly
 x As Long
   abc As Long
     xyz As Long
   Something As Long
  Other As Long
  End Type

Function TEST(ByVal num As Long, MyStr As String  ,   xyz As Long) As Dword ' Just a test
   Dim x As Long  ,y As Long, value&, t!

   t! = Timer

  ! FNCLEX  ; some random ASM
! MOV AX  ,   "xy"
! MOV EAX, value&

For X = 1 To 10 ' The indentation will take care of this nested code
For Y =   2 To 20
  If x =  1 Then y=2

  If x= 5 Then
      If Y = X Then Print "Testing 'testing' 123" ' Just testing
      value& = value& + 1      *x   * xyz   -5^ 2
    If MyStr = "Something ""or"" other" Then   value& =Len(MyStr)*2
   End If
Next
 Print Timer-t!
Next

Function = 123+Len(MyStr)+num  /2
End Function

Function PBMain () As Long
   Dim x As Long  ,y As Long, z As String, FileNumber As Long

FileNumber = FreeFile
  Open "c:\test\kjv10.txt" For Binary As #FileNumber

If Lof(#FileNumber) > 1000 Then ' big enough
While Rnd() < .25
For x= 1 To 10
Print Test(x +123   ,"abc xyz",123)
 For y = 1 To 10 : Print  x, y: Next
   While Rnd()*10 < 5 :Print y    : Wend
Next
 Wend
 End If

Data "One","Two", "Three"  ,   "Four", 5 ,6 , 7, 8
End Function

PrettyBas.uc
Code: [Select]
# PrettyBas.uc - uCalc Transformation file
# This file was saved with uCalc Transform 1.9 on 10/13/2013 2:21:39 PM
# Comment: Adds color and indentation to BASIC source code

ExternalKeywords: Exclude, Comment, Selected, ParentChild, FindMode, OutputFile, BatchAction, SEND
ExternalKeywords: Highlight, ForeColor, BackColor, FontName, FontSize, FontStyle
ExternalKeywords: FilterEndText, FilterSeparator, FilterSort, FilterSortFunc, FilterStartText, FilterUnique

FindMode: Replace

# Definitions


# Search Criteria

Criteria: 0
Enabled: True
Exclude: False
Comment: Adds color and indentation to BASIC source code
Selected: False
Highlight: False
ForeColor: ControlText
BackColor: Transparent
FontName:
FontSize:
FontStyle:
CaseSensitive: False
QuoteSensitive: True
CodeBlockSensitive: False
FilterEndText:
FilterSeparator: {#10}
FilterSort: False
FilterSortFunc:
FilterStartText:
FilterUnique: False
Min: 0
Max: -1
MinSoft: 0
MaxSoft: -1
BatchAction: Transform
OutputFile:
SEND:
StartAfter: 0
StopAfter: -1
SkipOver: False
ParentChild: 0
Pass: 0
PassOnce: False
Precedence: 0
RightToLeft: False

Criteria: 1
BackColor: CornflowerBlue
Find: {@Note:                  == Explanation ==
        This section here, enlcosed within {@Note: ...} represents a comment.
         
        Preliminary items are defined on the right in preparation for
        transformation operations below.
     
        {@Define: ...} with one colon defines things in the "Evaluation" space,
        which is kept separate from the space of text being parsed.
     
        {@Define:: ...} (2 colons) defines things in the space of text being
        parsed.  Alphanumeric tokens are redefined to support PB prefixes/suffixes.
      }
Replace: {@Define:
            Var: Indentation = 0
            Const: IndentSize = 3
         
            Inline: {indent+}      := Indentation += IndentSize
            Inline: {indent-}      := Indentation -= IndentSize
            Inline: {indent}       := " " * Indentation
         }
         
         {@Define:: Include: PBTokens.uc}

Criteria: 2
Comment: Adds indentation
Pass: 1

Criteria: 3
Selected: True
Find: {@Start}
Replace: {@Eval: Indentation = 0}

Criteria: 4
Comment: {nl} represents New Line (defined as such in Patterns.uc), and {etc} is just a pattern variable
PassOnce: True
Find: {nl}{etc}
Replace: {nl}{indent}{etc}

Criteria: 5
Comment: Indents tag then increments indentation
PassOnce: True
Find: {nl}{StartWord: Type | Union | For | If | Do | While | Macro | Sub | Function | Select}
Replace: {nl}{indent}{StartWord}{indent+}

Criteria: 6
PassOnce: True
Find: {nl}{MiddleWord: Else | ElseIf | Case}
Replace: {nl}{indent-}{indent}{MiddleWord}{indent+}

Criteria: 7
Comment: Indents end-tag then decrements indentation
PassOnce: True
Find: {nl}{EndWord: End | Next | Loop | Wend }
Replace: {nl}{indent-}{indent}{EndWord}

Criteria: 8
PassOnce: True
Find: {nl}{SameLine: For | Do | While } {etc} :
Replace: {nl}{indent}{SameLine} {etc} :

Criteria: 9
Comment: Doesn't increase indentation for single-line If statement
PassOnce: True
Find: {nl}If {cond} { Then | Goto} {Space:"[ ]+"} {SameLine:"[^'\r\n]"}
Replace: {nl}{indent}If {cond} Then {SameLine}

Criteria: 10
PassOnce: True
Find: {nl}{Other: Function = | Macro {def} = }
Replace: {nl}{indent}{Other}

Criteria: 11
Comment: Adds color
Pass: 2

Criteria: 12
Comment: Adds color to value within quotes
Highlight: True
ForeColor: Brown
PassOnce: True
Find: {QuotedText:"[\q][^\q]*[\q]"}
Replace: {QuotedText}

Criteria: 13
Comment: {@Eval: ...} is replaced with ! | #Bloat | #Compile | #Compiler | #Debug | ...
Highlight: True
ForeColor: Blue
PassOnce: True
Find: {Keyword: {@Eval: Retain(Remove(FileText("PBKeywords.txt"), "{'\x27'}"), "{'.*'}", Delim(" | ")) } }
Replace: {Keyword}

Criteria: 14
Highlight: True
ForeColor: Green
PassOnce: True
Find: {Comment:"'.*"}
Replace: {Comment}

Criteria: 15
Highlight: True
ForeColor: Red
PassOnce: True
Find: ! {ASM}
Replace: ! {ASM}

Criteria: 16
Comment: Normalizes spacing between arithmetic symbols like +, -, *, etc.
ForeColor: Black
PassOnce: True
Find: [{"[ ]+"}] {Symbol:"[\=\:\+\-\*\^\\\/]"} [{"[ ]+"}]
Replace: {sp}{Symbol}{sp}

Criteria: 17
Comment: Normalizes spacing around commas
ForeColor: Black
PassOnce: True
Find: {Comma:" *, *"}
Replace: ,{sp}

# End Search

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: BAS2NIM
« Reply #58 on: October 16, 2013, 09:54:18 PM »
Kent,

I think your library idea as a way to get BASIC programmers using Nimrod is outstanding. Nice Job !

John

kryton9

  • Guest
Re: BAS2NIM
« Reply #59 on: October 16, 2013, 10:10:55 PM »
Thanks John. I just made a small example for real developers to get an idea of where to start if they wanted to port their BASIC to Nimrod and have all its cross platform options.

When you look in the cross compiler section, wow they can compile to arm and even embedded systems like avr.
http://nimrod-code.org/nimrodc.html#compiler-usage

Off to try your translation code now.