What is the difference between lexical grammar and syntactic grammar?

I am reading the Java 8 language specification.

I am trying to understand chapter 2. Grammar.

Here is what I already learned:

  • Semantics:
    Semantics is the study of meaning.

  • Value:
    The meaning in semantics is defined as an extension: the thing in the world to which the word / phrase refers, plus the intention: the concepts / mental images that the word / phrase invokes.

  • Syntax:
    The syntax is all about the structure of sentences, as well as what words go there.

  • Production:
    A production or production rule in computer science is a rewrite rule that defines character substitution, which can be recursively executed to generate new sequences of characters.

  • Alphabet:
    A nonempty set is called an alphabet when its intended use in string operations is indicated.

  • Token:
    A token is a string of characters that forms a syntactic unit.

  • Syntax unit:
    A sentence is the “highest” (i.e., largest) syntax unit,
    the smallest (i.e. smallest) syntactic units are words,
    intermediate syntactic units are phrases.

  • Token:
    A token is a structure representing a token that clearly indicates its categorization for parsing.

  • Grammar:
    Grammar (when context is not defined, often called formal grammar for clarity) is a set of production rules for strings in a formal language. The rules describe how to form strings from the language alphabet that are valid according to the language syntax. A formal grammar is a set of rules for rewriting strings along with the "start character" from which rewriting begins.

  • Lexical Grammar:
    Lexical grammar is a formal grammar that defines the syntax of tokens.

I could not find out what syntax grammar is.

+7
java context-free-grammar grammar lexical
source share
1 answer

A more expansive definition of "syntax" will be the set of all ordered combinations of characters that form the correct document in a given language. Thus, “syntactic grammar” can be briefly described as part of a language grammar that describes how various markers can be ordered to form meaningful phrases.

Of course, it comes down to your provided definition of “lexical grammar”, so let me highlight the main difference - lexical grammar describes the structure of the lexicon, that is, each token (word) used in the language. The syntactic grammar describes how phrases and documents are formed from these tokens.

+8
source share

All Articles