Liberty BASIC Community Forum
« Nothing Happens »

Welcome Guest. Please Login or Register.
Mar 29th, 2017, 04:13am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Nothing Happens  (Read 230 times)
PoseidonScript
Full Member
ImageImageImage


member is offline

Avatar

Leader of the Space Pirates

ICQ
Homepage PM

Gender: Male
Posts: 106
question Nothing Happens
« Thread started on: Oct 14th, 2015, 09:26am »

Hello,

I am trying to write a simple compiler in Liberty Basic . :P So I'm following this tutorial. I managed to get all the syntax correct, however when i run it it ends quickly even though there is an input command which means it's being skipped. Here is the latest version of my code:
Code:
NoMainWin

Look$ = ""

Sub GetChar
    input ""; Look$
end sub

sub Errors String$
    print "\n"
    print "Error: " + String$ + "."
end sub

sub Abort String$
    call Errors String$
    end
end sub

sub Expected String$
    call Abort String$ + " Expected"
end sub

sub Match x$
    if Look$ = x$ then
      call GetChar
    else
      call Expected "" + x$ + ""
    end if
end sub

function isAlpha(Char$)
    asciiCode = asc(Char$)
    if asciiCode > 64  and asciiCode < 91 then
       isAlpha = 1
    else
       isAlpha = 0
    end if
end function


function isDigit(Char$)
    asciiCode = asc(Char$)
    if asciiCode > 47  and asciiCode < 58 then
       isDigit = 1
    else
       isDigit = 0
    end if
end function

function GetName$()
   char$ = Look$
   if isAlpha(Look$) = 0 then
      call Expected "Name"
   end if
   GetName$ = upper$(char$)
   call GetChar
end function

function GetNum()
   char$ = Look$
   if isDigit(Look$) = 0 then
      call Expected "Integer"
   end if
   GetNum$ = upper$(char$)
   call GetChar
end function

sub Emit String$
   print "   " + String$
end sub

sub EmitLn String$
   call Emit String$
   print "\n"
end sub

sub Init
   call GetChar
end sub

call Init
 

Any assistance in this matter would be greatly appreciated.

Sincerely,

PoseidonScript
User IP Logged

PoseidonScript written in Liberty Basic
Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14909
question Re: Nothing Happens
« Reply #1 on: Oct 14th, 2015, 10:26am »

I'm happy to assist. Why not work through the tutorial that comes with LB to familiarize yourself with the structure and syntax, then work on your own compiler?

Here is a fix for the problem you described. Do not disable the mainwin.
Code:
'NoMainWin
print "Waiting for input. Type something, then press ENTER."
input a$

print "You typed ";a$

wait

Look$ = ""

Sub GetChar
    input ""; Look$
end sub

sub Errors String$
    print "\n"
    print "Error: " + String$ + "."
end sub

sub Abort String$
    call Errors String$
    end
end sub

sub Expected String$
    call Abort String$ + " Expected"
end sub

sub Match x$
    if Look$ = x$ then
      call GetChar
    else
      call Expected "" + x$ + ""
    end if
end sub

function isAlpha(Char$)
    asciiCode = asc(Char$)
    if asciiCode > 64  and asciiCode < 91 then
       isAlpha = 1
    else
       isAlpha = 0
    end if
end function


function isDigit(Char$)
    asciiCode = asc(Char$)
    if asciiCode > 47  and asciiCode < 58 then
       isDigit = 1
    else
       isDigit = 0
    end if
end function

function GetName$()
   char$ = Look$
   if isAlpha(Look$) = 0 then
      call Expected "Name"
   end if
   GetName$ = upper$(char$)
   call GetChar
end function

function GetNum()
   char$ = Look$
   if isDigit(Look$) = 0 then
      call Expected "Integer"
   end if
   GetNum$ = upper$(char$)
   call GetChar
end function

sub Emit String$
   print "   " + String$
end sub

sub EmitLn String$
   call Emit String$
   print "\n"
end sub

sub Init
   call GetChar
end sub

call Init

 
User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


Alyce's Restaurant
for Liberty BASIC code, tools and references
Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14909
question Re: Nothing Happens
« Reply #2 on: Oct 14th, 2015, 11:11am »

