Help-Site Computer Manuals
Software
Hardware
Programming
Networking
  Algorithms & Data Structures   Programming Languages   Revision Control
  Protocols
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac

Syntax
Pod file describing syntax understood by Language::Basic module

Syntax - Pod file describing syntax understood by Language::Basic module


NAME

Syntax - Pod file describing syntax understood by Language::Basic module


SYNOPSIS

There is no Language::Basic::Syntax module. This is just a pod file describing the syntax that's supported by the Language::Basic module.


DESCRIPTION

Things in italics are objects. Things in boldface are actual strings (reserved words or punctuation). ``[]'' means optional, ``...'' means optionally more copies of the same thing, and things between slashes that look like Perl regexps are Perl regexps.

This syntax description probably isn't exactly correct from a computer science standpoint, but the idea is just to show what LB supports.

Line Syntax

Line:
Line_Num Statement [: Statement ...]

Statement Syntax

  • DATA Constant [ , Constant ...]

  • DIM Var-Name [ Arglist ] [ , Var-Name [ Arglist ] ...]

    Arglist must be made up of constant arithmetic expressions.

  • DEF Func-Name ( Var-Name [ , Var-Name ...] ) = Arith-Exp

    Var-Names must be scalar variables.

  • END

  • FOR Lvalue = Arith-Exp TO Arith-Exp [ STEP Arith-Exp]

  • GOTO Arith-Exp

  • IF Or-Exp THEN Statement [ : Statement ...] [ ELSE Statement [ : Statement ...]]

    IF Or-Exp THEN Line_Num [ ELSE Line_Num ]

  • INPUT [ Str-Const ; ] Lvalue [ , Lvalue ...]

  • [LET] Lvalue = Arith-Exp

  • NEXT Lvalue

  • ON Arith-Exp GOTO/GOSUB Arith-Exp [ , Arith-Exp ...]

  • PRINT [ Expression [ Print_Sep ] [ Expression [ Print_Sep ] ...] ]

  • READ Lvalue [ , Lvalue ...]

  • Comment

Expression Syntax

Note that, unlike C or Perl, Boolean values cannot be ``cast'' to non-Boolean (string or numeric) values and vice versa.

By the way, the classes in module Language::Basic::Expression rather closely mimic this syntax description.

Expression:
Arith-Exp

Or-Exp

Arithmetic Expression:
Mult-Exp Arith-Op Mult-Exp

String-Exp + String-Exp

Multiplicative Expression:
Unary-Exp Mult-Op Unary-Exp

Unary Expression:
- Unary-Exp

(Arith-Exp)

Lvalue

Function

Constant

Lvalue:
Var-Name [ Arglist ]

Arglist:
( Expression [ , Expression ...] )

Function:
Func-Name Arglist

Constant:
Str-Const

Num-Const

String Expression:
Str-Const

Arith-Exp

The Arith-Exp must be made from Str-Exps.

Logical Or Expression:
And-Exp [ OR Or-Exp ]

Logical And Expression:
Rel-Exp [ AND And-Exp ]

Relational Expression:
NOT Rel-Exp

Arith-Exp Rel-Op Arith-Exp

String-Exp Rel-Op String-Exp

( Or-Exp )

Identifier Syntax

Variable Name:
Numeric Identifier

String Identifier

Function Name:
/FN[A-Z]\w+/

Numeric Identifier:
/[A-Z]\w*/

String Identifier:
/[A-Z]\w*\$/

Token Syntax

Tokens, or atoms, are indivisible pieces of text making up a BASIC program

(Note: Language::Basic only pays attention to case in string constants.)

Line Number:
/\d+/

Comment:
REM /.*/

Note that a comment goes all the way to the end of a line. Colons in a comment do not start a new statement.

Keyword:
DATA | DIM | DEF | END | FOR | GOSUB | GOTO | IF | INPUT | LET | NEXT | ON | PRINT | READ | RETURN | THEN | ELSE | TO | STEP

Numeric Constant:
/(\d*)?\.?\d+/

String Constant:
/``.*?''/

Relational Operator:
< | <= | > | >= | = | <>

Arithmetic Operator:
+ | -

Multiplicative Operator:
* | /

Print Separator:
, | ;

Programminig
Wy
Wy
yW
Wy
Programming
Wy
Wy
Wy
Wy