Skip to content

Hugely useful tool #6

@The-Futurist

Description

@The-Futurist

I'm using the tool to explore a new grammar, an adaptation of the PL/I language. The tool is extremely helpful and as I use it several things have come up on a "wish list" I'll list them here in case you get an opportunity to consider them.

The biggest limitation just now is that I can't paste a test input because it contains whitespaces and I don't know how to cater for that in a grammar. Ordinarily the lexical analyzer strips these away so we just see tokens but here there is no lexer as such.

Here's the gist of the grammar at an early stage, this is very draft and far from complete at this stage:

/* https://bnfplayground.pauliankline.com/ */

<DCL> ::= " dcl " | " declare "
<ARG> ::= " arg " | "argument "
<PROC> ::= " proc " | " procedure "
<FUNC> ::= " func " | " function "
<BIN>  ::= " bin " | " binary "
<DEC> ::= " dec " | "decimal "
<STRING> ::= " string "
<STATIC> ::= " static "
<BASED> ::= " based "
<CALL> ::= " call "
<GOTO> ::= " goto " | " go to "
<RETURN> ::= " return " 
<RETURNTO> ::= " return to "
<IF> ::= " if "
<THEN> ::= " then "
<ELSE> ::= " else "
<FIXED> ::= " fixed "
<FLOAT> ::= " float "
<VAR> ::= " varying "
<DEF> ::= " defined "
<LOOP> ::= " loop "
<WHILE> ::= " while "
<UNTIL> ::= " until "
<TO> ::= " to "
<BY> ::= " by "
<REPEAT> ::= " repeat "
<POINTER> ::= " pointer "
<compilation_unit> ::= <stmt>+
<stmt> ::= <dcl_stmt> | <def_stmt>  
<dcl_stmt> ::= <DCL> <identifier> <array_specifier>? <reqd_dcl_attribs> <optional_dcl_attribs>* ";"
<arg_stmt> ::= <ARG> <identifier> <array_specifier>? <reqd_dcl_attribs> <optional_dcl_attribs>* ";"
<identifier> ::= [a-z]+ " "
<def_stmt> ::= ( <PROC> | <FUNC> ) <identifier> <arglist>? <reqd_dcl_attribs>? <block>
<arglist> ::= "(" <identifier> ( "," <identifier>)* ")"
<array_specifier> ::= "(" <integers> ( "," <integers>)* ")"
<integers> ::= [0-9]+  
<reqd_dcl_attribs> ::= <numeric> | (<string> <VAR>?) | <POINTER>
<optional_dcl_attribs> ::= <STATIC> | <based> | <defined>
<defined> ::= (<DEF> ("(" <identifier> ")") )
<based> ::= (<BASED> ("(" <identifier> ")")? )
<numeric> ::= (<base> <scale>?) | (<scale> <base>?)
<binary> ::= <BIN> (<FIXED> | <FLOAT>)?
<decimal> ::= <DEC> (<FIXED> | <FLOAT>)?
<base> ::= <BIN> | <DEC>
<scale> ::= <FIXED> | <FLOAT>
<string> ::= <STRING> "(" <integers> ")"
<block> ::= "{" <arg_stmt>* <dcl_stmt>* <exe_stmt>* "}"
<exe_stmt> ::= (<assignment> | <keyword_stmt>) ";"
<assignment> ::= <identifier> " = " <identifier> 
<keyword_stmt> ::= <call_stmt> | <goto_stmt> | <return_stmt> | <if_stmt> | <loop_stmt>

/* executable statements */
<call_stmt> ::= <CALL> <identifier> <arglist>?
<goto_stmt> ::= <GOTO> <identifier> ( "(" (<integers> | <identifier>) ")" )?
<return_stmt> ::= <RETURN> | (<RETURN> "(" <expression> ")")
<if_stmt> ::= <IF> <expression> <THEN> (<block> | <exe_stmt>) (<ELSE> (<block> | <exe_stmt>) )?
<loop_stmt> ::= <LOOP> (<iterate>? | <repeat>?) ((<while>? <until>?) | (<until>? <while>?))? <block> 
<while> ::= <WHILE> "(" <expression> ")"
<until> ::= <UNTIL> "(" <expression> ")" 
<iterate> ::= <identifier> "=" <expression> <TO> <expression> (<BY> <expression>)?
<repeat> ::= <identifier> "=" <expression> <REPEAT> "(" <expression> ")"

/* expressions */
<expression> ::= <identifier> | <integers>

Expressions are not defined yet (other than being a simple identifier or numeric literal) but you can see the idea here.

I find the tool extremely helpful as I incrementally extend the grammar gradually but the whitespace thing is slowing things down a bit.

Is there a way to cater for this purely using EBNF? Here's a typical test input that I'd expect to parse cleanly:

dcl name(10) string(32);

proc main (arg1) 
{
   arg arg1 string(32);

   loop I = 1 to 100 by 5 until (fail)
   {
     call testutil(I);
   }

}

Of course it won't because the presence of CR and LF etc mess everything up. Also if we could get the tool to tolerate these white spaces then could the test input area be changed so that it is also an expandable text input box, like the BNF editor window itself?

Finally it would be neat too if we could somehow "download" the grammar text (rather than just saving the URL as you support but I find a little confusing). Currently I'm copying/pasting this as I work, into a file on my desktop PC.

I have developed a full PL/I compiler for Windows in the past, like some 20 years ago so I'm very much at home with this but have never used any kind of grammar tool and it is a huge help when exploring options for a new grammar.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions