What is the difference between Lexical grammar and Syntactic grammar?
Asked Answered
N

1

8

I am reading The Java Language Specification 8.

I am trying to understand Chapter 2. Grammars.

Here's what I have already learned:

  1. Semantics:
    Semantics is the study of meaning.

  2. Meaning:
    Meaning, in semantics, is defined as being Extension: The thing in the world that the word/phrase refers to, plus Intention: The concepts/mental images that the word/phrase evokes.

  3. Syntax:
    Syntax is all about the structure of sentences, and what determines which words go where.

  4. Production:
    A production or production rule in computer science is a rewrite rule specifying a symbol substitution that can be recursively performed to generate new symbol sequences.

  5. Alphabet:
    A non-empty set is called alphabet when its intended use in string operations shall be indicated.

  6. Lexeme:
    A lexeme is a string of characters which forms a syntactic unit.

  7. Syntactic unit:
    Sentence is the "highest" (i.e., largest) syntactic unit,
    the lowest (i.e., smallest) syntactic units are words,
    the intermediate syntactic units are the phrases.

  8. Token:
    A token is a structure representing a lexeme that explicitly indicates its categorization for the purpose of parsing.

  9. Grammar:
    A grammar (when the context is not given, often called a 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's alphabet that are valid according to the language's syntax. A formal grammar is a set of rules for rewriting strings, along with a "start symbol" from which rewriting starts.

  10. Lexical grammar:
    A lexical grammar is a formal grammar defining the syntax of tokens.

I could not find out what syntactic grammar is.

Nickens answered 17/5, 2015 at 7:23 Comment(0)
H
11

A more expansive definition of "syntax" would be the set of all ordered combinations of symbols which form a correct document, in the given language. Thus, "syntactic grammar" can be summarily described as the portion of the language's grammar that describes how various tokens can be ordered, to form meaningful phrases.

Of course this folds back on your provided definition of "lexical grammar", so allow me to highlight the major difference--lexical grammar describes the structure of the lexicon, that is, every token (word) used in the language. Syntactical grammar describes how phrases and documents are formed from those tokens.

Homunculus answered 17/5, 2015 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.