Grammar Notation
Format of a production
left hand side: right hand side;
: should be read as 'is defined as'.
The right hand side of a production is terminated by a ;.
A word in
italics represent the name of a production (the left
hand side of the production).
Few operators are used to describe the FreeBASIC grammar.
operator | meaning |
. | any character |
* | 0 or more (repetition) |
+ | 1 or more (repetition) |
? | optional (choice) |
() | grouping |
| | separator (separates alternatives) |
semicolon | end of production |
Any symbol that appears on the right hand side of a production
that is not an operator and does not appear in
italics
represents itself and appears
bold.
A symbol at the right hand side of a rule can refer to a production.
Such references are in
italics.
For navigational purposes a reference is a link to the production
being referenced.
When reading the grammar be aware that FreeBASIC is a case insensitive
language.
The grammar presented is not an exact statement of the FreeBASIC language.
Go straight to:
program
expression
Tokens
white:
\t |
any_char:   
any valid character;
eol:    
\n|
\r|
\n\r;
statement_separator: (
: |
eol )+;
dot:         
.;
sign:        
+|
-;
alpha:      
a|
b|
c|
d|
e|
f|
g|
h|
i|
j|
k|
l|
m|
n|
p|
q|
r|
s|
t|
v|
w|
x|
y|
z;
digit:       
0|
1|
2|
3|
4|
5|
6|
7|
8|
9;
hexdigit:   
a|
b|
c|
d|
e|
f|
digit;
octdigit:   
0|
1|
2|
3|
4|
5|
6|
7;
bindigit:   
0|
1;
alphadigit:  
alpha|
digit;
integer_suffix:     
%|
&|
l|
u|
ul|
ll|
ull;
floating_point_suffix:     
!|
#|
f;
suffix:      
integer_suffix|
floating_point_suffix|
$;
expchar:  
d|
e;
operator
:
= |
< |
> |
<> |
+ |
- |
* |
@
& | -> | / | \ | ^ | andalso
orelse | and | or | xor | eqv | imp
+= | -= | *= | /= | \= | ^= | &= |
and= | or= | xor= | eqv= | imp=
new | delete | delete[] | cast | procptr
varptr | strptr | sizeof | [] | ()
;
binary_operator
:
= |
< |
> |
<> |
+ |
- |
& | -> | / | \ | ^
+= | -= | *= | /= | \= | ^= | &= |
and= | or= | xor= | eqv= | imp=
andalso | orelse
;
identifier
literal
integer_literal
decimal_integer:
digit+;
hexadecimal integer:
&hhexdigit+;
octal_integer:
&ooctdigit+;
binary_integer:
&bbindigit+;
floating_literal
string_literal
escape_sequence
simple_escape_sequence
: \a|\b|\f|\l|\n|\r|\t|\v|\\|\'|\"
;
unicode_escape_sequence
decimal_escape_sequence
hexadecimal_escape_sequence
octal_escape_sequence
binary_escape_sequence
Comment
comment
: ( ' | rem) (($directive) | (any_char_but_eol*))
;
multiline_nested_comment
Toplevel
program
line
label
statement
(
declaration |
procedure_call_or_assign |
compound_statement |
quirk_statement |
assembler_block |
assignment )?
(
statement_separator statement)*
;
declaration
procedure_call_or_assign
compound_statement
namespace_statement
scope_statement:
scope statement_separator statement*
end scope
;
if_statement
short_if_statement
else statement_separator statement*
(
eol|
end if |
endif)
;
long_if_statement
statement*
elseif_block*
(
else statement_separator statement*)?
(
end if|
endif)
;
elseif_block
for_statement
(
statement|
exit for(
, for)* |
continue for (
, for)*)*
next identifier (
, identifier)*
statement_separator
;
do_statement
while_statement
(
statement |
exit while (
, while)* |
continue while (
, while)*)*
wend
;
select_statement
case_statement
case_expression
assembler_block
assignment
variable
const_declaration
:
const (
as symbol_type)?
const_assign (
, const_assign)*
;
type_or_union_declaration
type_declaration
union_declaration
type_member_declaration
variable_declaration
symbol_type
:
const?
unsigned?
(
scalar
)(
const? (
ptr|
pointer))*
;
scalar
:
byte
ubyte
short
ushort
integer
uinteger
longint
ulongint
long
ulong
single
double
;
parameters
parameter
user_defined_type
procedure_declaration
procedure_parameter_list
procedure_parameter
expressions
expression
boolean_expression
logical_expression
logical_or_expression
logical_and_expression
relational_expression
concatenation_expression
add_expression
shift_expression
mod_expression
integer_division_expression
multiplication_expression
exponentiation_expression
prefix_expression
highest_precedence_expression
address_of_expression
:
varptr ( highest_precedence_expression
)
;
dereference_expression
casting_expression
quirk_function
quirk_function_name
:
mkd |
mki |
mkl |
mklongint |
mkshort
cvd | cvi | cvl | cvlongint | cvs | cvshort
asc | chr | instr | instrev | lcase | left | len | lset | ltrim | mid | right | rset | rtrim | space | string | ucase | wchr | wstr | wstring
abs | sgn | fix | frac | len | sizeof,sin | asin | cos | acos | tan | atn | sqr | log | exp | atan2 | int
peek
lbound | ubound
seek | input | open | close | get | put | name
err
iif
va_first
cbyte | cshort | cint | clng | clngint | cubyte | cushort | cuint | culng | culngint | csng | cdbl | csign | cunsg
type
view | width | color | screen
;
quirk_statement
jump_statement
print_statement
data_statement
array_statement
line_input_statement
input_statement
poke_statement
file_statement
write_statement
error_statement
on_statement
:
on local? (
error |
expression)
goto identifier
;
view_statement
mid_statement
lrset_statement
width_statement
color_statement
gfx_statement
:
pset (
expression , )?
step?
( expression , expression ) (
, expression )?
line (
expression , )?
step? (
( expression
, expression ) )?
- step?
( expression , expression ) (
, expression? (
, string_literal? (
, expression )?)?)?
circle (
expression , )?
step?
( expression , expression ) , expression ((
, expression? (
, expression? (
, expression? (
, expression (
, expression)? )? )?)?)?)?
paint (
expression , )?
step?
( expression , expression ) (
, expression? (
, expression? ) )
draw ( expression
, )?
expression
view (
screen?
( expression , expression ) - ( expression , expression ) (
, expression? (
, expression)?)? )?
palette get? ((
using variable) | (
expression , expression (
, expression , expression)?)?)
put (
expression , )?
step?
( expression , expression ) , (
( expression , expression ) - ( expression , expression ) ,)?
variable (
, expression (
, expression)?)?
get (
expression , )?
step?
( expression , expression ) - step?
( expression , expression ) , variable
screen (
integer_literal | ((
expression (((
, expression)?
, expression)?
expression)?
, expression))
screenres expression , expression (((
, expression)?
, expression)?
, expression)?
;