Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Off-side rule
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Implementation== The off-side rule can be implemented in the [[lexical analysis]] phase, as in [[Python (programming language)|Python]], where increasing the indenting results in the lexer outputting an <code>INDENT</code> token, and decreasing the indenting results in the lexer outputting a <code>DEDENT</code> token.<ref>[https://docs.python.org/ Python Documentation], [https://docs.python.org/3/reference/lexical_analysis.html 2. Lexical analysis]: [https://docs.python.org/3/reference/lexical_analysis.html#indentation 2.1.8. Indentation]</ref> These tokens correspond to the opening brace <code>{</code> and closing brace <code>}</code> in languages that use braces for blocks, and means that the phrase grammar does not depend on whether braces or indentation are used. This requires that the lexer hold state, namely the current indent level, and thus can detect changes in indentation when this changes, and thus the lexical [[Formal grammar|grammar]] is not [[Context-free grammar|context-free]]: <code>INDENT</code> and <code>DEDENT</code> depend on the contextual information of the prior indent level.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)