In: Computer Science
3.Use EBNF to describe the syntax of Java ifstatements, no need to further define other statements or Boolean expressions.
4.Python uses indention in its program structures. How do you define the syntax of a language construct that uses indention?
EBNF:
=======
If-statement
------------
if_statement <=
[if_label : ]
if boolean_expression then
{ sequential_statement
}
{ elsif boolean_expression then
{ sequential_statement }
}
[else
{ sequential_statement }
]
end if [if_label];
Python:
========
There are two parts to create language:
1. Lexeme specification:
defines groups of characters that represent a single syntactic
construct like token or terminal value
2. Grammar specification:
defines the valid combinations of syntactic
constructs/tokens/terminal values that make up non-terminal values
that express how the language can be used in level
start ::= list
| list NEWLINE
.
list ::= entry
| list entry
.
entry ::= STRING NEWLINE
| STRING NEWLINE INDENT
list DEDENT
.
Sample if-statement:
x = true
if x:
print("x is true")
else:
print("x is false")