Re: Misplaced parenthesis




"Hans-Peter Diettrich" <DrDiettrich@xxxxxxxxxxx> wrote in message
news:47vb7nFh4g3oU1@xxxxxxxxxxxxxxxxx

What's a grammar unless it's written down?

A grammar.

Hmmm. A parser is not restricted to syntax checks, it also can check
constraints (predicates...); this feature can be important in the
disambiguation of otherwise ambiguous syntax.

The entire purpose of the parser component of a compiler is syntax
verification. I refer you to http://en.wikipedia.org/wiki/Parser.

What went wrong when a sentence is accepted by the parser, but is
rejected by the compiler?

Any number of things. Perhaps a missing declaration, perhaps a type
conflict. Perhaps the program or structure is too large, or too small. None
of these things have anything to do with syntax.

In this case the parser accepts a different language than the compiler
accepts. Now the language, accepted by the compiler, is a subset of the
language, accepted by the parser.

Its not necessarily a subset. IIRC, regular grammars are a case in point.
But you are right as far as most programming languages. The syntax of a
programming language generally allows construction of sentences that are
semantically meaningless or invalid. This can be especially true in
strongly typed languages.

We can end our discussion immediately, if you are satisfied with an OPL
grammar that describes an superset of the OPL language. In this case I
can provide a trivial OPL grammar like this:

Goal -> { Keyword | Operator | Identifier | Literal } 'end' '.'

You could, but its absurd.

ISTM that you are thinking of parsing as the process of program validation.
This is, to my mind, incorrect. Validating a program requires lexical
analysis, syntactic analysis, and finally semantic analysis. The fact that
modern compilers interleave these tasks is not material to the fact that
the tasks are identifiably different.


.



Relevant Pages

  • Re: Why C for operating systems
    ... This kind of modification of the language is something that is useful ... extensions in the compiler. ... That's where Lisp shines: you can easily ... Homoiconicity is when the syntax to write data is ...
    (comp.programming)
  • Re: Compiler and an interpreter
    ... >> Suppose in a source-code file, the 4th line contains the first syntax ... >> error.Can anybody please tell me how the compiler and interpreter will ... Some small unit of the language is an acceptable input. ... Perl does not to my knowledge in any way require the reading of the ...
    (comp.programming)
  • Re: RAD vs. performance
    ... It depends on what the compiler can infer and optimize. ... rationals are another type, which are not supported in the cpu and would ... (rather than typed declarations based language with a class-based types ... using about the same syntax as before. ...
    (comp.lang.misc)
  • Maintainable compiler design?
    ... I am working with my pet language, defining grammar, building runtime ... solidly organize the compiler to ensure that it is easy to maintain. ... Currently I am working with ANTLR on the grammar, ...
    (comp.compilers)
  • Re: mixing C and assembly
    ... What you're doing here is writing assembly with C syntax. ... a heavily non-standard language extension, ... how the compiler behaves (you don't want the compiler to use the stack ... high-level language as fast as possible. ...
    (comp.arch.embedded)