I've created some (fun!) tasks over at Rosettacode:
http://rosettacode.org/wiki/Compiler/lexical_analyzer
http://rosettacode.org/wiki/Compiler/syntax_analyzer
http://rosettacode.org/wiki/Compiler/code_generator
http://rosettacode.org/wiki/Compiler/vi ... nterpreter
http://rosettacode.org/wiki/Compiler/AST_interpreter
I've put up a FreeBasic solution for the lexical analyzer task (feel free to improve it!)
It would be great if folks here could write FreeBasic (or other) solutions for the other four tasks.
Additionally, if any of the specifications are ambiguous and/or not detailed enough, let me know and I'll improve them.
Thanks!
Rosetta code: help needed
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: Rosetta code: help needed
Very interesting. Far beyond my knowledge but nice reading.
Re: Rosetta code: help needed
I added sleep because Windows and FBEdit(mod) closes the window when program ends making it impossible to see any error message(s).Ed Davis wrote: I've put up a FreeBasic solution for the lexical analyzer task (feel free to improve it!)
I also changed "\" on a few places with chr(92). The code highlighter seems to get confused when it encounters \".
All alterations are marked with #added# and #changed#. I will clean up the listing in a few days.
Regards Frisian.
Re: Rosetta code: help needed
Very interesting projects.
I looked at the first project, the lexical analyzer.
The two functions, is_digit and is_alnum, have unnecessary empty string checks. Look at is_digitx and is_alnumx in the following code:
The function install has a weird bit of code to init the array. It can be reduced to eliminate one of the ubound calls:
Until now I haven't seen anyone using 'system' to close files. Not sure I would do it that way.
On line 200 you declare a boolean type var and assign it the return value of is_digit. is_digit is a function that returns a long.
I scoured the code and can find no reason not to declare the two functions is_digit and is_alnum booleans as well.
I am going to look closer at this analyzer as it is in line with what I am playing around with. Thanks for sharing it.
I looked at the first project, the lexical analyzer.
The two functions, is_digit and is_alnum, have unnecessary empty string checks. Look at is_digitx and is_alnumx in the following code:
Code: Select all
function is_digit(byval ch as string) as long
is_digit = (ch <> "") and ch >= "0" and ch <= "9"
end function
function is_alnum(byval ch as string) as long
is_alnum = (ch <> "") and ((ucase(ch) >= "A" and ucase(ch) <= "Z") or (is_digit(ch)))
end Function
function is_digitx(byval ch as string) as long
is_digitx = ch >= "0" AndAlso ch <= "9"
end function
function is_alnumx(byval ch as string) as long
is_alnumx = (ucase(ch) >= "A" AndAlso ucase(ch) <= "Z") OrElse (is_digit(ch))
end Function
Print is_digit("0")
Print is_digitx("0")
Print is_digit("")
Print is_digitx("")
Print is_alnum("1")
Print is_alnumx("1")
Print is_alnum("")
Print is_alnumx("")
sleep
Code: Select all
function install(byval s_name as string, byval tok as Token_type) as integer
dim n as integer
n = ubound(symtab)
redim preserve symtab(n + 1)
n = ubound(symtab)
----------------------------------------------------------------------------
function install(byval s_name as string, byval tok as Token_type) as integer
Dim n As Integer = ubound(symtab) + 1
ReDim Preserve symtab(n)
On line 200 you declare a boolean type var and assign it the return value of is_digit. is_digit is a function that returns a long.
I scoured the code and can find no reason not to declare the two functions is_digit and is_alnum booleans as well.
I am going to look closer at this analyzer as it is in line with what I am playing around with. Thanks for sharing it.