Discussion:
[LogoForum] BNF grammar for LOGO programming language.
(too old to reply)
naripeddy_333
2006-04-06 20:50:01 UTC
Permalink
The message below is being cross-posted from LogoForum.

I need complete grammar for LOGO programming language.If anyone knows
abt this..please help me out.






LogoForum messages are archived at:
http://groups.yahoo.com/group/LogoForum
Brian Harvey
2006-04-07 17:43:23 UTC
Permalink
Post by naripeddy_333
I need complete grammar for LOGO programming language.If anyone knows
abt this..please help me out.
In Logo everything is a procedure call. A procedure is either a
command, which has an effect, or an operation, which returns a value.
So basically the syntax is

<instruction> ::= <command-name> <expression>* |
( <command-name> <expression>* )

<expression> ::= <operation-name> <expression>* |
<list> | <quoted-word> | <number> |
<variable-ref> | ( <expression> )

<list> ::= [ <list-element>* ]

<quoted-word> ::= " <word>

<list-element>::= <list> | <word>

<word> ::= <string of characters other than space or [ or ]>

<variable-ref>::= : <word>

except that there is also infix arithmetic with + - * / = < > in the
usual way. Wherever it says <expression>* the number of expressions
must match what the called procedure expects.

It'd be hard to do a really helpful BNF, because of that last point.
It would have to include things like

<proc call> ::= <name-of-proc-with-0-default-inputs> |
<name-of-proc-with-1-default-input> <expr> |
<name-of-proc-with-2-default-inputs> <expr> <expr> |
<name-of-proc-with-3-default-inputs> <expr> <expr> <expr> |
... |
( <name-of-proc-that-can-take-0-inputs> ) |
( <name-of-proc-that-can-take-1-input> <expr> ) |
( <name-of-proc-that-can-take-2-inputs> <expr> <expr> ) |
( <name-of-proc-that-can-take-3-inputs> <expr> <expr> <expr> ) |
...

If you just said <proc-name> <expr>* that wouldn't help you parse things like
foo baz 1 2 3 4 5
for which you need to know the arity of foo and baz. And you actually
need two such rules, one for commands and one for operations.

Also, different dialects differ about the precise rules for tokenization,
so the description of <word> above is a lie. I'm afraid I know of no
published bnf, even for specific dialects.

Logo does have one special form, TO, which is used to define
procedures.

You might want to look at
ftp://ftp.cs.berkeley.edu/pub/ucblogo/usermanual
for the Berkeley Logo reference manual, which gives examples.
Pavel Boytchev
2006-04-09 06:16:19 UTC
Permalink
The message below is being cross-posted from LogoForum.
Post by Brian Harvey
In Logo everything is a procedure call. A procedure is either a
command, which has an effect, or an operation, which returns a value.
So basically the syntax is
<instruction> ::= <command-name> <expression>* |
( <command-name> <expression>* )
<expression> ::= <operation-name> <expression>* |
<list> | <quoted-word> | <number> |
<variable-ref> | ( <expression> )
<list> ::= [ <list-element>* ]
<quoted-word> ::= " <word>
<list-element>::= <list> | <word>
<word> ::= <string of characters other than space or [ or ]>
<variable-ref>::= : <word>
except that there is also infix arithmetic with + - * / = < > in the
usual way. Wherever it says <expression>* the number of expressions
must match what the called procedure expects.
It'd be hard to do a really helpful BNF, because of that last point.
It would have to include things like
<proc call> ::= <name-of-proc-with-0-default-inputs> |
<name-of-proc-with-1-default-input> <expr> |
<name-of-proc-with-2-default-inputs> <expr> <expr> |
<name-of-proc-with-3-default-inputs> <expr> <expr> <expr> |
... |
( <name-of-proc-that-can-take-0-inputs> ) |
( <name-of-proc-that-can-take-1-input> <expr> ) |
( <name-of-proc-that-can-take-2-inputs> <expr> <expr> ) |
( <name-of-proc-that-can-take-3-inputs> <expr> <expr> <expr> ) |
...
If you just said <proc-name> <expr>* that wouldn't help you parse
things
like
foo baz 1 2 3 4 5
for which you need to know the arity of foo and baz. And you actually
need two such rules, one for commands and one for operations.
Also, different dialects differ about the precise rules for
tokenization,
so the description of <word> above is a lie. I'm afraid I know of no
published bnf, even for specific dialects.
Logo does have one special form, TO, which is used to define
procedures.
LogoForum messages are archived at:
http://groups.yahoo.com/group/LogoForum

Continue reading on narkive:
Search results for '[LogoForum] BNF grammar for LOGO programming language.' (Questions and Answers)
6
replies
how do I make a programming language?
started 2014-03-12 19:43:46 UTC
programming & design
Loading...