3 ms·
> No. (Syntax is a subset of grammar.) Can you elucidate what you see the relationship between them as being? > No, it's also because it's a pattern-based pre
by skissane 5y ago
> No. (Syntax is a subset of grammar.)
Can you elucidate what you see the relationship between them as being?
> No, it's also because it's a pattern-based preprocessor.
What do you mean by that? Why does being a "pattern-based processor" imply something has "no official grammar"?
> There are efforts to produce Markdown grammars; some have been done.
So, if people have produced grammars for it, it has a grammar, no?
> No, these are not the same.
How and why are they different?
- unfocussed_mike 5y ago> Can you elucidate what you see the relationship between them as being? Grammar covers the correct use of the syntax of a language. With syntax alone you cannot know whether a program is a correct use of a language -- that is, it will parse or compile, even if its output is nonsensical. A grammar lets you do that. So for example an unambiguous grammar is essential to being able to translate higher level language into assembly language. > What do you mean by that? Why does being a "pattern-based processor" imply something has "no official grammar"? Can you parse and transform arbitrary HTML correctly with only regular expressions? The answer as I am sure you will know is no. That is your answer here too. > So, if people have produced grammars for it, it has a grammar, no? I don't know if any Markdown grammar exists that expresses all of what you can do in the reference implementation of Markdown, so *shrug*. Maybe, maybe not. The fact that it has no deliberately designed grammar is an interoperability problem though. > How and why are they different? Because you are comparing extending semantics within what is allowed by the grammar (writing functions in the programming language it concerns) (e.g. in Java), and extending the interpreter itself (Tcl as a "language" changes according to which extensions are compiled in, and the extensions determine what the symbols mean). The fundamental question here is this: Can a program conclude that a Tcl program will parse correctly (even if the code itself has errors) without running the specific Tcl interpreter for which it is designed (or at least without knowledge of the implementation of its extensions)? No, it essentially cannot. That is what a grammar gives you. You can stare at a bit of C code you do not understand and at least say "it is valid C". And so can another program (a static analyser/explorer, a linter, etc.) More difficult with Tcl. (And perl4, for example)
- skissane 5y ago> Grammar covers the correct use of the syntax of a language. With syntax alone you cannot know whether a program is a correct use of a language -- that is, it will parse or compile, even if its output is nonsensical. A grammar lets you do that. Suppose I am writing a Pascal compiler. I might start with a grammar for Pascal, expressed in EBNF. I might write a parser from that grammar, either by hand, or by using some parser generator. My parser converts text (or a sequence of tokens generated by an independent lexical analysis stage) to some kind of parse tree or abstract syntax tree. Since Pascal is a statically typed language, I also need to write some code to do type-checking. If you look at a tutorial on writing a compiler, you might see this presented as a subsequent compilation stage, after parsing is complete. It takes the AST and symbol table, annotates it with type information (possibly even doing type inference), and checks various rules are obeyed. And, an EBNF grammar doesn't tell us how to do it. Generally you'd either express it informally, or if you were going to use some kind of formalism, you'd use a rather different formalism from those in which programming language grammars are commonly expressed. There are "typed grammar" formalisms which combine type-checking into parsing, but you don't see them commonly used by people implementing programming languages in the real world. In my experience they are mainly popular in academia (and I've seen them presented more often in the context of natural language processing than programming languages.) I don't get the impression you are thinking of one of those "typed grammar" formalisms; I more get the impression that you are using the word "grammar" in an idiosyncratic way which elides the conceptual distinction between syntax and semantics, and ignores the standard usage in which the word "grammar" is primarily associated with the former not the later.
- unfocussed_mike 5y agoThe fact remains -- you cannot know that a Tcl program is syntactically correct without running it, can you? Because the full syntax is determined by the extensions. Can you write a parser for Tcl in Yacc? https://compilers.iecc.com/comparch/article/99-08-100 https://compilers.iecc.com/comparch/article/99-08-100 http://computer-programming-forum.com/57-tcl/7aaac08c64c8c610.htm http://computer-programming-forum.com/57-tcl/7aaac08c64c8c61... This is why I say Tcl doesn't have a grammar. It literally lacks one by definition. Unless something fundamental has changed. IMO it's a terrible language which should have been left in the last century with perl4.