[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

What is this form called when you see in a book explaining g

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 14
Thread images: 1

File: 1478429782351.png (389KB, 720x694px) Image search: [Google]
1478429782351.png
389KB, 720x694px
What is this form called when you see in a book explaining general syntax for something?

int printf ( string $format [, mixed $args [, mixed $... ]] )


I cant find anywhere the rules for writing this format, especially weird part is " [," , comma going after the opened parentheses.

Are there standardized rules for writing these prototypes?

The example above is from : http://php.net/manual/en/function.printf.php
>>
The comma goes after the brackets because the comma shouldn't be present unless the rest of the content of the brackets is, there's nothing weird about that.
>>
>>57735636
If there is nothing after comma it is perfectly understandable that comma shouldnt be there either

1,2,3,
1,2,3
>>
>>57735601
it is called optional characters. It comes from regex syntax
>>
>>57736252
in this case, optional arguments*
>>
>>57736252
So it's standard format for representing general rules for writing something , in this case a printf ?
>>
>>57736252
disregard this question>>57736369

Wasnt thinking. It is all regexp rules. Thanks
>>
>>57736369
It is not language agnostic. In this case, printf may have an infinite number of arguments as well. 1 argument is obligatory, the rest is optional

In C#, for example, we represent it as params:

https://msdn.microsoft.com/en-us/library/w5zay9db.aspx

It means that it takes a variable number of arguments, from 0 to infinite. This is useful when you are not sure about the number of arguments.

A great and simple example is printf. Since you want 1 obligatory argument, you use

print(string arg1, params string[] args)

This way you enforce 1 + 0~infinite arguments. Knowing mathematics, the lower limit is 1 and the upper is infinite.

If you check manual files (for example write man tar on linux terminal) you will see that they usually use something like:

command [-e | -f | -u]

this shows that e f and u are optional, but you can use one of them if you want. Nothing else.

This syntax is common knowledge and goes back to regex, but it doesn't mean you will always find it like this. Since method arguments are not tightly related to regex, some other languages (like C#, ie) use other notations.
>>
>>57736529
Thank you very much anon for your time.

Also,do you think that in command [-e | -f | -u] they used "|" to kind a represent the logical OR so it would be clear that you can use one of given options?
>>
>>57736529
Correcting all my lesson there, [] is not optional in regex. it uses ()? to set optional.

But still, [] is common knowledge for optional

check this: http://docopt.org/
>>
>>57736609
This comes from logical operations (operators).

Usually, | means or, as much as & means and.

Why don't we use & then? Well, studying the dragon book you will see that writing A & B is the same as A+B or AB. If you think as a compiler making a lexical analysis, AB means it needs A and B input.

A | B must be distinctively divided due to the fact that a state machine expecting A OR B should have a division when jumping states
>>
>>57736671
What else to say, thank you anon.
>>
>>57736671
all this ends up to formal languages and automata. Anything that represents a chain of characters can be described as an automata, such as finite state machine or stack machine. You can build a formal language.

The key here is the formal language that your automata accepts.

In your case, | means that it can accept one or another and that [] represents something optional. If this element doesn't exist, it is ok. The automata will just skip the state spontaneously as an ε input (for espontaneous)

Therefore, analysing the formal language, you get your grammar, just like english. It has rules to represent what is correct and wrong

| is an or
[] is optional
etc.

This is your grammar
>>
>>57736717
Good luck anon. I am glad to help. If you have any other questions regarding anything else let me know
Thread posts: 14
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.