Re: Looking for Perl Grammar



* Khamis Abuelkomboz schrieb:
>
> However I still find clauses like
>
> if ( s{foo}{bar} ) ...
> if ( s[foo][var] ) ...
> if ( s<foo><bar> ) ...
>
> I still don't figure out what could be used as "brackets" for the
> s|tr|m commands???? So I'm looking as example for grammar descriping
> how the (s, tr, qq) could be built, something like
>
> S: s OP1 expr OP2 expr OP3
> OP1: '/' | '{' | '[' | ':' | ...
> OP2: '/' | '}{' | '][' | ...
> OP3: '/' | '}' | ']' | ':' | ...
>
> I'm still guissing :-)

This is mentioned in `perldoc perlop` in the section named "Quote and
Quote-like Operators".

Non-bracketing delimiters use the same character fore and aft, but
the four sorts of brackets (round, angle, square, curly) will all
nest, which means that

q{foo{bar}baz}

is the same as

'foo{bar}baz'

[...]

There can be whitespace between the operator and the quoting
characters, except when # is being used as the quoting character.
q#foo# is parsed as the string foo, while q #foo# is the operator q
followed by a comment. Its argument will be taken from the next
line. This allows you to write:

s {foo} # Replace foo
{bar} # with bar.

So, for s/// you could start with a grammar similar to

S: s WS BRACKETED WS BRACKETED | s WS DELIM expr DELIM expr DELIM
BRACKETED: '(' expr ')' | '<' expr '>' | '[' expr ']' | '{' expr '}'
WS: WHITE-SPACES *
DELIM: '/' | '!' | ':' | '^'

I'm not deeply familiar with grammar descriptions. Is there a way to
ensure that each DELIM is the same char?

Don't forget to add the special behavior of »#« to your grammar. And of
course, do you want to allow comments between the BRACKETED parts as in
the example above? ;-)

regards,
fabian
.



Relevant Pages

  • Re: Is reverse reading possible?
    ... >mixture of Chinese and English, ... do it straight off when you have non-uniform character sizes as ... without knowing the encoding method... ... Derive a grammar for a single ...
    (comp.lang.python)
  • Re: 2 Spaces Required Between Sentences
    ... John, I really am trying to avoid rocket science. ... this time to put everything into single space. ... You can use any character you like in place of %, I use % because it is very ... My grammar settings are for 2 spaces required between sentences. ...
    (microsoft.public.mac.office.word)
  • Re: 2 Spaces Required Between Sentences
    ... You can use any character you like in place of %, I use % because it is very ... old convention that was introduced in the days of typewriters, ... Modern electronic typesetters will substitute this character whenever they ... My grammar settings are for 2 spaces required between sentences. ...
    (microsoft.public.mac.office.word)
  • Re: Bad Grammar in dialogue
    ... >Different characters ought to have differnt attitudes towards grammar. ... >speaking to one character, somewhat incorrect grammar when speaking to ... and really horribly bad grammar when speaking to a third character. ... I think I do much the same myself, in real life, though not to quite ...
    (rec.arts.sf.composition)
  • Re: Find spaces with Regex
    ... working fine, except in the example "1 space", it is picking up the space. ... I know it's because it's looking for a space, &, n, b, s, p,; character. ... How to I change the regular expression to look for a space ... without a quantifier like the * I added would only match a single one of the characters in the brackets. ...
    (microsoft.public.dotnet.languages.csharp)