If you are asking for user input without having a GUI window and controls, you need to use the mainwin. The nomainwin command stops the mainwin from opening. Do not use the nomainwin statement anywhere in your program, or the mainwin will not open.

You need to issue a "wait" or "input" statement before listing subs and functions, otherwise the program execution falls through until it reaches the first stopping point.

In your program, you have the following:
Code:
Look$ = ""

Sub GetChar
    input ""; Look$
end sub
 


You have not called this sub when execution reaches it, so there is nowhere to jump back to. Also, since the input statement works in the mainwin and this program does not have a mainwin, there will be no input from the user.

Some suggested reading:
http://lbpe.wikispaces.com/FunctionFundamentals
http://lbpe.wikispaces.com/SubroutinesAndGosubs
User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


Alyce's Restaurant
for Liberty BASIC code, tools and references
PoseidonScript
Full Member
ImageImageImage


member is offline

Avatar

Leader of the Space Pirates

ICQ
Homepage PM

Gender: Male
Posts: 106
question Re: Nothing Happens
« Reply #3 on: Oct 14th, 2015, 1:56pm »

on Oct 14th, 2015, 11:11am, Alyce Watson wrote:
If you are asking for user input without having a GUI window and controls, you need to use the mainwin. The nomainwin command stops the mainwin from opening. Do not use the nomainwin statement anywhere in your program, or the mainwin will not open.

You need to issue a "wait" or "input" statement before listing subs and functions, otherwise the program execution falls through until it reaches the first stopping point.

In your program, you have the following:
Code:
Look$ = ""

Sub GetChar
    input ""; Look$
end sub
 


You have not called this sub when execution reaches it, so there is nowhere to jump back to. Also, since the input statement works in the mainwin and this program does not have a mainwin, there will be no input from the user.

Some suggested reading:
http://lbpe.wikispaces.com/FunctionFundamentals
http://lbpe.wikispaces.com/SubroutinesAndGosubs

Thanks guys, I sorta managed to get it working:
Code:
Look$ = ""

call Init

end

Sub GetChar
    input ">"; Look$
end sub

sub Errors String$
    print "\n"
    print "Error: " + String$ + "."
end sub

sub Abort String$
    call Errors String$
    end
end sub

sub Expected String$
    call Abort String$ + " Expected"
end sub

sub Match x$
    if Look$ = x$ then
      call GetChar
    else
      call Expected "" + x$ + ""
    end if
end sub

function isAlpha(Char$)
    asciiCode = asc(Char$)
    if asciiCode > 64  and asciiCode < 91 then
       isAlpha = 1
    else
       isAlpha = 0
    end if
end function


function isDigit(Char$)
    asciiCode = asc(Char$)
    if asciiCode > 47  and asciiCode < 58 then
       isDigit = 1
    else
       isDigit = 0
    end if
end function

function GetName$()
   char$ = Look$
   if isAlpha(Look$) = 0 then
      call Expected "Name"
   end if
   GetName$ = upper$(char$)
   call GetChar
end function

function GetNum()
   char$ = Look$
   if isDigit(Look$) = 0 then
      call Expected "Integer"
   end if
   GetNum$ = upper$(char$)
   call GetChar
end function

sub Emit String$
   print "   " + String$
end sub

sub EmitLn String$
   call Emit String$
   print "\n"
end sub

sub Init
   call GetChar
end sub
 

This works, but looks like it gets suck and doesn't continue after the input statement in GetChar. Any assistance would be greatly appreciated.

Sincerely,

PoseidonScript
User IP Logged

PoseidonScript written in Liberty Basic
tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1609
question Re: Nothing Happens
« Reply #4 on: Oct 14th, 2015, 3:23pm »

Quote:
This works, but looks like it gets suck and doesn't continue after the input statement in GetChar.

My guess that it was 1st lesson of tutorial
So it's really not does much at all.
You have pretty long road ahead, see
http://compilers.iecc.com/crenshaw/
User IP Logged

The existence of bug reports means somebody is using the software and actually cares to report back to you that he is having a problem with it, instead of just deleting it from their hard disk.
(Janusz Marcin Gorycki)
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls