FreeBASIC grammar Part II

User projects written in or related to FreeBASIC.
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

FreeBASIC grammar Part II

Postby AGS » Apr 30, 2010 17:27

The FreeBASIC grammar can be found in the FB manual. There it is spread out over many HTML pages. I thought it would be nice to have all the rules in one place. And in the format of syntax diagrams. Example of such a diagram:

Image

The above simply states that a binary digit is either a 0 or a 1.

I'm going to present the grammar in a way not unsimilar to the way it has been done in Annex A of the ISO C99 standard
(the document can be found at http://www.open-std.org/JTC1/SC22/WG14/ ... /n1256.pdf ). The difference being that the document on C99 uses text only while I'll be representing the grammar using syntax diagrams.

I'll start with the Lexical Grammar and from there slowly progress towards the phrase structure grammar (I'll follow the C99 standard as a guide).

I will of course divert from the C99 standard where needed (FB, after all, is not C).
Last edited by AGS on Apr 30, 2010 18:16, edited 1 time in total.
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Postby AGS » Apr 30, 2010 17:46

Added floating point constants.

Added string constants.
Due to technical difficulties it was not possible to use a quoted backslash ('\'). The word BACKSLASH should be read as a quoted backslash.

Added keywords section (leaving out compiler intrinsics as these will be put in the preprocessor section).
Last edited by AGS on May 08, 2010 20:05, edited 3 times in total.
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Postby AGS » Apr 30, 2010 18:03

Lexical Grammar

Keywords
abs access acos alias and andalso any append as asc asin
asm assert assertwarn atan2 atn binary bit bitreset bitset byref byte
byval call case cast cbyte cdbl cdecl chr cint circle class
clng clngint close color common const constructor continue cos cptr cshort
csign csng cubyte cuint culng culngint cunsg cushort cvd cvi cvl
cvlongint cvs cvshort data declare defbyte defdbl defined defint deflng deflongint
defshort defsng defstr defubyte defuint defulng defulongint defushort delete destructor dim
do double draw dynamic else elseif encoding end endif enum eqv
erase err error exit exp explicit export extern field fix for
frac function get gosub goto hibyte hiword if iif imagecreate imp
import include input instr instrrev int integer is lbound len let
lib line lobyte local lock log long longint loop loword lprint
lset ltrim mid mkd mki mkl mklongint mks mkshort mod name
namespace new next not offsetof on open operator option or orelse
output overload paint palette pascal peek point pointer poke preserve preset
print private procptr property protected pset ptr public put random read
redim rem restore resume return rgb rgba rset rtrim sadd scope
screen screenres seek select sgn shared shl short shr sin single
sizeof spc sqr static stdcall step str string strptr sub swap
tab tan then to trim type typeof ubound ubyte uinteger ulong
ulongint union unlock unsigned until ushort using va_arg va_first va_next var
varptr view wchr wend while width window with write wstr wstring

Tokens

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image

Image
Last edited by AGS on May 08, 2010 20:12, edited 3 times in total.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Apr 30, 2010 20:44

Yes, please :)
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Postby AGS » May 08, 2010 20:28

I've added a bunch of things over the past week. Most keywords are in there and a lot of the token definitions have been done as well (some finetuning is needed as there are a couple of mistakes here and there). Definition of strings could be better (UNICODE related stuff).

Still to do:
- comments;
- punctuators;
- phrase structure grammar;
- preprocessing directives.

The C99 grammar definition as written down in the appendix of the C99 ISO standard (this includes the grammar of the preprocessor) takes up 14 pages of a PDF file (A4 formatted). So the message containing the grammar is going to get REALLY long.

A message with a length that equals 14 pages of A4 text is not going to be very readable so I'm going to put it all in a PDF file (with bookmarks for easy access to the different parts of the grammar).
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Postby AGS » Jun 02, 2010 4:09

The first PDF version of the grammar is ready. I used:
- FreeBASIC (what else?);
- restructured text markup http://docutils.sourceforge.net/docs/re ... dtext.html
- rest2pdf http://code.google.com/p/rst2pdf/

to create the PDF file.

rest2pdf uses the reportlab package http://www.reportlab.com/software/opens ... l-toolkit/. Both reportlab and res2pdf have been written in python so there is a python dependency as well.

Not much has changed in the grammar. I concentrated on getting a printable PDF (ie make sure output looks good when printing the PDF).

And last but not least a link to the file (almost 2MB in size due to the huge amount of pictures used)

http://www.sarmardar.nl/FreeBASIC/fbgrammar.zip
MystikShadows
Posts: 606
Joined: Jun 15, 2005 13:22
Location: Upstate NY
Contact:

Postby MystikShadows » Jun 04, 2010 21:01

Excellent work on the grammar.

for the Constant statement. I know it's possible to specify a type for the constant. For example.

Code: Select all

CONST ApplicationName AS STRING = "Application Name"


I think it would be good to add it up somewhere :)
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Postby AGS » Jun 04, 2010 22:31

MystikShadows wrote:Excellent work on the grammar.

for the Constant statement. I know it's possible to specify a type for the constant. For example.

Code: Select all

CONST ApplicationName AS STRING = "Application Name"


I think it would be good to add it up somewhere :)


Declarations are going to be in the grammar for sure.

Return to “Projects”

Who is online

Users browsing this forum: Gunslinger and 1 guest