# Syntax checking expressed mathematically

1) Set B is the finite set of all rules for a particular programming language.

2) Set A is the infinite set of all valid strings of that language and is defined by Set B.

I'm having a problem defining expressing that mathematically.

My so far unsuccessful idea:

• Define a set C - the set of all possible strings.
• set A is a finite union between infinite sets A_i such that for every rule B_i

$B_i ( C ) = A_i$

can It be defined with an implication ? for every rule B_i of B applied to every string c_i of C, if $B_i ( c_j ) \implies c_j$

• To make this easier to read use latex formatting around your functions( put a dollar sign on each side of the function A_i becomes $A_i$ ) – lPlant Jun 27 '14 at 15:38
• Also initially you say $A$ is the set of rules and $B$ is a set of strings, but then refer to rule $B_i$ applying a string to it to get a new rule which does not make sense. – lPlant Jun 27 '14 at 15:48
• Can you explain in words the meaning of what you write formally. What are your rules supposed to look like and be used. What does it mean and/or produce when you apply a rule to a string. What is the meaning of defining something with an implication. Math is to some extent a Lego game, but you have to understand the shapes of the bricks to fit them together meaningfully. I am asking what shape you see to the bricks you propose to use, and how you propose to assemble them. – babou Jun 27 '14 at 17:44

## 1 Answer

The standard approach to formalize the syntax of a programming language involves using context-free grammars and context-free languages. I suggest reading a standard compilers textbook; it will discuss how to express the syntax of the programming language using techniques like context-free grammars, and that will provide you a lot of helpful context.

In particular, programming language syntax is typically formalized not by a set of "rules", but rather by a context-free grammar/language. The source code of a program must be in that language to be syntactically valid; if it isn't in the context-free language, it has a syntax error. See also Backus-Naur notation.

Take you a little while to read the material, and then I suspect you'll be in a better position either to make sense of this, or to pose a more specific question.

• That is incorrect sir. From "Engineering a compiler, 2nd edition" - Mathematically, the source language is a set, usually infinite, of strings defined by some finite set of rules, called a grammar – SdSdsdsd Jun 28 '14 at 10:56